[PATCH] dispatch_getprogname()
When compiling a libdispatch debug build on Linux, I found that getprogname(3) is not available. Here is a patch that implements a wrapper function. Regards, - Mark Index: configure.ac =================================================================== --- configure.ac (revision 174) +++ configure.ac (working copy) @@ -192,7 +192,7 @@ AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]]) AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]]) AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK], [], [], [[#include <sys/mount.h>]]) -AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf]) +AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf getprogname]) AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED], [have_posix_spawn_start_suspended=true], Index: src/queue.c =================================================================== --- src/queue.c (revision 174) +++ src/queue.c (working copy) @@ -1786,6 +1786,18 @@ va_end(ap); } +static char * +dispatch_getprogname(void) +{ +#if HAVE_GETPROGNAME + return getprogname(); +#elif __linux__ + return program_invocation_short_name; +#else +#error getprogname() is not available on this platform +#endif +} + void _dispatch_logv(const char *msg, va_list ap) { @@ -1806,7 +1818,8 @@ struct timeval tv; gettimeofday(&tv, NULL); fprintf(logfile, "=== log file opened for %s[%u] at %ld.%06u ===\n", - getprogname() ?: "", getpid(), tv.tv_sec, tv.tv_usec); + dispatch_getprogname() ?: "", + getpid(), tv.tv_sec, tv.tv_usec); } } vfprintf(logfile, newbuf, ap);
On Mon, 21 Dec 2009, Mark Heily wrote:
When compiling a libdispatch debug build on Linux, I found that getprogname(3) is not available. Here is a patch that implements a wrapper function.
Could you tweak the approach slightly to: - Add a src/shims/getprogname.[ch], implementing getprogname() there if it's not available? - Directly test for program_invocation_short_name using configure and use the resulting HAVE_ ifdef as needed? I think this would be more consistent with the shims setup that Paolo has been pushing us towards. Thanks! Robert N M Watson Computer Laboratory University of Cambridge
Regards,
- Mark
Index: configure.ac =================================================================== --- configure.ac (revision 174) +++ configure.ac (working copy) @@ -192,7 +192,7 @@ AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]]) AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]]) AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK], [], [], [[#include <sys/mount.h>]]) -AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf]) +AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf getprogname])
AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED], [have_posix_spawn_start_suspended=true], Index: src/queue.c =================================================================== --- src/queue.c (revision 174) +++ src/queue.c (working copy) @@ -1786,6 +1786,18 @@ va_end(ap); }
+static char * +dispatch_getprogname(void) +{ +#if HAVE_GETPROGNAME + return getprogname(); +#elif __linux__ + return program_invocation_short_name; +#else +#error getprogname() is not available on this platform +#endif +} + void _dispatch_logv(const char *msg, va_list ap) { @@ -1806,7 +1818,8 @@ struct timeval tv; gettimeofday(&tv, NULL); fprintf(logfile, "=== log file opened for %s[%u] at %ld.%06u ===\n", - getprogname() ?: "", getpid(), tv.tv_sec, tv.tv_usec); + dispatch_getprogname() ?: "", + getpid(), tv.tv_sec, tv.tv_usec); } } vfprintf(logfile, newbuf, ap); _______________________________________________ libdispatch-dev mailing list libdispatch-dev@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/libdispatch-dev
Robert Watson wrote:
On Mon, 21 Dec 2009, Mark Heily wrote:
When compiling a libdispatch debug build on Linux, I found that getprogname(3) is not available. Here is a patch that implements a wrapper function.
Could you tweak the approach slightly to:
- Add a src/shims/getprogname.[ch], implementing getprogname() there if it's not available? - Directly test for program_invocation_short_name using configure and use the resulting HAVE_ ifdef as needed?
See below for the revised patch. Regards, - Mark Index: configure.ac =================================================================== --- configure.ac (revision 174) +++ configure.ac (working copy) @@ -192,7 +192,7 @@ AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]]) AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]]) AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK], [], [], [[#include <sys/mount.h>]]) -AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf]) +AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf getprogname program_invocation_short_name]) AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED], [have_posix_spawn_start_suspended=true], Index: src/shims/getprogname.h =================================================================== --- src/shims/getprogname.h (revision 0) +++ src/shims/getprogname.h (revision 0) @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2009 Apple Inc. All rights reserved. + * + * @APPLE_APACHE_LICENSE_HEADER_START@ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @APPLE_APACHE_LICENSE_HEADER_END@ + */ + +#ifndef __DISPATCH_SHIMS_GETPROGNAME__ +#define __DISPATCH_SHIMS_GETPROGNAME__ + +#ifndef HAVE_GETPROGNAME +static inline char * +getprogname(void) +{ +# if HAVE_PROGRAM_INVOCATION_SHORT_NAME + return program_invocation_short_name; +# else +# error getprogname(3) is not available on this platform +# endif +} +#endif /* HAVE_GETPROGNAME */ + +#endif /* __DISPATCH_SHIMS_GETPROGNAME__ */ Index: src/os_shims.h =================================================================== --- src/os_shims.h (revision 174) +++ src/os_shims.h (working copy) @@ -46,6 +46,7 @@ #define FD_COPY(f, t) (void)(*(t) = *(f)) #endif +#include "shims/getprogname.h" #include "shims/malloc_zone.h" #include "shims/tsd.h" #include "shims/perfmon.h"
On Fri, 25 Dec 2009, Mark Heily wrote:
When compiling a libdispatch debug build on Linux, I found that getprogname(3) is not available. Here is a patch that implements a wrapper function.
Could you tweak the approach slightly to:
- Add a src/shims/getprogname.[ch], implementing getprogname() there if it's not available? - Directly test for program_invocation_short_name using configure and use the resulting HAVE_ ifdef as needed?
See below for the revised patch.
Hi Mark-- I've committed this patch as r177. I think the configure.ac check is probably not quite right, as program_invocation_short_name looks to me like a regular symbol pointing at a string rather than a function -- probably we should redo as a test that use of the symbol links. Robert N M Watson Computer Laboratory University of Cambridge
Regards,
- Mark
Index: configure.ac =================================================================== --- configure.ac (revision 174) +++ configure.ac (working copy) @@ -192,7 +192,7 @@ AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]]) AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]]) AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK], [], [], [[#include <sys/mount.h>]]) -AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf]) +AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf getprogname program_invocation_short_name])
AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED], [have_posix_spawn_start_suspended=true], Index: src/shims/getprogname.h =================================================================== --- src/shims/getprogname.h (revision 0) +++ src/shims/getprogname.h (revision 0) @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2009 Apple Inc. All rights reserved. + * + * @APPLE_APACHE_LICENSE_HEADER_START@ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @APPLE_APACHE_LICENSE_HEADER_END@ + */ + +#ifndef __DISPATCH_SHIMS_GETPROGNAME__ +#define __DISPATCH_SHIMS_GETPROGNAME__ + +#ifndef HAVE_GETPROGNAME +static inline char * +getprogname(void) +{ +# if HAVE_PROGRAM_INVOCATION_SHORT_NAME + return program_invocation_short_name; +# else +# error getprogname(3) is not available on this platform +# endif +} +#endif /* HAVE_GETPROGNAME */ + +#endif /* __DISPATCH_SHIMS_GETPROGNAME__ */ Index: src/os_shims.h =================================================================== --- src/os_shims.h (revision 174) +++ src/os_shims.h (working copy) @@ -46,6 +46,7 @@ #define FD_COPY(f, t) (void)(*(t) = *(f)) #endif
+#include "shims/getprogname.h" #include "shims/malloc_zone.h" #include "shims/tsd.h" #include "shims/perfmon.h"
participants (2)
-
Mark Heily
-
Robert Watson