From 549bec923b5cdbd6baa83a67b7e625f1fa824539 Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Mon, 12 Jan 2015 06:18:31 -0600 Subject: [PATCH 08/18] initialize setproctitle where needed We need to save a copy of argv and __progname to avoid setproctitle clobbering them. --- src/usr.sbin/ntpd/ntpd.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c index a0da39adf7..7259bb6236 100644 --- a/src/usr.sbin/ntpd/ntpd.c +++ b/src/usr.sbin/ntpd/ntpd.c @@ -134,6 +134,13 @@ auto_preconditions(const struct ntpd_conf *cnf) #define PFD_PIPE 0 #define PFD_MAX 1 +/* Saves a copy of argv for setproctitle emulation */ +#ifndef HAVE_SETPROCTITLE +static char **saved_argv; +#endif + +char *get_progname(char *argv0); + int main(int argc, char *argv[]) { @@ -154,6 +161,8 @@ main(int argc, char *argv[]) time_t settime_deadline; int sopt = 0; + __progname = get_progname(argv[0]); + if (strcmp(__progname, "ntpctl") == 0) { ctl_main(argc, argv); /* NOTREACHED */ @@ -163,6 +172,17 @@ main(int argc, char *argv[]) memset(&lconf, 0, sizeof(lconf)); +#ifndef HAVE_SETPROCTITLE + /* Prepare for later setproctitle emulation */ + saved_argv = calloc(argc + 1, sizeof(*saved_argv)); + for (i = 0; i < argc; i++) + saved_argv[i] = strdup(argv[i]); + saved_argv[i] = NULL; + compat_init_setproctitle(argc, argv); + argv = saved_argv; + argv0 = argv; +#endif + while ((ch = getopt(argc, argv, "df:np:P:sSv")) != -1) { switch (ch) { case 'd': -- 2.27.0