Duplicate logging fd, so it can be used from child process
authorRobert Swiecki <robert@swiecki.net>
Sat, 11 Feb 2017 19:33:54 +0000 (20:33 +0100)
committerRobert Swiecki <robert@swiecki.net>
Sat, 11 Feb 2017 19:33:54 +0000 (20:33 +0100)
contain.c
log.c
subproc.c

index 4d3d377d5aec2321b5d0c55734f4892d2b846101..8b55aeebc72be18b4367f28bb5c48b34b7fb7362 100644 (file)
--- a/contain.c
+++ b/contain.c
@@ -222,9 +222,11 @@ static bool containPassFd(struct nsjconf_t *nsjconf, int fd)
 
 static bool containMakeFdsCOENaive(struct nsjconf_t *nsjconf)
 {
-       // Don't use getrlimit(RLIMIT_NOFILE) here, as it can return an artifically small value
-       // (e.g. 32), which could be smaller than a maximum assigned number to file-descriptors
-       // in this process. Just use some reasonably sane value (e.g. 1024)
+       /*
+        * Don't use getrlimit(RLIMIT_NOFILE) here, as it can return an artifically small value
+        * (e.g. 32), which could be smaller than a maximum assigned number to file-descriptors
+        * in this process. Just use some reasonably sane value (e.g. 1024)
+        */
        for (unsigned fd = 0; fd < 1024; fd++) {
                int flags = TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD, 0));
                if (flags == -1) {
diff --git a/log.c b/log.c
index 872459c5b3230608ef0d77b866710e340a24e641..770586b8b8117c1bf23716d177c22cb22de7aad1 100644 (file)
--- a/log.c
+++ b/log.c
@@ -52,7 +52,7 @@ bool logInitLogFile(struct nsjconf_t *nsjconf, const char *logfile, bool is_verb
                logfile = _LOG_DEFAULT_FILE;
        }
        if (logfile == NULL) {
-               log_fd = STDERR_FILENO;
+               log_fd = fcntl(log_fd, F_DUPFD_CLOEXEC);
        } else {
                if (TEMP_FAILURE_RETRY(log_fd = open(logfile, O_CREAT | O_RDWR | O_APPEND, 0640)) ==
                    -1) {
index b2f350dc0872200587a2dd3698912dbdecedf659..df7b82d4ee522de3905924665661a224a219c11d 100644 (file)
--- a/subproc.c
+++ b/subproc.c
@@ -87,7 +87,10 @@ static int subprocNewProc(struct nsjconf_t *nsjconf, int fd_in, int fd_out, int
                putenv(p->val);
        }
 
-       LOG_D("Trying to execve('%s')", nsjconf->argv[0]);
+       char cs_addr[64];
+       netConnToText(fd_in, true /* remote */ , cs_addr, sizeof(cs_addr), NULL);
+       LOG_I("Executing '%s' for '%s'", nsjconf->argv[0], cs_addr);
+
        for (size_t i = 0; nsjconf->argv[i]; i++) {
                LOG_D(" Arg[%zu]: '%s'", i, nsjconf->argv[i]);
        }
@@ -393,7 +396,6 @@ void subprocRunChild(struct nsjconf_t *nsjconf, int fd_in, int fd_out, int fd_er
        close(parent_fd);
        char cs_addr[64];
        netConnToText(fd_in, true /* remote */ , cs_addr, sizeof(cs_addr), NULL);
-       LOG_I("PID: %d about to execute '%s' for %s", pid, nsjconf->argv[0], cs_addr);
 }
 
 int subprocSystem(const char **argv, char **env)