From 341832d7556706c476d77d11631294a2621e97bd Mon Sep 17 00:00:00 2001 From: Robert Swiecki Date: Sat, 11 Feb 2017 20:33:54 +0100 Subject: [PATCH] Duplicate logging fd, so it can be used from child process --- contain.c | 8 +++++--- log.c | 2 +- subproc.c | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/contain.c b/contain.c index 4d3d377..8b55aee 100644 --- 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 872459c..770586b 100644 --- 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) { diff --git a/subproc.c b/subproc.c index b2f350d..df7b82d 100644 --- 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)