Re: syslogd in foreground

2015-06-12 Thread Todd C. Miller
On Fri, 12 Jun 2015 21:02:47 +0200, Alexander Bluhm wrote:

> You are right.  Then this is the correct diff.  ok?

OK millert@

 - todd



Re: syslogd in foreground

2015-06-12 Thread Alexander Bluhm
On Fri, Jun 12, 2015 at 12:53:34PM -0600, Todd C. Miller wrote:
> > I wanted both places were we close the lockpipe in a consistent
> > order.  Now I think we should compare the fd with 2 in both places
> > to have the same level of paranoia as with nullfd a few lines below.
> 
> It is safer to close the lock fd first for the following reasons:
> 
> 1) No need to check whether it might be in the range 0-2.
> 
> 2) You free up a free fd slot in case resource limits are
>low.

You are right.  Then this is the correct diff.  ok?

bluhm

Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.162
diff -u -p -r1.162 syslogd.c
--- usr.sbin/syslogd/syslogd.c  12 Jun 2015 00:54:28 -  1.162
+++ usr.sbin/syslogd/syslogd.c  12 Jun 2015 18:59:17 -
@@ -629,10 +629,10 @@ main(int argc, char *argv[])
reply_text = ctl_reply + CTL_HDR_LEN;
 
if (!Debug) {
+   close(lockpipe[1]);
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
-   close(lockpipe[1]);
}
if (nullfd > 2)
close(nullfd);



Re: syslogd in foreground

2015-06-12 Thread Anthony J. Bentley
"Todd C. Miller" writes:
> > @@ -85,6 +85,8 @@ and do not disassociate from the control
> >  Specify the pathname of an alternate configuration file;
> >  the default is
> >  .Pa /etc/syslog.conf .
> > +.It Fl F
> > +Do not daemonize and stay in foreground.
> 
> Since "daemonize" is not a word, how about something like:
> 
> Run in the foreground instead of disassociating from the controlling
> terminal and running as a background daemon.

True, "daemonize" is not a word, but it is used very frequently in
our documentation, and the meaning is pretty clear.

$ grep daemonize /usr/share/man/man8/* | wc -l
  27

-- 
Anthony J. Bentley



Re: syslogd in foreground

2015-06-12 Thread Todd C. Miller
On Fri, 12 Jun 2015 20:43:33 +0200, Alexander Bluhm wrote:

> I wanted both places were we close the lockpipe in a consistent
> order.  Now I think we should compare the fd with 2 in both places
> to have the same level of paranoia as with nullfd a few lines below.

It is safer to close the lock fd first for the following reasons:

1) No need to check whether it might be in the range 0-2.

2) You free up a free fd slot in case resource limits are
   low.

 - todd



Re: syslogd in foreground

2015-06-12 Thread Alexander Bluhm
On Fri, Jun 12, 2015 at 10:30:18AM -0600, Todd C. Miller wrote:
> > I need a syslogd running in foreground for a project.  FreeBSD
> > also uses the option -F for that.
> 
> I don't have any objection to that.  A few comments inline.

Theo convinced me that this feature does not make sense for OpenBSD.

> Why move the close(lockfd) here?

I wanted both places were we close the lockpipe in a consistent
order.  Now I think we should compare the fd with 2 in both places
to have the same level of paranoia as with nullfd a few lines below.

ok for this part?

> Since "daemonize" is not a word, how about something like:
> 
> Run in the foreground instead of disassociating from the controlling
> terminal and running as a background daemon.

Thanks for your input.

bluhm

Index: usr.sbin/syslogd/privsep.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/privsep.c,v
retrieving revision 1.51
diff -u -p -r1.51 privsep.c
--- usr.sbin/syslogd/privsep.c  19 Jan 2015 16:40:49 -  1.51
+++ usr.sbin/syslogd/privsep.c  12 Jun 2015 18:41:07 -
@@ -151,10 +151,11 @@ priv_init(char *conf, int numeric, int l
}
 
if (!Debug) {
-   close(lockfd);
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
+   if (lockfd > 2)
+   close(lockfd);
}
if (nullfd > 2)
close(nullfd);
Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.162
diff -u -p -r1.162 syslogd.c
--- usr.sbin/syslogd/syslogd.c  12 Jun 2015 00:54:28 -  1.162
+++ usr.sbin/syslogd/syslogd.c  12 Jun 2015 18:40:30 -
@@ -632,7 +632,8 @@ main(int argc, char *argv[])
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
-   close(lockpipe[1]);
+   if (lockpipe[1] > 2)
+   close(lockpipe[1]);
}
if (nullfd > 2)
close(nullfd);



Re: syslogd in foreground

2015-06-12 Thread Todd C. Miller
On Fri, 12 Jun 2015 01:07:57 +0200, Alexander Bluhm wrote:

> I need a syslogd running in foreground for a project.  FreeBSD
> also uses the option -F for that.

I don't have any objection to that.  A few comments inline.

 - todd

> Index: usr.sbin/syslogd/privsep.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/privsep.c,v
> retrieving revision 1.51
> diff -u -p -r1.51 privsep.c
> --- usr.sbin/syslogd/privsep.c19 Jan 2015 16:40:49 -  1.51
> +++ usr.sbin/syslogd/privsep.c11 Jun 2015 22:58:31 -
> @@ -151,10 +151,10 @@ priv_init(char *conf, int numeric, int l
>   }
>  
>   if (!Debug) {
> - close(lockfd);
>   dup2(nullfd, STDIN_FILENO);
>   dup2(nullfd, STDOUT_FILENO);
>   dup2(nullfd, STDERR_FILENO);
> + close(lockfd);

Why move the close(lockfd) here?

>   }
>   if (nullfd > 2)
>   close(nullfd);
> Index: usr.sbin/syslogd/syslogd.8
> ===
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.8,v
> retrieving revision 1.33
> diff -u -p -r1.33 syslogd.8
> --- usr.sbin/syslogd/syslogd.830 Jan 2015 14:09:49 -  1.33
> +++ usr.sbin/syslogd/syslogd.811 Jun 2015 22:55:14 -
> @@ -39,7 +39,7 @@
>  .Sh SYNOPSIS
>  .Nm syslogd
>  .Bk -words
> -.Op Fl 46dhnuV
> +.Op Fl 46dFhnuV
>  .Op Fl a Ar path
>  .Op Fl C Ar CAfile
>  .Op Fl f Ar config_file
> @@ -85,6 +85,8 @@ and do not disassociate from the control
>  Specify the pathname of an alternate configuration file;
>  the default is
>  .Pa /etc/syslog.conf .
> +.It Fl F
> +Do not daemonize and stay in foreground.

Since "daemonize" is not a word, how about something like:

Run in the foreground instead of disassociating from the controlling
terminal and running as a background daemon.

>  .It Fl h
>  Include the hostname when forwarding messages to a remote host.
>  .It Fl m Ar mark_interval
> Index: usr.sbin/syslogd/syslogd.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
> retrieving revision 1.161
> diff -u -p -r1.161 syslogd.c
> --- usr.sbin/syslogd/syslogd.c30 Mar 2015 09:21:42 -  1.161
> +++ usr.sbin/syslogd/syslogd.c11 Jun 2015 22:59:10 -
> @@ -205,6 +205,7 @@ structfiled consfile;
>  int  nunix = 1;  /* Number of Unix domain sockets requested */
>  char *path_unix[MAXUNIX] = { _PATH_LOG }; /* Paths to Unix domain sockets */
>  int  Debug;  /* debug flag */
> +int  Foreground; /* run in foreground, instead of daemonizing */
>  int  Startup = 1;/* startup flag */
>  char LocalHostName[HOST_NAME_MAX+1]; /* our hostname */
>  char *LocalDomain;   /* our local domain name */
> @@ -328,7 +329,7 @@ main(int argc, char *argv[])
>   int  ch, i;
>   int  lockpipe[2] = { -1, -1}, pair[2], nullfd, fd;
>  
> - while ((ch = getopt(argc, argv, "46C:dhnuf:m:p:a:s:V")) != -1)
> + while ((ch = getopt(argc, argv, "46C:dhnuf:Fm:p:a:s:V")) != -1)
>   switch (ch) {
>   case '4':   /* disable IPv6 */
>   IPv4Only = 1;
> @@ -347,6 +348,9 @@ main(int argc, char *argv[])
>   case 'f':   /* configuration file */
>   ConfFile = optarg;
>   break;
> + case 'F':   /* foreground */
> + Foreground = 1;
> + break;
>   case 'h':   /* RFC 3164 hostnames */
>   IncludeHostname = 1;
>   break;
> @@ -557,7 +561,7 @@ main(int argc, char *argv[])
>  
>   tzset();
>  
> - if (!Debug) {
> + if (!Debug && !Foreground) {
>   char c;
>  
>   pipe(lockpipe);
> @@ -969,7 +973,7 @@ usage(void)
>  {
>  
>   (void)fprintf(stderr,
> - "usage: syslogd [-46dhnuV] [-a path] [-C CAfile] [-f config_file]\n
> "
> + "usage: syslogd [-46dFhnuV] [-a path] [-C CAfile] [-f config_file]\
> n"
>   "   [-m mark_interval] [-p log_socket] [-s reporting_so
> cket]\n");
>   exit(1);
>  }
> 



Re: syslogd in foreground

2015-06-12 Thread Sebastian Benoit
Alexander Bluhm(alexander.bl...@gmx.net) on 2015.06.12 01:07:57 +0200:
> Hi,
> 
> I need a syslogd running in foreground for a project.  FreeBSD
> also uses the option -F for that.
> 
> Do we want this feature in OpenBSD?

i dont see why not, and -d does obviously too much.
-F is fine, nobody else has another flag

> ok?

ok.

maybe the manpage should use the same wording as for -d: 
"do not disassociate from the controlling terminal"?

> bluhm
> 
> Index: usr.sbin/syslogd/privsep.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/privsep.c,v
> retrieving revision 1.51
> diff -u -p -r1.51 privsep.c
> --- usr.sbin/syslogd/privsep.c19 Jan 2015 16:40:49 -  1.51
> +++ usr.sbin/syslogd/privsep.c11 Jun 2015 22:58:31 -
> @@ -151,10 +151,10 @@ priv_init(char *conf, int numeric, int l
>   }
>  
>   if (!Debug) {
> - close(lockfd);
>   dup2(nullfd, STDIN_FILENO);
>   dup2(nullfd, STDOUT_FILENO);
>   dup2(nullfd, STDERR_FILENO);
> + close(lockfd);
>   }
>   if (nullfd > 2)
>   close(nullfd);
> Index: usr.sbin/syslogd/syslogd.8
> ===
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.8,v
> retrieving revision 1.33
> diff -u -p -r1.33 syslogd.8
> --- usr.sbin/syslogd/syslogd.830 Jan 2015 14:09:49 -  1.33
> +++ usr.sbin/syslogd/syslogd.811 Jun 2015 22:55:14 -
> @@ -39,7 +39,7 @@
>  .Sh SYNOPSIS
>  .Nm syslogd
>  .Bk -words
> -.Op Fl 46dhnuV
> +.Op Fl 46dFhnuV
>  .Op Fl a Ar path
>  .Op Fl C Ar CAfile
>  .Op Fl f Ar config_file
> @@ -85,6 +85,8 @@ and do not disassociate from the control
>  Specify the pathname of an alternate configuration file;
>  the default is
>  .Pa /etc/syslog.conf .
> +.It Fl F
> +Do not daemonize and stay in foreground.
>  .It Fl h
>  Include the hostname when forwarding messages to a remote host.
>  .It Fl m Ar mark_interval
> Index: usr.sbin/syslogd/syslogd.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
> retrieving revision 1.161
> diff -u -p -r1.161 syslogd.c
> --- usr.sbin/syslogd/syslogd.c30 Mar 2015 09:21:42 -  1.161
> +++ usr.sbin/syslogd/syslogd.c11 Jun 2015 22:59:10 -
> @@ -205,6 +205,7 @@ structfiled consfile;
>  int  nunix = 1;  /* Number of Unix domain sockets requested */
>  char *path_unix[MAXUNIX] = { _PATH_LOG }; /* Paths to Unix domain sockets */
>  int  Debug;  /* debug flag */
> +int  Foreground; /* run in foreground, instead of daemonizing */
>  int  Startup = 1;/* startup flag */
>  char LocalHostName[HOST_NAME_MAX+1]; /* our hostname */
>  char *LocalDomain;   /* our local domain name */
> @@ -328,7 +329,7 @@ main(int argc, char *argv[])
>   int  ch, i;
>   int  lockpipe[2] = { -1, -1}, pair[2], nullfd, fd;
>  
> - while ((ch = getopt(argc, argv, "46C:dhnuf:m:p:a:s:V")) != -1)
> + while ((ch = getopt(argc, argv, "46C:dhnuf:Fm:p:a:s:V")) != -1)
>   switch (ch) {
>   case '4':   /* disable IPv6 */
>   IPv4Only = 1;
> @@ -347,6 +348,9 @@ main(int argc, char *argv[])
>   case 'f':   /* configuration file */
>   ConfFile = optarg;
>   break;
> + case 'F':   /* foreground */
> + Foreground = 1;
> + break;
>   case 'h':   /* RFC 3164 hostnames */
>   IncludeHostname = 1;
>   break;
> @@ -557,7 +561,7 @@ main(int argc, char *argv[])
>  
>   tzset();
>  
> - if (!Debug) {
> + if (!Debug && !Foreground) {
>   char c;
>  
>   pipe(lockpipe);
> @@ -969,7 +973,7 @@ usage(void)
>  {
>  
>   (void)fprintf(stderr,
> - "usage: syslogd [-46dhnuV] [-a path] [-C CAfile] [-f config_file]\n"
> + "usage: syslogd [-46dFhnuV] [-a path] [-C CAfile] [-f 
> config_file]\n"
>   "   [-m mark_interval] [-p log_socket] [-s 
> reporting_socket]\n");
>   exit(1);
>  }
> 

-- 



syslogd in foreground

2015-06-11 Thread Alexander Bluhm
Hi,

I need a syslogd running in foreground for a project.  FreeBSD
also uses the option -F for that.

Do we want this feature in OpenBSD?
ok?

bluhm

Index: usr.sbin/syslogd/privsep.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/privsep.c,v
retrieving revision 1.51
diff -u -p -r1.51 privsep.c
--- usr.sbin/syslogd/privsep.c  19 Jan 2015 16:40:49 -  1.51
+++ usr.sbin/syslogd/privsep.c  11 Jun 2015 22:58:31 -
@@ -151,10 +151,10 @@ priv_init(char *conf, int numeric, int l
}
 
if (!Debug) {
-   close(lockfd);
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
+   close(lockfd);
}
if (nullfd > 2)
close(nullfd);
Index: usr.sbin/syslogd/syslogd.8
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.8,v
retrieving revision 1.33
diff -u -p -r1.33 syslogd.8
--- usr.sbin/syslogd/syslogd.8  30 Jan 2015 14:09:49 -  1.33
+++ usr.sbin/syslogd/syslogd.8  11 Jun 2015 22:55:14 -
@@ -39,7 +39,7 @@
 .Sh SYNOPSIS
 .Nm syslogd
 .Bk -words
-.Op Fl 46dhnuV
+.Op Fl 46dFhnuV
 .Op Fl a Ar path
 .Op Fl C Ar CAfile
 .Op Fl f Ar config_file
@@ -85,6 +85,8 @@ and do not disassociate from the control
 Specify the pathname of an alternate configuration file;
 the default is
 .Pa /etc/syslog.conf .
+.It Fl F
+Do not daemonize and stay in foreground.
 .It Fl h
 Include the hostname when forwarding messages to a remote host.
 .It Fl m Ar mark_interval
Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.161
diff -u -p -r1.161 syslogd.c
--- usr.sbin/syslogd/syslogd.c  30 Mar 2015 09:21:42 -  1.161
+++ usr.sbin/syslogd/syslogd.c  11 Jun 2015 22:59:10 -
@@ -205,6 +205,7 @@ struct  filed consfile;
 intnunix = 1;  /* Number of Unix domain sockets requested */
 char   *path_unix[MAXUNIX] = { _PATH_LOG }; /* Paths to Unix domain sockets */
 intDebug;  /* debug flag */
+intForeground; /* run in foreground, instead of daemonizing */
 intStartup = 1;/* startup flag */
 char   LocalHostName[HOST_NAME_MAX+1]; /* our hostname */
 char   *LocalDomain;   /* our local domain name */
@@ -328,7 +329,7 @@ main(int argc, char *argv[])
int  ch, i;
int  lockpipe[2] = { -1, -1}, pair[2], nullfd, fd;
 
-   while ((ch = getopt(argc, argv, "46C:dhnuf:m:p:a:s:V")) != -1)
+   while ((ch = getopt(argc, argv, "46C:dhnuf:Fm:p:a:s:V")) != -1)
switch (ch) {
case '4':   /* disable IPv6 */
IPv4Only = 1;
@@ -347,6 +348,9 @@ main(int argc, char *argv[])
case 'f':   /* configuration file */
ConfFile = optarg;
break;
+   case 'F':   /* foreground */
+   Foreground = 1;
+   break;
case 'h':   /* RFC 3164 hostnames */
IncludeHostname = 1;
break;
@@ -557,7 +561,7 @@ main(int argc, char *argv[])
 
tzset();
 
-   if (!Debug) {
+   if (!Debug && !Foreground) {
char c;
 
pipe(lockpipe);
@@ -969,7 +973,7 @@ usage(void)
 {
 
(void)fprintf(stderr,
-   "usage: syslogd [-46dhnuV] [-a path] [-C CAfile] [-f config_file]\n"
+   "usage: syslogd [-46dFhnuV] [-a path] [-C CAfile] [-f 
config_file]\n"
"   [-m mark_interval] [-p log_socket] [-s 
reporting_socket]\n");
exit(1);
 }