Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/ntp - use setproctitle if we have it



details:   https://anonhg.NetBSD.org/src/rev/84a973d46736
branches:  trunk
changeset: 993171:84a973d46736
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Aug 28 11:11:18 2018 +0000

description:
- use setproctitle if we have it
- emulate setproctitle better

diffstat:

 external/bsd/ntp/dist/configure.ac       |   2 +-
 external/bsd/ntp/dist/libntp/work_fork.c |  40 ++++++++++++++++++++++---------
 external/bsd/ntp/include/config.h        |   2 +
 3 files changed, 31 insertions(+), 13 deletions(-)

diffs (85 lines):

diff -r 727abc5753fe -r 84a973d46736 external/bsd/ntp/dist/configure.ac
--- a/external/bsd/ntp/dist/configure.ac        Tue Aug 28 09:42:10 2018 +0000
+++ b/external/bsd/ntp/dist/configure.ac        Tue Aug 28 11:11:18 2018 +0000
@@ -857,7 +857,7 @@
     )]
 )
 
-AC_CHECK_FUNCS([fnmatch getbootfile getuid getrusage nanosleep strsignal])
+AC_CHECK_FUNCS([fnmatch getbootfile getuid getrusage nanosleep strsignal setproctitle])
 
 # kvm_open() is only used by tickadj.  Also see above.
 case "$ac_cv_header_kvm_h" in
diff -r 727abc5753fe -r 84a973d46736 external/bsd/ntp/dist/libntp/work_fork.c
--- a/external/bsd/ntp/dist/libntp/work_fork.c  Tue Aug 28 09:42:10 2018 +0000
+++ b/external/bsd/ntp/dist/libntp/work_fork.c  Tue Aug 28 11:11:18 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: work_fork.c,v 1.11 2017/04/13 20:17:42 christos Exp $  */
+/*     $NetBSD: work_fork.c,v 1.12 2018/08/28 11:11:18 christos Exp $  */
 
 /*
  * work_fork.c - fork implementation for blocking worker child.
@@ -432,6 +432,32 @@
 }
 #endif
 
+#if HAVE_SETPROCTITLE == 0
+static void
+setproctitle(const char *fmt, ...)
+{
+       va_list ap;
+       char b1[128];
+       int argcc, argvlen, l;
+
+       if (saved_argc == 0)
+               return;
+
+       va_start(ap, fmt);
+       vsnprintf(b1, sizeof(b1), fmt, ap);
+       va_end(ap);
+
+       /* Clear argv */
+       for (argvlen = 0, argcc = 0; argcc < saved_argc; argcc++) {
+               l = strlen(saved_argv[argcc]);
+               argvlen += l + 1;
+               memset(saved_argv[argcc], 0, l);
+       }
+       l = snprintf(saved_argv[0], argvlen, "ntpd: %s", b1);
+       for (argcc = 1; argcc < saved_argc; argcc++)
+               saved_argv[argcc] = &saved_argv[0][l];
+}
+#endif
 
 static void
 fork_blocking_child(
@@ -543,17 +569,7 @@
         * Change the process name of the child to avoid confusion
         * about ntpd trunning twice.
         */
-       if (saved_argc != 0) {
-               int argcc;
-               int argvlen = 0;
-               /* Clear argv */
-               for (argcc = 0; argcc < saved_argc; argcc++) {
-                       int l = strlen(saved_argv[argcc]);
-                       argvlen += l + 1;
-                       memset(saved_argv[argcc], 0, l);
-               }
-               strlcpy(saved_argv[0], "ntpd: asynchronous dns resolver", argvlen);
-       }
+       setproctitle("asynchronous dns resolver");
 
        /*
         * In the child, close all files except stdin, stdout, stderr,
diff -r 727abc5753fe -r 84a973d46736 external/bsd/ntp/include/config.h
--- a/external/bsd/ntp/include/config.h Tue Aug 28 09:42:10 2018 +0000
+++ b/external/bsd/ntp/include/config.h Tue Aug 28 11:11:18 2018 +0000
@@ -330,6 +330,8 @@
 /* Define to 1 if you have `alloca', as a function or macro. */
 #define HAVE_ALLOCA 1
 
+#define HAVE_SETPROCTITLE 1
+
 /* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
    */
 /* #undef HAVE_ALLOCA_H */



Home | Main Index | Thread Index | Old Index