scanner sc;
uid_t drop = -1;
gid_t dropg = -1;
+ const char *pidfile = 0;
conffile *cf, **cff = &conffiles;
#define f_bogus 1u
{ "file", OPTF_ARGREQ, 0, 'f' },
{ "fork", 0, 0, 'd' },
{ "daemon", 0, 0, 'd' },
+ { "pidfile", OPTF_ARGREQ, 0, 'p' },
{ "syslog", 0, 0, 'l' },
{ "log", 0, 0, 'l' },
{ "quiet", 0, 0, 'q' },
{ 0, 0, 0, 0 }
};
- int i = mdwopt(argc, argv, "+hvu GO f:dls:g:", opts, 0, 0, 0);
+ int i = mdwopt(argc, argv, "+hvu" "GO" "f:dp:ls:g:", opts, 0, 0, 0);
if (i < 0)
break;
case 'd':
f |= f_fork;
break;
+ case 'p':
+ pidfile = optarg;
+ break;
case 'l':
f |= f_syslog;
break;
if (kid != 0)
_exit(0);
}
+ if (pidfile) {
+ FILE *fp = fopen(pidfile, "w");
+ if (!fp) {
+ die(EXIT_FAILURE, "couldn't create pidfile `%s': %s",
+ pidfile, strerror(errno));
+ }
+ fprintf(fp, "%lu\n", (unsigned long)getpid());
+ if (fflush(fp) || ferror(fp) || fclose(fp)) {
+ die(EXIT_FAILURE, "couldn't write pidfile `%s': %s",
+ pidfile, strerror(errno));
+ }
+ }
if (f & f_syslog) {
flags |= FW_SYSLOG;