Package: openntpd Followup-For: Bug #354825
Attached patch should work with -s option too.
Index: openntpd-3.9p1+debian/ntpd.8 =================================================================== --- openntpd-3.9p1+debian.orig/ntpd.8 2009-02-01 14:43:41.000000000 +0300 +++ openntpd-3.9p1+debian/ntpd.8 2009-02-01 14:49:35.000000000 +0300 @@ -24,7 +24,8 @@ .Nm ntpd .Bk -words .Op Fl dSs -.Op Fl f Ar file +.Op Fl f Ar conffile +.Op Fl p Ar pidfile .Ek .Sh DESCRIPTION The @@ -67,12 +68,16 @@ .Nm will run in the foreground and log to .Em stderr . -.It Fl f Ar file +.It Fl f Ar conffile Use -.Ar file +.Ar conffile as the configuration file, instead of the default .Pa /etc/ntpd.conf . +.It Fl p Ar pidfile +Specify the name and path of the file used to record the +.Nm +process ID. .It Fl S Do not set the time immediately at startup. This is the default. @@ -91,6 +96,10 @@ default .Nm configuration file +.It Pa /var/run/openntpd.pid +Contains the process ID of the +.Nm +listening for connections. .El .Sh SEE ALSO .Xr date 1 , Index: openntpd-3.9p1+debian/ntpd.c =================================================================== --- openntpd-3.9p1+debian.orig/ntpd.c 2009-02-01 14:43:40.000000000 +0300 +++ openntpd-3.9p1+debian/ntpd.c 2009-02-01 14:51:50.000000000 +0300 @@ -39,6 +39,7 @@ #include "ntpd.h" void sighdlr(int); +void write_pid(struct ntpd_conf*); __dead void usage(void); int main(int, char *[]); int check_child(pid_t, const char *); @@ -51,6 +52,14 @@ volatile sig_atomic_t sigchld = 0; struct imsgbuf *ibuf; +void write_pid(struct ntpd_conf *conf) +{ + FILE *f; + f = fdopen(conf->pid_fd, "w"); + fprintf(f, "%ld\n", (long) getpid()); + fclose(f); +} + void sighdlr(int sig) { @@ -87,6 +96,7 @@ struct pollfd pfd[POLL_MAX]; pid_t chld_pid = 0, pid; const char *conffile; + const char *pidfile; int ch, nfds, timeout = INFTIM; int pipe_chld[2]; extern char *__progname; @@ -94,6 +104,7 @@ __progname = _compat_get_progname(argv[0]); conffile = CONFFILE; + pidfile = PIDFILE; bzero(&conf, sizeof(conf)); @@ -108,6 +119,9 @@ case 'f': conffile = optarg; break; + case 'p': + pidfile = optarg; + break; case 's': conf.settime = 1; break; @@ -123,6 +137,11 @@ if (parse_config(conffile, &conf)) exit(1); + if ( (conf.pid_fd = creat(pidfile, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1) { + fprintf(stderr, "ntpd: can't create pid file\n"); + exit(1); + } + if (geteuid()) { fprintf(stderr, "ntpd: need root privileges\n"); exit(1); @@ -143,6 +162,8 @@ if (!conf.debug) if (daemon(1, 0)) fatal("daemon"); + else + write_pid(&conf); } else timeout = SETTIME_TIMEOUT * 1000; @@ -186,6 +207,8 @@ if (!conf.debug) if (daemon(1, 0)) fatal("daemon"); + else + write_pid(&conf); } if (nfds > 0 && (pfd[PFD_PIPE].revents & POLLOUT)) @@ -224,6 +247,8 @@ msgbuf_clear(&ibuf->w); free(ibuf); log_info("Terminating"); + close(conf.pid_fd); + unlink(pidfile); return (0); } @@ -295,6 +320,8 @@ if (!conf->debug) if (daemon(1, 0)) fatal("daemon"); + else + write_pid(conf); conf->settime = 0; break; case IMSG_HOST_DNS: Index: openntpd-3.9p1+debian/ntpd.h =================================================================== --- openntpd-3.9p1+debian.orig/ntpd.h 2009-02-01 14:43:40.000000000 +0300 +++ openntpd-3.9p1+debian/ntpd.h 2009-02-01 14:43:42.000000000 +0300 @@ -35,6 +35,8 @@ #endif #define CONFFILE SYSCONFDIR "/ntpd.conf" +#define PIDFILE "/var/run/openntpd.pid" + #define READ_BUF_SIZE 4096 #define NTPD_OPT_VERBOSE 0x0001 @@ -132,6 +134,7 @@ u_int8_t settime; u_int8_t debug; u_int32_t scale; + int pid_fd; }; struct buf {