[libdispatch-dev] [PATCH] dispatch_getprogname()
Robert Watson
robert at fledge.watson.org
Thu Dec 24 11:42:25 PST 2009
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 at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/libdispatch-dev
>
More information about the libdispatch-dev
mailing list