Hi,

I would like to remove the artificial maximum number of unix domain
sockets in syslogd(8).  Just malloc(3) them dynamically which also
gives a more random address space layout.

ok?

bluhm

Index: usr.sbin/syslogd/syslogd.8
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.8,v
retrieving revision 1.51
diff -u -p -r1.51 syslogd.8
--- usr.sbin/syslogd/syslogd.8  4 Oct 2016 22:09:21 -0000       1.51
+++ usr.sbin/syslogd/syslogd.8  17 Oct 2016 00:06:57 -0000
@@ -75,7 +75,6 @@ to use only IPv6 addresses for UDP.
 Specify a location where
 .Nm
 should place an additional log socket.
-Up to 20 additional logging sockets can be specified.
 The primary use for this is to place additional log sockets in
 .Pa /dev/log
 of various chroot filespaces, though the need for these is
Index: usr.sbin/syslogd/syslogd.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.220
diff -u -p -r1.220 syslogd.c
--- usr.sbin/syslogd/syslogd.c  16 Oct 2016 22:12:50 -0000      1.220
+++ usr.sbin/syslogd/syslogd.c  17 Oct 2016 00:28:11 -0000
@@ -197,8 +197,8 @@ char        *TypeNames[] = {
 SIMPLEQ_HEAD(filed_list, filed) Files;
 struct filed consfile;
 
-int    nunix = 1;              /* Number of Unix domain sockets requested */
-char   *path_unix[MAXUNIX] = { _PATH_LOG }; /* Paths to Unix domain sockets */
+int    nunix;                  /* Number of Unix domain sockets requested */
+char   **path_unix;            /* Paths to Unix domain sockets */
 int    Debug;                  /* debug flag */
 int    Foreground;             /* run in foreground, instead of daemonizing */
 int    Startup = 1;            /* startup flag */
@@ -359,7 +359,12 @@ main(int argc, char *argv[])
        int              ch, i;
        int              lockpipe[2] = { -1, -1}, pair[2], nullfd, fd;
        int              fd_ctlsock, fd_klog, fd_sendsys, fd_bind, fd_listen;
-       int              fd_unix[MAXUNIX];
+       int             *fd_unix;
+
+       if ((path_unix = malloc(sizeof(*path_unix))) == NULL)
+               err(1, "malloc %s", _PATH_LOG);
+       path_unix[0] = _PATH_LOG;
+       nunix = 1;
 
        while ((ch = getopt(argc, argv, "46a:C:c:dFf:hK:k:m:nP:p:S:s:T:U:uVZ"))
            != -1)
@@ -371,8 +376,9 @@ main(int argc, char *argv[])
                        Family = PF_INET6;
                        break;
                case 'a':
-                       if (nunix >= MAXUNIX)
-                               errx(1, "out of descriptors: %s", optarg);
+                       if ((path_unix = reallocarray(path_unix, nunix + 1,
+                           sizeof(*path_unix))) == NULL)
+                               err(1, "malloc %s", optarg);
                        path_unix[nunix++] = optarg;
                        break;
                case 'C':               /* file containing CA certificates */
@@ -520,6 +526,8 @@ main(int argc, char *argv[])
                        die(0);
        }
 
+       if ((fd_unix = reallocarray(NULL, nunix, sizeof(*fd_unix))) == NULL)
+               err(1, "malloc unix");
        for (i = 0; i < nunix; i++) {
                fd_unix[i] = unix_socket(path_unix[i], SOCK_DGRAM, 0666);
                if (fd_unix[i] == -1) {
Index: usr.sbin/syslogd/syslogd.h
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.h,v
retrieving revision 1.25
diff -u -p -r1.25 syslogd.h
--- usr.sbin/syslogd/syslogd.h  16 Oct 2016 22:00:14 -0000      1.25
+++ usr.sbin/syslogd/syslogd.h  16 Oct 2016 22:44:41 -0000
@@ -42,9 +42,8 @@ void send_fd(int, int);
 int  receive_fd(int);
 
 /* The list of domain sockets */
-#define MAXUNIX        21
 extern int nunix;
-extern char *path_unix[MAXUNIX];
+extern char **path_unix;
 extern char *path_ctlsock;
 
 #define MAXLINE                8192            /* maximum line length */

Reply via email to