diff -Nur openntpd-5.7p2-orig/Makefile.am openntpd-5.7p2/Makefile.am --- openntpd-5.7p2-orig/Makefile.am 2015-01-19 17:18:56.000000000 -0800 +++ openntpd-5.7p2/Makefile.am 2015-01-21 12:09:17.221031344 -0800 @@ -162,6 +162,8 @@ libcompat_la_SOURCES += compat/md5.c endif +libcompat_la_SOURCES += compat/progname.c + if !HAVE_REALLOCARRAY libcompat_la_SOURCES += compat/reallocarray.c endif diff -Nur openntpd-5.7p2-orig/configure.ac openntpd-5.7p2/configure.ac --- openntpd-5.7p2-orig/configure.ac 2015-01-19 17:18:56.000000000 -0800 +++ openntpd-5.7p2/configure.ac 2015-01-21 12:10:32.118825079 -0800 @@ -153,6 +153,18 @@ -a "x$HOST_OS" != xnetbsd \ -a "x$ac_cv_func_arc4random_uniform" = xyes]) +AC_CACHE_CHECK([if libc defines __progname], ac_cv_libc_defines___progname, [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], + [[ extern char *__progname; printf("%s", __progname); ]])], + [ ac_cv_libc_defines___progname="yes" ], + [ ac_cv_libc_defines___progname="no" + ]) +]) +if test "x$ac_cv_libc_defines___progname" = "xyes" ; then + AC_DEFINE([HAVE___PROGNAME], [1], [Define if libc defines __progname]) +fi + + AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [ AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include diff -Nur openntpd-5.7p2-orig/configure openntpd-5.7p2/configure --- openntpd-5.7p2-orig/configure 2015-01-19 18:30:48.000000000 -0800 +++ openntpd-5.7p2/configure 2015-01-21 12:11:19.827967669 -0800 @@ -13519,6 +13519,42 @@ fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if libc defines __progname" >&5 +$as_echo_n "checking if libc defines __progname... " >&6; } +if ${ac_cv_libc_defines___progname+:} false; then : + $as_echo_n "(cached) " >&6 +else + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + extern char *__progname; printf("%s", __progname); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_libc_defines___progname="yes" +else + ac_cv_libc_defines___progname="no" + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_libc_defines___progname" >&5 +$as_echo "$ac_cv_libc_defines___progname" >&6; } +if test "x$ac_cv_libc_defines___progname" = "xyes" ; then + +$as_echo "#define HAVE___PROGNAME 1" >>confdefs.h + +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether va_copy exists" >&5 $as_echo_n "checking whether va_copy exists... " >&6; } if ${ac_cv_have_va_copy+:} false; then : diff -Nur openntpd-5.7p2-orig/Makefile.in openntpd-5.7p2/Makefile.in --- openntpd-5.7p2-orig/Makefile.in 2015-01-19 18:30:49.000000000 -0800 +++ openntpd-5.7p2/Makefile.in 2015-01-21 12:11:17.319907603 -0800 @@ -161,13 +161,14 @@ compat/adjfreq_osx.c compat/adjfreq_solaris.c \ compat/bsd-asprintf.c compat/clock_getres.c \ compat/clock_gettime_osx.c compat/imsg.c compat/imsg-buffer.c \ - compat/md5.c compat/reallocarray.c compat/setproctitle.c \ - compat/strlcat.c compat/strlcpy.c compat/strtonum.c \ - compat/bsd-setresgid.c compat/bsd-setresuid.c \ - compat/arc4random.c compat/getentropy_freebsd.c \ - compat/getentropy_linux.c compat/sha2.c \ - compat/getentropy_netbsd.c compat/getentropy_osx.c \ - compat/getentropy_solaris.c compat/arc4random_uniform.c + compat/md5.c compat/progname.c compat/reallocarray.c \ + compat/setproctitle.c compat/strlcat.c compat/strlcpy.c \ + compat/strtonum.c compat/bsd-setresgid.c \ + compat/bsd-setresuid.c compat/arc4random.c \ + compat/getentropy_freebsd.c compat/getentropy_linux.c \ + compat/sha2.c compat/getentropy_netbsd.c \ + compat/getentropy_osx.c compat/getentropy_solaris.c \ + compat/arc4random_uniform.c am__dirstamp = $(am__leading_dot)dirstamp @HAVE_ADJFREQ_FALSE@@HOST_FREEBSD_TRUE@am__objects_1 = compat/libcompat_la-adjfreq_freebsd.lo @HAVE_ADJFREQ_FALSE@@HOST_LINUX_TRUE@am__objects_2 = compat/libcompat_la-adjfreq_linux.lo @@ -207,7 +208,8 @@ am_libcompat_la_OBJECTS = $(am__objects_1) $(am__objects_2) \ $(am__objects_3) $(am__objects_4) $(am__objects_5) \ $(am__objects_6) $(am__objects_7) $(am__objects_8) \ - $(am__objects_9) $(am__objects_10) $(am__objects_11) \ + $(am__objects_9) $(am__objects_10) \ + compat/libcompat_la-progname.lo $(am__objects_11) \ $(am__objects_12) $(am__objects_13) $(am__objects_14) \ $(am__objects_15) $(am__objects_16) $(am__objects_17) \ $(am__objects_18) $(am__objects_19) $(am__objects_20) \ @@ -562,12 +564,13 @@ libcompat_la_SOURCES = $(am__append_4) $(am__append_5) $(am__append_6) \ $(am__append_7) $(am__append_8) $(am__append_9) \ $(am__append_10) $(am__append_11) $(am__append_12) \ - $(am__append_13) $(am__append_14) $(am__append_15) \ - $(am__append_16) $(am__append_17) $(am__append_18) \ - $(am__append_19) $(am__append_20) $(am__append_21) \ - $(am__append_22) $(am__append_23) $(am__append_24) \ - $(am__append_25) $(am__append_26) $(am__append_27) \ - $(am__append_28) $(am__append_29) $(am__append_30) + $(am__append_13) compat/progname.c $(am__append_14) \ + $(am__append_15) $(am__append_16) $(am__append_17) \ + $(am__append_18) $(am__append_19) $(am__append_20) \ + $(am__append_21) $(am__append_22) $(am__append_23) \ + $(am__append_24) $(am__append_25) $(am__append_26) \ + $(am__append_27) $(am__append_28) $(am__append_29) \ + $(am__append_30) libcompat_la_LIBADD = $(PLATFORM_LDADD) noinst_HEADERS = compat/arc4random.h compat/arc4random_freebsd.h \ compat/arc4random_linux.h compat/arc4random_netbsd.h \ @@ -649,6 +652,8 @@ compat/$(DEPDIR)/$(am__dirstamp) compat/libcompat_la-md5.lo: compat/$(am__dirstamp) \ compat/$(DEPDIR)/$(am__dirstamp) +compat/libcompat_la-progname.lo: compat/$(am__dirstamp) \ + compat/$(DEPDIR)/$(am__dirstamp) compat/libcompat_la-reallocarray.lo: compat/$(am__dirstamp) \ compat/$(DEPDIR)/$(am__dirstamp) compat/libcompat_la-setproctitle.lo: compat/$(am__dirstamp) \ @@ -783,6 +788,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@compat/$(DEPDIR)/libcompat_la-imsg-buffer.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@compat/$(DEPDIR)/libcompat_la-imsg.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@compat/$(DEPDIR)/libcompat_la-md5.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@compat/$(DEPDIR)/libcompat_la-progname.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@compat/$(DEPDIR)/libcompat_la-reallocarray.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@compat/$(DEPDIR)/libcompat_la-setproctitle.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@compat/$(DEPDIR)/libcompat_la-sha2.Plo@am__quote@ @@ -893,6 +899,13 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcompat_la_CFLAGS) $(CFLAGS) -c -o compat/libcompat_la-md5.lo `test -f 'compat/md5.c' || echo '$(srcdir)/'`compat/md5.c +compat/libcompat_la-progname.lo: compat/progname.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcompat_la_CFLAGS) $(CFLAGS) -MT compat/libcompat_la-progname.lo -MD -MP -MF compat/$(DEPDIR)/libcompat_la-progname.Tpo -c -o compat/libcompat_la-progname.lo `test -f 'compat/progname.c' || echo '$(srcdir)/'`compat/progname.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) compat/$(DEPDIR)/libcompat_la-progname.Tpo compat/$(DEPDIR)/libcompat_la-progname.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='compat/progname.c' object='compat/libcompat_la-progname.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcompat_la_CFLAGS) $(CFLAGS) -c -o compat/libcompat_la-progname.lo `test -f 'compat/progname.c' || echo '$(srcdir)/'`compat/progname.c + compat/libcompat_la-reallocarray.lo: compat/reallocarray.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcompat_la_CFLAGS) $(CFLAGS) -MT compat/libcompat_la-reallocarray.lo -MD -MP -MF compat/$(DEPDIR)/libcompat_la-reallocarray.Tpo -c -o compat/libcompat_la-reallocarray.lo `test -f 'compat/reallocarray.c' || echo '$(srcdir)/'`compat/reallocarray.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) compat/$(DEPDIR)/libcompat_la-reallocarray.Tpo compat/$(DEPDIR)/libcompat_la-reallocarray.Plo diff -Nur openntpd-5.7p2-orig/compat/progname.c openntpd-5.7p2/compat/progname.c --- openntpd-5.7p2-orig/compat/progname.c 1969-12-31 16:00:00.000000000 -0800 +++ openntpd-5.7p2/compat/progname.c 2015-01-21 12:09:55.528948784 -0800 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1999-2004 Damien Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#ifndef HAVE___PROGNAME +char *__progname; +#endif + +/* + * NB. duplicate __progname in case it is an alias for argv[0] + * Otherwise it may get clobbered by setproctitle() + */ +char *get_progname(char *argv0) +{ +#ifdef HAVE___PROGNAME + extern char *__progname; + + return strdup(__progname); +#else + char *p; + + if (argv0 == NULL) + return ("unknown"); /* XXX */ + p = strrchr(argv0, '/'); + if (p == NULL) + p = argv0; + else + p++; + + return (strdup(p)); +#endif +} diff -Nur openntpd-5.7p2-orig/ntpd.c openntpd-5.7p2/ntpd.c --- openntpd-5.7p2-orig/ntpd.c 2015-01-19 18:30:41.000000000 -0800 +++ openntpd-5.7p2/ntpd.c 2015-01-21 12:11:05.744630385 -0800 @@ -116,6 +116,8 @@ static char **saved_argv; #endif +char *get_progname(char *argv0); + int main(int argc, char *argv[]) { @@ -139,6 +141,8 @@ log_init(1); /* log to stderr until daemonized */ + __progname = get_progname(argv[0]); + #ifndef HAVE_SETPROCTITLE int i; /* Prepare for later setproctitle emulation */