Hello,
I was missing pid file support in OpenNTPD. I've created a patch that
enables pidfile /var/run/ntpd.pid in OpenNTPD and now I can define in the
rc script pidfile location. With pidfile location I dont see any more this
annoying message when restarting and stopping:
[root@vps24009 ~]# /usr/local/etc/rc.d/openntpd stop
Stopping openntpd.
kill: 20188: No such process
kill: 20189: No such process
And with pidfile="/var/run/ntpd.pid" in openntpd rc script
[root@vps24009 ~]# /usr/local/etc/rc.d/openntpd stop
Stopping openntpd.
Regards,
Tomasz
diff -ruN /usr/ports/net/openntpd/work/ntpd/Makefile /home/tmw/Code/warehouse/openntpd_pidfile/Makefile
--- /usr/ports/net/openntpd/work/ntpd/Makefile 2014-05-29 15:30:52.000000000 +0200
+++ /home/tmw/Code/warehouse/openntpd_pidfile/Makefile 2014-05-30 13:08:28.000000000 +0200
@@ -12,6 +12,6 @@
MAN= ntpd.8 ntpd.conf.5
DPADD= ${LIBMD}
-LDADD= -lmd
+LDADD= -lmd -lutil
.include <bsd.prog.mk>
diff -ruN /usr/ports/net/openntpd/work/ntpd/ntp.c /home/tmw/Code/warehouse/openntpd_pidfile/ntp.c
--- /usr/ports/net/openntpd/work/ntpd/ntp.c 2014-05-29 15:30:52.000000000 +0200
+++ /home/tmw/Code/warehouse/openntpd_pidfile/ntp.c 2014-05-30 15:16:15.000000000 +0200
@@ -74,7 +74,7 @@
}
pid_t
-ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf, struct passwd *pw)
+ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf, struct passwd *pw, struct pidfh *pfh)
{
int a, b, nfds, i, j, idx_peers, timeout;
#ifdef HAVE_SENSORS
@@ -105,6 +105,7 @@
fatal("cannot fork");
break;
case 0:
+ pidfile_close(pfh);
break;
default:
return (pid);
diff -ruN /usr/ports/net/openntpd/work/ntpd/ntpd.c /home/tmw/Code/warehouse/openntpd_pidfile/ntpd.c
--- /usr/ports/net/openntpd/work/ntpd/ntpd.c 2014-05-29 15:30:52.000000000 +0200
+++ /home/tmw/Code/warehouse/openntpd_pidfile/ntpd.c 2014-05-30 15:18:04.000000000 +0200
@@ -86,11 +86,12 @@
{
struct ntpd_conf lconf;
struct pollfd pfd[POLL_MAX];
- pid_t chld_pid = 0, pid;
+ pid_t chld_pid = 0, pid, otherpid;
const char *conffile;
int ch, nfds;
int pipe_chld[2];
struct passwd *pw;
+ struct pidfh *pfh;
conffile = CONFFILE;
@@ -158,8 +159,17 @@
signal(SIGCHLD, sighdlr);
/* fork child process */
- chld_pid = ntp_main(pipe_chld, &lconf, pw);
+ pfh = pidfile_open(PIDFILE, 0600, &otherpid);
+ if (pfh == NULL) {
+ if (errno == EEXIST) {
+ errx(EXIT_FAILURE, "Daemon already running, pid: %d",
+ otherpid);
+ }
+ warn("Cannot open or create pidfile");
+ }
+ pidfile_write(pfh);
+ chld_pid = ntp_main(pipe_chld, &lconf, pw, pfh);
setproctitle("[priv]");
readfreq();
@@ -192,8 +202,10 @@
log_debug("no reply received in time, skipping initial "
"time setting");
if (!lconf.debug)
- if (daemon(1, 0))
+ if (daemon(1, 0)) {
+ pidfile_remove(pfh);
fatal("daemon");
+ }
}
if (nfds > 0 && (pfd[PFD_PIPE].revents & POLLOUT))
@@ -231,6 +243,7 @@
msgbuf_clear(&ibuf->w);
free(ibuf);
+ pidfile_remove(pfh);
log_info("Terminating");
return (0);
}
diff -ruN /usr/ports/net/openntpd/work/ntpd/ntpd.h /home/tmw/Code/warehouse/openntpd_pidfile/ntpd.h
--- /usr/ports/net/openntpd/work/ntpd/ntpd.h 2014-05-29 15:32:22.000000000 +0200
+++ /home/tmw/Code/warehouse/openntpd_pidfile/ntpd.h 2014-05-30 15:17:27.000000000 +0200
@@ -29,6 +29,8 @@
#include <pwd.h>
#include <stdarg.h>
+#include <libutil.h>
+
#include "compat.h"
#include "ntp.h"
#include <imsg.h>
@@ -36,6 +38,7 @@
#define NTPD_USER "_ntp"
#define CONFFILE "/usr/local/etc/ntpd.conf"
#define DRIFTFILE "/var/db/ntpd.drift"
+#define PIDFILE "/var/run/ntpd.pid"
#define INTERVAL_QUERY_NORMAL 30 /* sync to peers every n secs */
#define INTERVAL_QUERY_PATHETIC 60
@@ -201,7 +204,7 @@
const char * log_sockaddr(struct sockaddr *);
/* ntp.c */
-pid_t ntp_main(int[2], struct ntpd_conf *, struct passwd *);
+pid_t ntp_main(int[2], struct ntpd_conf *, struct passwd *, struct pidfh *);
int priv_adjtime(void);
void priv_settime(double);
void priv_host_dns(char *, u_int32_t);
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "[email protected]"