Index: usr.sbin/daemon/daemon.8 =================================================================== --- usr.sbin/daemon/daemon.8 +++ usr.sbin/daemon/daemon.8 @@ -34,7 +34,7 @@ .Nd run detached from the controlling terminal .Sh SYNOPSIS .Nm -.Op Fl cfrS +.Op Fl cfirS .Op Fl p Ar child_pidfile .Op Fl P Ar supervisor_pidfile .Op Fl t Ar title @@ -63,6 +63,8 @@ .It Fl f Redirect standard input, standard output and standard error to .Pa /dev/null . +.It Fl i +Create pid files with 0644 mode instead of default 0600. .It Fl S Enable syslog output. This is implicitly applied if other syslog parameters are provided. Index: usr.sbin/daemon/daemon.c =================================================================== --- usr.sbin/daemon/daemon.c +++ usr.sbin/daemon/daemon.c @@ -69,7 +69,7 @@ static int listen_child(int, struct log_params *); static int get_log_mapping(const char *, const CODE *); static void open_pid_files(const char *, const char *, struct pidfh **, - struct pidfh **); + struct pidfh **, mode_t); static void do_output(const unsigned char *, size_t, struct log_params *); static void daemon_sleep(time_t, long); static void usage(void); @@ -85,6 +85,7 @@ struct log_params logpar; int pfd[2] = { -1, -1 }, outfd = -1; int stdmask, logpri, logfac; + mode_t pidmode; struct pidfh *ppfh, *pfh; char *p; @@ -99,7 +100,8 @@ dosyslog = 0; outfn = NULL; title = NULL; - while ((ch = getopt(argc, argv, "cfSp:P:ru:o:s:l:t:l:m:R:T:")) != -1) { + pidmode=0600; + while ((ch = getopt(argc, argv, "cfiSp:P:ru:o:s:l:t:l:m:R:T:")) != -1) { switch (ch) { case 'c': nochdir = 0; @@ -107,6 +109,9 @@ case 'f': noclose = 0; break; + case 'i': + pidmode=0644; + break; case 'l': logfac = get_log_mapping(optarg, facilitynames); if (logfac == -1) @@ -181,7 +186,7 @@ * Try to open the pidfile before calling daemon(3), * to be able to report the error intelligently */ - open_pid_files(pidfile, ppidfile, &pfh, &ppfh); + open_pid_files(pidfile, ppidfile, &pfh, &ppfh, pidmode); if (daemon(nochdir, noclose) == -1) { warn("daemon"); goto exit; @@ -392,13 +397,13 @@ static void open_pid_files(const char *pidfile, const char *ppidfile, - struct pidfh **pfh, struct pidfh **ppfh) + struct pidfh **pfh, struct pidfh **ppfh, mode_t pidmode) { pid_t fpid; int serrno; if (pidfile) { - *pfh = pidfile_open(pidfile, 0600, &fpid); + *pfh = pidfile_open(pidfile, pidmode, &fpid); if (*pfh == NULL) { if (errno == EEXIST) { errx(3, "process already running, pid: %d", @@ -409,7 +414,7 @@ } /* Do the same for the actual daemon process. */ if (ppidfile) { - *ppfh = pidfile_open(ppidfile, 0600, &fpid); + *ppfh = pidfile_open(ppidfile, pidmode, &fpid); if (*ppfh == NULL) { serrno = errno; pidfile_remove(*pfh); @@ -560,7 +565,7 @@ usage(void) { (void)fprintf(stderr, - "usage: daemon [-cfrS] [-p child_pidfile] [-P supervisor_pidfile]\n" + "usage: daemon [-cfirS] [-p child_pidfile] [-P supervisor_pidfile]\n" " [-u user] [-o output_file] [-t title]\n" " [-l syslog_facility] [-s syslog_priority]\n" " [-T syslog_tag] [-m output_mask] [-R restart_delay_secs]\n"