Re: syslogd libevent

2014-10-04 Thread Alexander Bluhm
On Sat, Oct 04, 2014 at 09:03:58AM +0100, Nicholas Marriott wrote:
> This should be:
> 
> LDADD=  -levent
> DPADD=  ${LIBEVENT}
> 
> Rather than LDFLAGS.

Here is the updated diff.

Index: usr.sbin/syslogd/Makefile
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/Makefile,v
retrieving revision 1.5
diff -u -p -r1.5 Makefile
--- usr.sbin/syslogd/Makefile   4 Jan 2004 08:28:49 -   1.5
+++ usr.sbin/syslogd/Makefile   4 Oct 2014 09:17:53 -
@@ -3,5 +3,7 @@
 PROG=  syslogd
 SRCS=  syslogd.c ttymsg.c privsep.c privsep_fdpass.c ringbuf.c
 MAN=   syslogd.8 syslog.conf.5
+LDADD= -levent
+DPADD= ${LIBEVENT}
 
 .include 
Index: usr.sbin/syslogd/privsep.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/privsep.c,v
retrieving revision 1.47
diff -u -p -r1.47 privsep.c
--- usr.sbin/syslogd/privsep.c  3 Oct 2014 21:55:22 -   1.47
+++ usr.sbin/syslogd/privsep.c  4 Oct 2014 09:17:25 -
@@ -171,21 +171,21 @@ priv_init(char *conf, int numeric, int l
close(socks[1]);
 
/* Close descriptors that only the unpriv child needs */
+   if (fd_ctlconn != -1)
+   close(fd_ctlconn);
+   if (fd_ctlsock != -1)
+   close(fd_ctlsock);
+   if (fd_klog != -1)
+   close(fd_klog);
+   if (fd_sendsys != -1)
+   close(fd_sendsys);
+   if (fd_udp != -1)
+   close(fd_udp);
+   if (fd_udp6 != -1)
+   close(fd_udp6);
for (i = 0; i < nunix; i++)
-   if (pfd[PFD_UNIX_0 + i].fd != -1)
-   close(pfd[PFD_UNIX_0 + i].fd);
-   if (pfd[PFD_INET].fd != -1)
-   close(pfd[PFD_INET].fd);
-   if (pfd[PFD_INET6].fd != -1)
-   close(pfd[PFD_INET6].fd);
-   if (pfd[PFD_CTLSOCK].fd != -1)
-   close(pfd[PFD_CTLSOCK].fd);
-   if (pfd[PFD_CTLCONN].fd != -1)
-   close(pfd[PFD_CTLCONN].fd);
-   if (pfd[PFD_KLOG].fd != -1)
-   close(pfd[PFD_KLOG].fd);
-   if (pfd[PFD_SENDSYS].fd != -1)
-   close(pfd[PFD_SENDSYS].fd);
+   if (fd_unix[i] != -1)
+   close(fd_unix[i]);
 
/* Save the config file specified by the child process */
if (strlcpy(config_file, conf, sizeof config_file) >= 
sizeof(config_file))
@@ -371,9 +371,9 @@ priv_init(char *conf, int numeric, int l
 
/* Unlink any domain sockets that have been opened */
for (i = 0; i < nunix; i++)
-   if (pfd[PFD_UNIX_0 + i].fd != -1)
+   if (fd_unix[i] != -1)
(void)unlink(path_unix[i]);
-   if (path_ctlsock != NULL && pfd[PFD_CTLSOCK].fd != -1)
+   if (path_ctlsock != NULL && fd_ctlsock != -1)
(void)unlink(path_ctlsock);
 
if (restart) {
Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.127
diff -u -p -r1.127 syslogd.c
--- usr.sbin/syslogd/syslogd.c  3 Oct 2014 21:55:22 -   1.127
+++ usr.sbin/syslogd/syslogd.c  4 Oct 2014 09:17:25 -
@@ -50,6 +50,7 @@
  * extensive changes by Ralph Campbell
  * more extensive changes by Eric Allman (again)
  * memory buffer logging by Damien Miller
+ * IPv6, libevent by Alexander Bluhm
  */
 
 #defineMAXLINE 1024/* maximum line length */
@@ -81,6 +82,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -248,23 +250,28 @@ size_tctl_reply_offset = 0;   /* Number o
 char   *linebuf;
 int linesize;
 
-voidklog_read_handler(int);
-voidudp_read_handler(int);
-voidunix_read_handler(int);
-
-struct pollfd pfd[N_PFD];
-
-volatile sig_atomic_t MarkSet;
-volatile sig_atomic_t WantDie;
-volatile sig_atomic_t DoInit;
+int fd_ctlsock, fd_ctlconn, fd_klog, fd_sendsys,
+fd_udp, fd_udp6, fd_unix[MAXUNIX];
+struct eventev_ctlaccept, ev_ctlread, ev_ctlwrite, ev_klog, ev_sendsys,
+ev_udp, ev_udp6, ev_unix[MAXUNIX],
+ev_hup, ev_int, ev_quit, ev_term, ev_mark;
+
+voidklog_readcb(int, short, void *);
+voidudp_readcb(int, short, void *);
+voidunix_readcb(int, short, void *);
+voiddie_signalcb(int, short, void *);
+voidmark_timercb(int, short, void *);
+voidinit_signalcb(int, short, void *);
+voidctlsock_acceptcb(int, short, void *);
+voidctlconn_readcb(int, short, void *);
+voidctlconn_writecb(int, short, void *);
+voidctlconn_logto(char *);
+voidctlconn_cleanup(void);
 
 struct filed *cfline(char *, char *);
 void   cvthname(struct sockaddr *, char *, size_t);
 intdecode(const char *, const CODE *);
-void   dodie(int);
-void   doinit(int);
 void   die(int);
-void   domark(int);
 void   markit(void);
 void   fprintlog(struct fi

Re: syslogd libevent

2014-10-04 Thread Nicholas Marriott
On Sat, Oct 04, 2014 at 01:29:21AM +0200, Alexander Bluhm wrote:
> Hi,
> 
> After some preparation, I can convert syslogd to use libevent now.
> 
> ok?
> 
> bluhm
> 
> Index: usr.sbin/syslogd/Makefile
> ===
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/Makefile,v
> retrieving revision 1.5
> diff -u -p -u -p -r1.5 Makefile
> --- usr.sbin/syslogd/Makefile 4 Jan 2004 08:28:49 -   1.5
> +++ usr.sbin/syslogd/Makefile 3 Oct 2014 22:30:00 -
> @@ -1,7 +1,8 @@
>  #$OpenBSD: Makefile,v 1.5 2004/01/04 08:28:49 djm Exp $
>  
> -PROG=syslogd
> -SRCS=syslogd.c ttymsg.c privsep.c privsep_fdpass.c ringbuf.c
> -MAN= syslogd.8 syslog.conf.5
> +PROG =   syslogd
> +SRCS =   syslogd.c ttymsg.c privsep.c privsep_fdpass.c ringbuf.c
> +MAN =syslogd.8 syslog.conf.5
> +LDFLAGS =-levent

This should be:

LDADD=  -levent
DPADD=  ${LIBEVENT}

Rather than LDFLAGS.

Otherwise this looks good and works fine for me.

>  
>  .include 
> Index: usr.sbin/syslogd/privsep.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/privsep.c,v
> retrieving revision 1.47
> diff -u -p -u -p -r1.47 privsep.c
> --- usr.sbin/syslogd/privsep.c3 Oct 2014 21:55:22 -   1.47
> +++ usr.sbin/syslogd/privsep.c3 Oct 2014 23:03:50 -
> @@ -171,21 +171,21 @@ priv_init(char *conf, int numeric, int l
>   close(socks[1]);
>  
>   /* Close descriptors that only the unpriv child needs */
> + if (fd_ctlconn != -1)
> + close(fd_ctlconn);
> + if (fd_ctlsock != -1)
> + close(fd_ctlsock);
> + if (fd_klog != -1)
> + close(fd_klog);
> + if (fd_sendsys != -1)
> + close(fd_sendsys);
> + if (fd_udp != -1)
> + close(fd_udp);
> + if (fd_udp6 != -1)
> + close(fd_udp6);
>   for (i = 0; i < nunix; i++)
> - if (pfd[PFD_UNIX_0 + i].fd != -1)
> - close(pfd[PFD_UNIX_0 + i].fd);
> - if (pfd[PFD_INET].fd != -1)
> - close(pfd[PFD_INET].fd);
> - if (pfd[PFD_INET6].fd != -1)
> - close(pfd[PFD_INET6].fd);
> - if (pfd[PFD_CTLSOCK].fd != -1)
> - close(pfd[PFD_CTLSOCK].fd);
> - if (pfd[PFD_CTLCONN].fd != -1)
> - close(pfd[PFD_CTLCONN].fd);
> - if (pfd[PFD_KLOG].fd != -1)
> - close(pfd[PFD_KLOG].fd);
> - if (pfd[PFD_SENDSYS].fd != -1)
> - close(pfd[PFD_SENDSYS].fd);
> + if (fd_unix[i] != -1)
> + close(fd_unix[i]);
>  
>   /* Save the config file specified by the child process */
>   if (strlcpy(config_file, conf, sizeof config_file) >= 
> sizeof(config_file))
> @@ -371,9 +371,9 @@ priv_init(char *conf, int numeric, int l
>  
>   /* Unlink any domain sockets that have been opened */
>   for (i = 0; i < nunix; i++)
> - if (pfd[PFD_UNIX_0 + i].fd != -1)
> + if (fd_unix[i] != -1)
>   (void)unlink(path_unix[i]);
> - if (path_ctlsock != NULL && pfd[PFD_CTLSOCK].fd != -1)
> + if (path_ctlsock != NULL && fd_ctlsock != -1)
>   (void)unlink(path_ctlsock);
>  
>   if (restart) {
> Index: usr.sbin/syslogd/syslogd.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
> retrieving revision 1.127
> diff -u -p -u -p -r1.127 syslogd.c
> --- usr.sbin/syslogd/syslogd.c3 Oct 2014 21:55:22 -   1.127
> +++ usr.sbin/syslogd/syslogd.c3 Oct 2014 23:09:30 -
> @@ -50,6 +50,7 @@
>   * extensive changes by Ralph Campbell
>   * more extensive changes by Eric Allman (again)
>   * memory buffer logging by Damien Miller
> + * IPv6, libevent by Alexander Bluhm
>   */
>  
>  #define  MAXLINE 1024/* maximum line length */
> @@ -81,6 +82,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -248,23 +250,28 @@ size_t  ctl_reply_offset = 0;   /* Number o
>  char *linebuf;
>  int   linesize;
>  
> -void  klog_read_handler(int);
> -void  udp_read_handler(int);
> -void  unix_read_handler(int);
> -
> -struct pollfd pfd[N_PFD];
> -
> -volatile sig_atomic_t MarkSet;
> -volatile sig_atomic_t WantDie;
> -volatile sig_atomic_t DoInit;
> +int   fd_ctlsock, fd_ctlconn, fd_klog, fd_sendsys,
> +  fd_udp, fd_udp6, fd_unix[MAXUNIX];
> +struct event  ev_ctlaccept, ev_ctlread, ev_ctlwrite, ev_klog, ev_sendsys,
> +  ev_udp, ev_udp6, ev_unix[MAXUNIX],
> +  ev_hup, ev_int, ev_quit, ev_term, ev_mark;
> +
> +void  klog_readcb(int, short, void *);
> +void  udp_readcb(int, short, void *);
> +void  unix_readcb(int, short, void *);
> +void  die_signalcb(int, short, void *);
> +void  mark_timercb(int, short, void *);
> +void  init_signalcb(in

Re: syslogd libevent

2014-10-03 Thread Alexander Bluhm
Hi,

After some preparation, I can convert syslogd to use libevent now.

ok?

bluhm

Index: usr.sbin/syslogd/Makefile
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/Makefile,v
retrieving revision 1.5
diff -u -p -u -p -r1.5 Makefile
--- usr.sbin/syslogd/Makefile   4 Jan 2004 08:28:49 -   1.5
+++ usr.sbin/syslogd/Makefile   3 Oct 2014 22:30:00 -
@@ -1,7 +1,8 @@
 #  $OpenBSD: Makefile,v 1.5 2004/01/04 08:28:49 djm Exp $
 
-PROG=  syslogd
-SRCS=  syslogd.c ttymsg.c privsep.c privsep_fdpass.c ringbuf.c
-MAN=   syslogd.8 syslog.conf.5
+PROG = syslogd
+SRCS = syslogd.c ttymsg.c privsep.c privsep_fdpass.c ringbuf.c
+MAN =  syslogd.8 syslog.conf.5
+LDFLAGS =  -levent
 
 .include 
Index: usr.sbin/syslogd/privsep.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/privsep.c,v
retrieving revision 1.47
diff -u -p -u -p -r1.47 privsep.c
--- usr.sbin/syslogd/privsep.c  3 Oct 2014 21:55:22 -   1.47
+++ usr.sbin/syslogd/privsep.c  3 Oct 2014 23:03:50 -
@@ -171,21 +171,21 @@ priv_init(char *conf, int numeric, int l
close(socks[1]);
 
/* Close descriptors that only the unpriv child needs */
+   if (fd_ctlconn != -1)
+   close(fd_ctlconn);
+   if (fd_ctlsock != -1)
+   close(fd_ctlsock);
+   if (fd_klog != -1)
+   close(fd_klog);
+   if (fd_sendsys != -1)
+   close(fd_sendsys);
+   if (fd_udp != -1)
+   close(fd_udp);
+   if (fd_udp6 != -1)
+   close(fd_udp6);
for (i = 0; i < nunix; i++)
-   if (pfd[PFD_UNIX_0 + i].fd != -1)
-   close(pfd[PFD_UNIX_0 + i].fd);
-   if (pfd[PFD_INET].fd != -1)
-   close(pfd[PFD_INET].fd);
-   if (pfd[PFD_INET6].fd != -1)
-   close(pfd[PFD_INET6].fd);
-   if (pfd[PFD_CTLSOCK].fd != -1)
-   close(pfd[PFD_CTLSOCK].fd);
-   if (pfd[PFD_CTLCONN].fd != -1)
-   close(pfd[PFD_CTLCONN].fd);
-   if (pfd[PFD_KLOG].fd != -1)
-   close(pfd[PFD_KLOG].fd);
-   if (pfd[PFD_SENDSYS].fd != -1)
-   close(pfd[PFD_SENDSYS].fd);
+   if (fd_unix[i] != -1)
+   close(fd_unix[i]);
 
/* Save the config file specified by the child process */
if (strlcpy(config_file, conf, sizeof config_file) >= 
sizeof(config_file))
@@ -371,9 +371,9 @@ priv_init(char *conf, int numeric, int l
 
/* Unlink any domain sockets that have been opened */
for (i = 0; i < nunix; i++)
-   if (pfd[PFD_UNIX_0 + i].fd != -1)
+   if (fd_unix[i] != -1)
(void)unlink(path_unix[i]);
-   if (path_ctlsock != NULL && pfd[PFD_CTLSOCK].fd != -1)
+   if (path_ctlsock != NULL && fd_ctlsock != -1)
(void)unlink(path_ctlsock);
 
if (restart) {
Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.127
diff -u -p -u -p -r1.127 syslogd.c
--- usr.sbin/syslogd/syslogd.c  3 Oct 2014 21:55:22 -   1.127
+++ usr.sbin/syslogd/syslogd.c  3 Oct 2014 23:09:30 -
@@ -50,6 +50,7 @@
  * extensive changes by Ralph Campbell
  * more extensive changes by Eric Allman (again)
  * memory buffer logging by Damien Miller
+ * IPv6, libevent by Alexander Bluhm
  */
 
 #defineMAXLINE 1024/* maximum line length */
@@ -81,6 +82,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -248,23 +250,28 @@ size_tctl_reply_offset = 0;   /* Number o
 char   *linebuf;
 int linesize;
 
-voidklog_read_handler(int);
-voidudp_read_handler(int);
-voidunix_read_handler(int);
-
-struct pollfd pfd[N_PFD];
-
-volatile sig_atomic_t MarkSet;
-volatile sig_atomic_t WantDie;
-volatile sig_atomic_t DoInit;
+int fd_ctlsock, fd_ctlconn, fd_klog, fd_sendsys,
+fd_udp, fd_udp6, fd_unix[MAXUNIX];
+struct eventev_ctlaccept, ev_ctlread, ev_ctlwrite, ev_klog, ev_sendsys,
+ev_udp, ev_udp6, ev_unix[MAXUNIX],
+ev_hup, ev_int, ev_quit, ev_term, ev_mark;
+
+voidklog_readcb(int, short, void *);
+voidudp_readcb(int, short, void *);
+voidunix_readcb(int, short, void *);
+voiddie_signalcb(int, short, void *);
+voidmark_timercb(int, short, void *);
+voidinit_signalcb(int, short, void *);
+voidctlsock_acceptcb(int, short, void *);
+voidctlconn_readcb(int, short, void *);
+voidctlconn_writecb(int, short, void *);
+voidctlconn_logto(char *);
+voidctlconn_cleanup(void);
 
 struct filed *cfline(char *, char *);
 void   cvthname(struct sockaddr *, char *, size_t);
 intdecode(const char *, const CODE *);
-void   dodie(int);

Re: syslogd libevent

2014-09-26 Thread Alexander Bluhm
On Fri, Aug 29, 2014 at 11:25:52PM +0200, Alexander Bluhm wrote:
> try to pull parts of the diff into separate changes to make review
> easier.

Also in debug mode, close nullfd when it is not needed anymore.

ok?

bluhm

Index: usr.sbin/syslogd/privsep.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/privsep.c,v
retrieving revision 1.45
diff -u -p -u -p -r1.45 privsep.c
--- usr.sbin/syslogd/privsep.c  10 Sep 2014 13:16:20 -  1.45
+++ usr.sbin/syslogd/privsep.c  25 Sep 2014 14:43:40 -
@@ -153,7 +153,6 @@ priv_init(char *conf, int numeric, int l
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
}
-
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.124
diff -u -p -u -p -r1.124 syslogd.c
--- usr.sbin/syslogd/syslogd.c  10 Sep 2014 13:16:20 -  1.124
+++ usr.sbin/syslogd/syslogd.c  25 Sep 2014 14:43:40 -
@@ -539,10 +539,10 @@ main(int argc, char *argv[])
dup2(nullfd, STDIN_FILENO);
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
-   if (nullfd > 2)
-   close(nullfd);
close(lockpipe[1]);
}
+   if (nullfd > 2)
+   close(nullfd);
 
/*
 * Signal to the priv process that the initial config parsing is done



Re: syslogd libevent

2014-09-26 Thread Alexander Bluhm
On Fri, Aug 29, 2014 at 11:25:52PM +0200, Alexander Bluhm wrote:
> With this diff all my regression tests for syslogd pass.  I will
> try to pull parts of the diff into separate changes to make review
> easier.  I have not tested the syslogc feature yet.  So I will write
> more tests before committing this.

The tests for syslog control sockets are commited.  Next step to
libevent in syslogd is to cleanup the control connection code.
- Name variable path_ctlsock consistently.
- Name function ctlconn_logto() consistently.
- Replace the nested if/else logic in ctlconn_write_handler()
  with if/return.
- Call ctlconn_cleanup() only if there is a control connection.

ok?

bluhm

Index: usr.sbin/syslogd/privsep.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/privsep.c,v
retrieving revision 1.45
diff -u -p -u -p -r1.45 privsep.c
--- usr.sbin/syslogd/privsep.c  10 Sep 2014 13:16:20 -  1.45
+++ usr.sbin/syslogd/privsep.c  13 Sep 2014 23:48:26 -
@@ -374,8 +374,8 @@ priv_init(char *conf, int numeric, int l
for (i = 0; i < nunix; i++)
if (pfd[PFD_UNIX_0 + i].fd != -1)
(void)unlink(path_unix[i]);
-   if (ctlsock_path != NULL && pfd[PFD_CTLSOCK].fd != -1)
-   (void)unlink(ctlsock_path);
+   if (path_ctlsock != NULL && pfd[PFD_CTLSOCK].fd != -1)
+   (void)unlink(path_ctlsock);
 
if (restart) {
int r;
Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.124
diff -u -p -u -p -r1.124 syslogd.c
--- usr.sbin/syslogd/syslogd.c  10 Sep 2014 13:16:20 -  1.124
+++ usr.sbin/syslogd/syslogd.c  14 Sep 2014 00:12:24 -
@@ -199,7 +199,7 @@ int IPv4Only = 0;   /* when true, disable
 intIPv6Only = 0;   /* when true, disable IPv4 */
 intIncludeHostname = 0;/* include RFC 3164 style hostnames when 
forwarding */
 
-char   *ctlsock_path = NULL;   /* Path to control socket */
+char   *path_ctlsock = NULL;   /* Path to control socket */
 
 #define CTL_READING_CMD1
 #define CTL_WRITING_REPLY  2
@@ -284,7 +284,7 @@ voidctlsock_accept_handler(void);
 void   ctlconn_read_handler(void);
 void   ctlconn_write_handler(void);
 void   tailify_replytext(char *, int);
-void   logto_ctlconn(char *);
+void   ctlconn_logto(char *);
 
 int
 main(int argc, char *argv[])
@@ -335,7 +335,7 @@ main(int argc, char *argv[])
path_unix[nunix++] = optarg;
break;
case 's':
-   ctlsock_path = optarg;
+   path_ctlsock = optarg;
break;
default:
usage();
@@ -460,8 +460,8 @@ main(int argc, char *argv[])
pfd[PFD_SENDSYS].fd = fd;
pfd[PFD_SENDSYS].events = POLLIN;
 
-   if (ctlsock_path != NULL) {
-   fd = unix_socket(ctlsock_path, SOCK_STREAM, 0600);
+   if (path_ctlsock != NULL) {
+   fd = unix_socket(path_ctlsock, SOCK_STREAM, 0600);
if (fd != -1) {
if (listen(fd, 16) == -1) {
logerror("ctlsock listen");
@@ -1075,7 +1075,7 @@ fprintlog(struct filed *f, int flags, ch
if (ringbuf_append_line(f->f_un.f_mb.f_rb, line) == 1)
f->f_un.f_mb.f_overflow = 1;
if (f->f_un.f_mb.f_attached)
-   logto_ctlconn(line);
+   ctlconn_logto(line);
break;
}
f->f_prevcount = 0;
@@ -1893,8 +1893,8 @@ ctlconn_cleanup(void)
 {
struct filed *f;
 
-   if (pfd[PFD_CTLCONN].fd != -1)
-   close(pfd[PFD_CTLCONN].fd);
+   if (close(pfd[PFD_CTLCONN].fd) == -1)
+   logerror("close ctlconn");
 
pfd[PFD_CTLCONN].fd = -1;
pfd[PFD_CTLCONN].events = pfd[PFD_CTLCONN].revents = 0;
@@ -1923,7 +1923,8 @@ ctlsock_accept_handler(void)
return;
}
 
-   ctlconn_cleanup();
+   if (pfd[PFD_CTLCONN].fd != -1)
+   ctlconn_cleanup();
 
/* Only one connection at a time */
pfd[PFD_CTLSOCK].events = pfd[PFD_CTLSOCK].revents = 0;
@@ -1984,7 +1985,6 @@ ctlconn_read_handler(void)
default:
ctl_cmd_bytes += n;
}
-
if (ctl_cmd_bytes < sizeof(ctl_cmd))
return;
 
@@ -2086,7 +2086,6 @@ ctlconn_read_handler(void)
/* another syslogc can kick us out */
if (ctl_state == CTL_WRITING_CONT_REPLY)
pfd[PFD_CTLSOCK].events = POLLIN;
-
 }
 
 void
@@ -2101,6 +2100,7 @@ ctlconn_write_handler(void)
ctlconn_cleanup();
return;
}
+
  retry:
n = write(pfd[PFD_CTLCONN].fd, ctl_reply + ctl_reply_offs

Re: syslogd libevent handler

2014-09-04 Thread Alexander Bluhm
On Wed, Sep 03, 2014 at 04:34:47PM -0700, Doug Hogan wrote:
> On Sun, Aug 31, 2014 at 10:46:50PM +0200, Alexander Bluhm wrote:
> > Move the handlers for the poll events into separate functions.  They
> > will become the libevent callbacks later.
> ...
> 
> > +   udp_read_handler(pfd[PFD_UNIX_0 + i].fd);
> ...
> 
> Shouldn't this be a call to unix_read_handler() instead of
> udp_read_handler()?

Yes, of course.  This bug can be seen in the test output:
Sep 04 13:18:17 ??? syslogd-regress[21485]: syslogd regress test log message
Sep 04 13:21:35 t430s syslogd-regress[23917]: syslogd regress test log message
I have added a check to regress.

Thanks for finding this, updated diff below.

Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.121
diff -u -p -r1.121 syslogd.c
--- usr.sbin/syslogd/syslogd.c  31 Aug 2014 22:11:43 -  1.121
+++ usr.sbin/syslogd/syslogd.c  4 Sep 2014 11:19:05 -
@@ -245,6 +245,13 @@ char   *reply_text;/* Start of reply tex
 size_t ctl_reply_size = 0; /* Number of bytes used in reply */
 size_t ctl_reply_offset = 0;   /* Number of bytes of reply written so far */
 
+char   *linebuf;
+int linesize;
+
+voidklog_read_handler(int);
+voidudp_read_handler(int);
+voidunix_read_handler(int);
+
 struct pollfd pfd[N_PFD];
 
 volatile sig_atomic_t MarkSet;
@@ -282,12 +289,8 @@ void   logto_ctlconn(char *);
 int
 main(int argc, char *argv[])
 {
-   int ch, i, linesize, fd;
-   struct sockaddr_un fromunix;
-   struct sockaddr_storage from;
-   socklen_t len;
-   char *p, *line;
-   char resolve[MAXHOSTNAMELEN];
+   int ch, i, fd;
+   char *p;
int lockpipe[2] = { -1, -1}, pair[2], nullfd;
struct addrinfo hints, *res, *res0;
FILE *fp;
@@ -367,7 +370,7 @@ main(int argc, char *argv[])
if (linesize < MAXLINE)
linesize = MAXLINE;
linesize++;
-   if ((line = malloc(linesize)) == NULL) {
+   if ((linebuf = malloc(linesize)) == NULL) {
logerror("Couldn't allocate line buffer");
die(0);
}
@@ -585,41 +588,13 @@ main(int argc, char *argv[])
}
 
if ((pfd[PFD_KLOG].revents & POLLIN) != 0) {
-   i = read(pfd[PFD_KLOG].fd, line, linesize - 1);
-   if (i > 0) {
-   line[i] = '\0';
-   printsys(line);
-   } else if (i < 0 && errno != EINTR) {
-   logerror("klog");
-   pfd[PFD_KLOG].fd = -1;
-   pfd[PFD_KLOG].events = 0;
-   }
+   klog_read_handler(pfd[PFD_KLOG].fd);
}
if ((pfd[PFD_INET].revents & POLLIN) != 0) {
-   len = sizeof(from);
-   i = recvfrom(pfd[PFD_INET].fd, line, MAXLINE, 0,
-   (struct sockaddr *)&from, &len);
-   if (i > 0) {
-   line[i] = '\0';
-   cvthname((struct sockaddr *)&from, resolve,
-   sizeof(resolve));
-   dprintf("cvthname res: %s\n", resolve);
-   printline(resolve, line);
-   } else if (i < 0 && errno != EINTR)
-   logerror("recvfrom inet");
+   udp_read_handler(pfd[PFD_INET].fd);
}
if ((pfd[PFD_INET6].revents & POLLIN) != 0) {
-   len = sizeof(from);
-   i = recvfrom(pfd[PFD_INET6].fd, line, MAXLINE, 0,
-   (struct sockaddr *)&from, &len);
-   if (i > 0) {
-   line[i] = '\0';
-   cvthname((struct sockaddr *)&from, resolve,
-   sizeof(resolve));
-   dprintf("cvthname res: %s\n", resolve);
-   printline(resolve, line);
-   } else if (i < 0 && errno != EINTR)
-   logerror("recvfrom inet6");
+   udp_read_handler(pfd[PFD_INET6].fd);
}
if ((pfd[PFD_CTLSOCK].revents & POLLIN) != 0)
ctlsock_accept_handler();
@@ -630,22 +605,64 @@ main(int argc, char *argv[])
 
for (i = 0; i < nfunix; i++) {
if ((pfd[PFD_UNIX_0 + i].revents & POLLIN) != 0) {
-   ssize_t rlen;
-
-   len = sizeof(fromunix);
-   rlen = recvfrom(pfd[PFD_UNIX_0 + i].fd, line,
-

Re: syslogd libevent handler

2014-09-03 Thread Doug Hogan
On Sun, Aug 31, 2014 at 10:46:50PM +0200, Alexander Bluhm wrote:
> Move the handlers for the poll events into separate functions.  They
> will become the libevent callbacks later.
...

> @@ -631,23 +606,65 @@ main(int argc, char *argv[])
>  
>   for (i = 0; i < nfunix; i++) {
>   if ((pfd[PFD_UNIX_0 + i].revents & POLLIN) != 0) {
> - ssize_t rlen;
> -
> - len = sizeof(fromunix);
> - rlen = recvfrom(pfd[PFD_UNIX_0 + i].fd, line,
> - MAXLINE, 0, (struct sockaddr *)&fromunix,
> - &len);
> - if (rlen > 0) {
> - line[rlen] = '\0';
> - printline(LocalHostName, line);
> - } else if (rlen == -1 && errno != EINTR)
> - logerror("recvfrom unix");
> + udp_read_handler(pfd[PFD_UNIX_0 + i].fd);
...

Shouldn't this be a call to unix_read_handler() instead of
udp_read_handler()?



Re: syslogd libevent handler

2014-09-03 Thread Alexander Bluhm
On Sun, Aug 31, 2014 at 10:46:50PM +0200, Alexander Bluhm wrote:
> On Fri, Aug 29, 2014 at 11:25:52PM +0200, Alexander Bluhm wrote:
> > I will try to pull parts of the diff into separate changes to
> > make review easier.
> 
> Move the handlers for the poll events into separate functions.  They
> will become the libevent callbacks later.
> 
> ok?

anyone?

> bluhm
> 
> Index: usr.sbin/syslogd/syslogd.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
> retrieving revision 1.119
> diff -u -p -r1.119 syslogd.c
> --- usr.sbin/syslogd/syslogd.c25 Aug 2014 18:19:18 -  1.119
> +++ usr.sbin/syslogd/syslogd.c31 Aug 2014 20:34:01 -
> @@ -245,6 +245,13 @@ char *reply_text;/* Start of reply tex
>  size_t   ctl_reply_size = 0; /* Number of bytes used in reply */
>  size_t   ctl_reply_offset = 0;   /* Number of bytes of reply written so 
> far */
>  
> +char *linebuf;
> +int   linesize;
> +
> +void  klog_read_handler(int);
> +void  udp_read_handler(int);
> +void  unix_read_handler(int);
> +
>  struct pollfd pfd[N_PFD];
>  
>  volatile sig_atomic_t MarkSet;
> @@ -283,12 +290,8 @@ void logto_ctlconn(char *);
>  int
>  main(int argc, char *argv[])
>  {
> - int ch, i, linesize, fd;
> - struct sockaddr_un fromunix;
> - struct sockaddr_storage from;
> - socklen_t len;
> - char *p, *line;
> - char resolve[MAXHOSTNAMELEN];
> + int ch, i, fd;
> + char *p;
>   int lockpipe[2] = { -1, -1}, pair[2], nullfd;
>   struct addrinfo hints, *res, *res0;
>   FILE *fp;
> @@ -368,7 +371,7 @@ main(int argc, char *argv[])
>   if (linesize < MAXLINE)
>   linesize = MAXLINE;
>   linesize++;
> - if ((line = malloc(linesize)) == NULL) {
> + if ((linebuf = malloc(linesize)) == NULL) {
>   logerror("Couldn't allocate line buffer");
>   die(0);
>   }
> @@ -586,41 +589,13 @@ main(int argc, char *argv[])
>   }
>  
>   if ((pfd[PFD_KLOG].revents & POLLIN) != 0) {
> - i = read(pfd[PFD_KLOG].fd, line, linesize - 1);
> - if (i > 0) {
> - line[i] = '\0';
> - printsys(line);
> - } else if (i < 0 && errno != EINTR) {
> - logerror("klog");
> - pfd[PFD_KLOG].fd = -1;
> - pfd[PFD_KLOG].events = 0;
> - }
> + klog_read_handler(pfd[PFD_KLOG].fd);
>   }
>   if ((pfd[PFD_INET].revents & POLLIN) != 0) {
> - len = sizeof(from);
> - i = recvfrom(pfd[PFD_INET].fd, line, MAXLINE, 0,
> - (struct sockaddr *)&from, &len);
> - if (i > 0) {
> - line[i] = '\0';
> - cvthname((struct sockaddr *)&from, resolve,
> - sizeof(resolve));
> - dprintf("cvthname res: %s\n", resolve);
> - printline(resolve, line);
> - } else if (i < 0 && errno != EINTR)
> - logerror("recvfrom inet");
> + udp_read_handler(pfd[PFD_INET].fd);
>   }
>   if ((pfd[PFD_INET6].revents & POLLIN) != 0) {
> - len = sizeof(from);
> - i = recvfrom(pfd[PFD_INET6].fd, line, MAXLINE, 0,
> - (struct sockaddr *)&from, &len);
> - if (i > 0) {
> - line[i] = '\0';
> - cvthname((struct sockaddr *)&from, resolve,
> - sizeof(resolve));
> - dprintf("cvthname res: %s\n", resolve);
> - printline(resolve, line);
> - } else if (i < 0 && errno != EINTR)
> - logerror("recvfrom inet6");
> + udp_read_handler(pfd[PFD_INET6].fd);
>   }
>   if ((pfd[PFD_CTLSOCK].revents & POLLIN) != 0)
>   ctlsock_accept_handler();
> @@ -631,23 +606,65 @@ main(int argc, char *argv[])
>  
>   for (i = 0; i < nfunix; i++) {
>   if ((pfd[PFD_UNIX_0 + i].revents & POLLIN) != 0) {
> - ssize_t rlen;
> -
> - len = sizeof(fromunix);
> - rlen = recvfrom(pfd[PFD_UNIX_0 + i].fd, line,
> - MAXLINE, 0, (struct sockaddr *)&fromunix,
> - &len);
> - if (rlen > 0) {
> - line[rlen] = '\0';
> - printline(LocalHostName, line);

Re: syslogd libevent

2014-09-03 Thread Alexander Bluhm
On Fri, Aug 29, 2014 at 11:25:52PM +0200, Alexander Bluhm wrote:
> So I will write more tests before committing this.

My regression tests found a bug in syslogd.  When adding the maximum
number of paths with the -a option, the arrays for unix domain
socket paths and the poll file descriptors overflow by one.

- increase pfd array by one
- operate on size of arrays not length
- null check for path not necessary when doing fd -1 check
- rename variables consistently ...unix
- make number of unix fds a local variable

ok?

bluhm

Index: usr.sbin/syslogd/privsep.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/privsep.c,v
retrieving revision 1.43
diff -u -p -r1.43 privsep.c
--- usr.sbin/syslogd/privsep.c  25 Aug 2014 20:19:14 -  1.43
+++ usr.sbin/syslogd/privsep.c  3 Sep 2014 16:08:03 -
@@ -172,7 +172,7 @@ priv_init(char *conf, int numeric, int l
close(socks[1]);
 
/* Close descriptors that only the unpriv child needs */
-   for (i = 0; i < nfunix; i++)
+   for (i = 0; i < MAXUNIX + 1; i++)
if (pfd[PFD_UNIX_0 + i].fd != -1)
close(pfd[PFD_UNIX_0 + i].fd);
if (pfd[PFD_INET].fd != -1)
@@ -369,9 +369,9 @@ priv_init(char *conf, int numeric, int l
close(socks[0]);
 
/* Unlink any domain sockets that have been opened */
-   for (i = 0; i < nfunix; i++)
-   if (funixn[i] != NULL && pfd[PFD_UNIX_0 + i].fd != -1)
-   (void)unlink(funixn[i]);
+   for (i = 0; i < MAXUNIX; i++)
+   if (pfd[PFD_UNIX_0 + i].fd != -1)
+   (void)unlink(path_unix[i]);
if (ctlsock_path != NULL && pfd[PFD_CTLSOCK].fd != -1)
(void)unlink(ctlsock_path);
 
Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.121
diff -u -p -r1.121 syslogd.c
--- usr.sbin/syslogd/syslogd.c  31 Aug 2014 22:11:43 -  1.121
+++ usr.sbin/syslogd/syslogd.c  3 Sep 2014 16:40:54 -
@@ -183,8 +183,7 @@ char*TypeNames[9] = {
 struct filed *Files;
 struct filed consfile;
 
-intnfunix = 1; /* Number of Unix domain sockets requested */
-char   *funixn[MAXFUNIX] = { _PATH_LOG }; /* Paths to Unix domain sockets */
+char   *path_unix[MAXUNIX] = { _PATH_LOG }; /* Paths to Unix domain sockets */
 intDebug;  /* debug flag */
 intStartup = 1;/* startup flag */
 char   LocalHostName[MAXHOSTNAMELEN];  /* our hostname */
@@ -282,7 +281,7 @@ voidlogto_ctlconn(char *);
 int
 main(int argc, char *argv[])
 {
-   int ch, i, linesize, fd;
+   int ch, i, linesize, fd, nunix = 1;
struct sockaddr_un fromunix;
struct sockaddr_storage from;
socklen_t len;
@@ -292,6 +291,9 @@ main(int argc, char *argv[])
struct addrinfo hints, *res, *res0;
FILE *fp;
 
+   for (i = 0; i < N_PFD; i++)
+   pfd[i].fd = -1;
+
while ((ch = getopt(argc, argv, "46dhnuf:m:p:a:s:")) != -1)
switch (ch) {
case '4':   /* disable IPv6 */
@@ -318,18 +320,18 @@ main(int argc, char *argv[])
NoDNS = 1;
break;
case 'p':   /* path */
-   funixn[0] = optarg;
+   path_unix[0] = optarg;
break;
case 'u':   /* allow udp input port */
SecureMode = 0;
break;
case 'a':
-   if (nfunix >= MAXFUNIX)
+   if (nunix >= MAXUNIX)
fprintf(stderr, "syslogd: "
"out of descriptors, ignoring %s\n",
optarg);
else
-   funixn[nfunix++] = optarg;
+   path_unix[nunix++] = optarg;
break;
case 's':
ctlsock_path = optarg;
@@ -439,8 +441,8 @@ main(int argc, char *argv[])
 #ifndef SUN_LEN
 #define SUN_LEN(unp) (strlen((unp)->sun_path) + 2)
 #endif
-   for (i = 0; i < nfunix; i++) {
-   if ((fd = unix_socket(funixn[i], SOCK_DGRAM, 0666)) == -1) {
+   for (i = 0; i < nunix; i++) {
+   if ((fd = unix_socket(path_unix[i], SOCK_DGRAM, 0666)) == -1) {
if (i == 0 && !Debug)
die(0);
continue;
@@ -450,7 +452,7 @@ main(int argc, char *argv[])
pfd[PFD_UNIX_0 + i].events = POLLIN;
}
 
-   nfunix++;
+   nunix++;
if (socketpair(AF_UNIX, SOCK_DGRAM, PF_UNSPEC, pair) == -1)
die(0);
fd = pair[0];
@@ -575,7 

Re: syslogd libevent

2014-08-31 Thread Alexander Bluhm
On Fri, Aug 29, 2014 at 11:25:52PM +0200, Alexander Bluhm wrote:
> I will try to pull parts of the diff into separate changes to
> make review easier.

The reapchild() signal handler collects all children.  This can be
done easier by ignoring SIGCHLD.

ok?

bluhm

Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.120
diff -u -p -r1.120 syslogd.c
--- usr.sbin/syslogd/syslogd.c  31 Aug 2014 20:51:31 -  1.120
+++ usr.sbin/syslogd/syslogd.c  31 Aug 2014 21:00:04 -
@@ -266,7 +266,6 @@ voidlogmsg(int, char *, char *, int);
 struct filed *find_dup(struct filed *);
 void   printline(char *, char *);
 void   printsys(char *);
-void   reapchild(int);
 char   *ttymsg(struct iovec *, int, char *, int);
 void   usage(void);
 void   wallmsg(struct filed *, struct iovec *);
@@ -553,7 +552,7 @@ main(int argc, char *argv[])
(void)signal(SIGTERM, dodie);
(void)signal(SIGINT, Debug ? dodie : SIG_IGN);
(void)signal(SIGQUIT, Debug ? dodie : SIG_IGN);
-   (void)signal(SIGCHLD, reapchild);
+   (void)signal(SIGCHLD, SIG_IGN);
(void)signal(SIGALRM, domark);
(void)signal(SIGPIPE, SIG_IGN);
(void)alarm(TIMERINTVL);
@@ -1117,18 +1116,6 @@ wallmsg(struct filed *f, struct iovec *i
}
(void)fclose(uf);
reenter = 0;
-}
-
-/* ARGSUSED */
-void
-reapchild(int signo)
-{
-   int save_errno = errno;
-   int status;
-
-   while (waitpid(-1, &status, WNOHANG) > 0)
-   ;
-   errno = save_errno;
 }
 
 /*



Re: syslogd libevent handler

2014-08-31 Thread Alexander Bluhm
On Fri, Aug 29, 2014 at 11:25:52PM +0200, Alexander Bluhm wrote:
> I will try to pull parts of the diff into separate changes to
> make review easier.

Move the handlers for the poll events into separate functions.  They
will become the libevent callbacks later.

ok?

bluhm

Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.119
diff -u -p -r1.119 syslogd.c
--- usr.sbin/syslogd/syslogd.c  25 Aug 2014 18:19:18 -  1.119
+++ usr.sbin/syslogd/syslogd.c  31 Aug 2014 20:34:01 -
@@ -245,6 +245,13 @@ char   *reply_text;/* Start of reply tex
 size_t ctl_reply_size = 0; /* Number of bytes used in reply */
 size_t ctl_reply_offset = 0;   /* Number of bytes of reply written so far */
 
+char   *linebuf;
+int linesize;
+
+voidklog_read_handler(int);
+voidudp_read_handler(int);
+voidunix_read_handler(int);
+
 struct pollfd pfd[N_PFD];
 
 volatile sig_atomic_t MarkSet;
@@ -283,12 +290,8 @@ void   logto_ctlconn(char *);
 int
 main(int argc, char *argv[])
 {
-   int ch, i, linesize, fd;
-   struct sockaddr_un fromunix;
-   struct sockaddr_storage from;
-   socklen_t len;
-   char *p, *line;
-   char resolve[MAXHOSTNAMELEN];
+   int ch, i, fd;
+   char *p;
int lockpipe[2] = { -1, -1}, pair[2], nullfd;
struct addrinfo hints, *res, *res0;
FILE *fp;
@@ -368,7 +371,7 @@ main(int argc, char *argv[])
if (linesize < MAXLINE)
linesize = MAXLINE;
linesize++;
-   if ((line = malloc(linesize)) == NULL) {
+   if ((linebuf = malloc(linesize)) == NULL) {
logerror("Couldn't allocate line buffer");
die(0);
}
@@ -586,41 +589,13 @@ main(int argc, char *argv[])
}
 
if ((pfd[PFD_KLOG].revents & POLLIN) != 0) {
-   i = read(pfd[PFD_KLOG].fd, line, linesize - 1);
-   if (i > 0) {
-   line[i] = '\0';
-   printsys(line);
-   } else if (i < 0 && errno != EINTR) {
-   logerror("klog");
-   pfd[PFD_KLOG].fd = -1;
-   pfd[PFD_KLOG].events = 0;
-   }
+   klog_read_handler(pfd[PFD_KLOG].fd);
}
if ((pfd[PFD_INET].revents & POLLIN) != 0) {
-   len = sizeof(from);
-   i = recvfrom(pfd[PFD_INET].fd, line, MAXLINE, 0,
-   (struct sockaddr *)&from, &len);
-   if (i > 0) {
-   line[i] = '\0';
-   cvthname((struct sockaddr *)&from, resolve,
-   sizeof(resolve));
-   dprintf("cvthname res: %s\n", resolve);
-   printline(resolve, line);
-   } else if (i < 0 && errno != EINTR)
-   logerror("recvfrom inet");
+   udp_read_handler(pfd[PFD_INET].fd);
}
if ((pfd[PFD_INET6].revents & POLLIN) != 0) {
-   len = sizeof(from);
-   i = recvfrom(pfd[PFD_INET6].fd, line, MAXLINE, 0,
-   (struct sockaddr *)&from, &len);
-   if (i > 0) {
-   line[i] = '\0';
-   cvthname((struct sockaddr *)&from, resolve,
-   sizeof(resolve));
-   dprintf("cvthname res: %s\n", resolve);
-   printline(resolve, line);
-   } else if (i < 0 && errno != EINTR)
-   logerror("recvfrom inet6");
+   udp_read_handler(pfd[PFD_INET6].fd);
}
if ((pfd[PFD_CTLSOCK].revents & POLLIN) != 0)
ctlsock_accept_handler();
@@ -631,23 +606,65 @@ main(int argc, char *argv[])
 
for (i = 0; i < nfunix; i++) {
if ((pfd[PFD_UNIX_0 + i].revents & POLLIN) != 0) {
-   ssize_t rlen;
-
-   len = sizeof(fromunix);
-   rlen = recvfrom(pfd[PFD_UNIX_0 + i].fd, line,
-   MAXLINE, 0, (struct sockaddr *)&fromunix,
-   &len);
-   if (rlen > 0) {
-   line[rlen] = '\0';
-   printline(LocalHostName, line);
-   } else if (rlen == -1 && errno != EINTR)
-   logerror("recvfrom unix");
+   

Re: syslogd libevent

2014-08-31 Thread Alexander Bluhm
On Fri, Aug 29, 2014 at 11:25:52PM +0200, Alexander Bluhm wrote:
> I will try to pull parts of the diff into separate changes to make review
> easier.

Let's start with an obvious bug.  Do not call free() on an array
in the data section.  Fortunately the code was not reached.  No
binary change.

ok?

bluhm

Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.119
diff -u -p -r1.119 syslogd.c
--- usr.sbin/syslogd/syslogd.c  25 Aug 2014 18:19:18 -  1.119
+++ usr.sbin/syslogd/syslogd.c  31 Aug 2014 20:00:14 -
@@ -646,7 +646,6 @@ main(int argc, char *argv[])
}
}
/* NOTREACHED */
-   free(pfd);
return (0);
 }
 



syslogd libevent

2014-08-29 Thread Alexander Bluhm
Hi,

I am currently working on converting syslogd to libevent.  Theo
recommended to do that before adding tcp and tls support.

With this diff all my regression tests for syslogd pass.  I will
try to pull parts of the diff into separate changes to make review
easier.  I have not tested the syslogc feature yet.  So I will write
more tests before committing this.

bluhm

Index: usr.sbin/syslogd/Makefile
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/Makefile,v
retrieving revision 1.5
diff -u -p -r1.5 Makefile
--- usr.sbin/syslogd/Makefile   4 Jan 2004 08:28:49 -   1.5
+++ usr.sbin/syslogd/Makefile   29 Aug 2014 15:09:10 -
@@ -1,7 +1,8 @@
 #  $OpenBSD: Makefile,v 1.5 2004/01/04 08:28:49 djm Exp $
 
-PROG=  syslogd
-SRCS=  syslogd.c ttymsg.c privsep.c privsep_fdpass.c ringbuf.c
-MAN=   syslogd.8 syslog.conf.5
+PROG = syslogd
+SRCS = syslogd.c ttymsg.c privsep.c privsep_fdpass.c ringbuf.c
+MAN =  syslogd.8 syslog.conf.5
+LDFLAGS =  -levent
 
 .include 
Index: usr.sbin/syslogd/privsep.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/privsep.c,v
retrieving revision 1.43
diff -u -p -r1.43 privsep.c
--- usr.sbin/syslogd/privsep.c  25 Aug 2014 20:19:14 -  1.43
+++ usr.sbin/syslogd/privsep.c  29 Aug 2014 15:09:10 -
@@ -153,7 +153,6 @@ priv_init(char *conf, int numeric, int l
dup2(nullfd, STDOUT_FILENO);
dup2(nullfd, STDERR_FILENO);
}
-
if (nullfd > 2)
close(nullfd);
 
@@ -172,19 +171,21 @@ priv_init(char *conf, int numeric, int l
close(socks[1]);
 
/* Close descriptors that only the unpriv child needs */
-   for (i = 0; i < nfunix; i++)
-   if (pfd[PFD_UNIX_0 + i].fd != -1)
-   close(pfd[PFD_UNIX_0 + i].fd);
-   if (pfd[PFD_INET].fd != -1)
-   close(pfd[PFD_INET].fd);
-   if (pfd[PFD_INET6].fd != -1)
-   close(pfd[PFD_INET6].fd);
-   if (pfd[PFD_CTLSOCK].fd != -1)
-   close(pfd[PFD_CTLSOCK].fd);
-   if (pfd[PFD_CTLCONN].fd != -1)
-   close(pfd[PFD_CTLCONN].fd);
-   if (pfd[PFD_KLOG].fd)
-   close(pfd[PFD_KLOG].fd);
+   if (fd_ctlconn != -1)
+   close(fd_ctlconn);
+   if (fd_ctlsock != -1)
+   close(fd_ctlsock);
+   for (i = 0; i < MAXFUNIX; i++)
+   if (fd_funix[i] != -1)
+   close(fd_funix[i]);
+   if (fd_klog != -1)
+   close(fd_klog);
+   if (fd_pair != -1)
+   close(fd_pair);
+   if (fd_udp != -1)
+   close(fd_udp);
+   if (fd_udp6 != -1)
+   close(fd_udp6);
 
/* Save the config file specified by the child process */
if (strlcpy(config_file, conf, sizeof config_file) >= 
sizeof(config_file))
@@ -369,11 +370,11 @@ priv_init(char *conf, int numeric, int l
close(socks[0]);
 
/* Unlink any domain sockets that have been opened */
-   for (i = 0; i < nfunix; i++)
-   if (funixn[i] != NULL && pfd[PFD_UNIX_0 + i].fd != -1)
-   (void)unlink(funixn[i]);
-   if (ctlsock_path != NULL && pfd[PFD_CTLSOCK].fd != -1)
-   (void)unlink(ctlsock_path);
+   for (i = 0; i < MAXFUNIX; i++)
+   if (path_funix[i] != NULL && fd_funix[i] != -1)
+   unlink(path_funix[i]);
+   if (path_ctlsock != NULL && fd_ctlsock != -1)
+   unlink(path_ctlsock);
 
if (restart) {
int r;
Index: usr.sbin/syslogd/syslogd.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.119
diff -u -p -r1.119 syslogd.c
--- usr.sbin/syslogd/syslogd.c  25 Aug 2014 18:19:18 -  1.119
+++ usr.sbin/syslogd/syslogd.c  29 Aug 2014 17:34:52 -
@@ -65,7 +65,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -81,6 +80,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -183,8 +183,7 @@ char*TypeNames[9] = {
 struct filed *Files;
 struct filed consfile;
 
-intnfunix = 1; /* Number of Unix domain sockets requested */
-char   *funixn[MAXFUNIX] = { _PATH_LOG }; /* Paths to Unix domain sockets */
+char   *path_funix[MAXFUNIX] = { _PATH_LOG }; /* Path to Unix domain sockets */
 intDebug;  /* debug flag */
 intStartup = 1;/* startup flag */
 char   LocalHostName[MAXHOSTNAMELEN];  /* our hostname */
@@ -199,7 +198,7 @@ int IPv4Only = 0;   /* when true, disable
 intIPv6Only = 0;   /* when true, disable IPv4 */
 intIncludeHostname = 0;/* include RFC 3164 style hostnames when 
forwarding */
 
-char   *ctlsock_path = NULL;   /* Path to control