Package: openntpd Version: 3.9p1-3 Tags: patch Followup-For: Bug #354825 Attached patch should fix this issue. Please review/comment.
#! /bin/sh /usr/share/dpatch/dpatch-run ## 03-parse.dpatch by Sergey B Kirpichev <skirpic...@gmail.com> ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: Create pid file on startup. Closes: #354825.
@DPATCH@ diff -urNad openntpd-3.9p1+debian~/ntpd.8 openntpd-3.9p1+debian/ntpd.8 --- openntpd-3.9p1+debian~/ntpd.8 2009-01-04 17:00:16.000000000 +0300 +++ openntpd-3.9p1+debian/ntpd.8 2009-01-04 17:04:31.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 , diff -urNad openntpd-3.9p1+debian~/ntpd.c openntpd-3.9p1+debian/ntpd.c --- openntpd-3.9p1+debian~/ntpd.c 2009-01-04 17:00:16.000000000 +0300 +++ openntpd-3.9p1+debian/ntpd.c 2009-01-04 17:00:19.000000000 +0300 @@ -87,6 +87,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 +95,7 @@ __progname = _compat_get_progname(argv[0]); conffile = CONFFILE; + pidfile = PIDFILE; bzero(&conf, sizeof(conf)); @@ -108,6 +110,9 @@ case 'f': conffile = optarg; break; + case 'p': + pidfile = optarg; + break; case 's': conf.settime = 1; break; @@ -149,6 +154,16 @@ if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_chld) == -1) fatal("socketpair"); + /* write pid */ + FILE *f = fopen(pidfile, "w"); + + if (f == NULL) { + error("Couldn't create pid file \"%s\": %s", pidfile, strerror(errno)); + } else { + fprintf(f, "%ld\n", (long) getpid()); + fclose(f); + } + /* fork child process */ chld_pid = ntp_main(pipe_chld, &conf); @@ -224,6 +239,7 @@ msgbuf_clear(&ibuf->w); free(ibuf); log_info("Terminating"); + unlink(pidfile); return (0); } diff -urNad openntpd-3.9p1+debian~/ntpd.h openntpd-3.9p1+debian/ntpd.h --- openntpd-3.9p1+debian~/ntpd.h 2009-01-04 17:00:16.000000000 +0300 +++ openntpd-3.9p1+debian/ntpd.h 2009-01-04 17:00:19.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