Duplicate logging fd, so it can be used from child process

This commit is contained in:
Robert Swiecki 2017-02-11 20:33:54 +01:00
parent a1c0cbacbd
commit 341832d755
3 changed files with 10 additions and 6 deletions

View File

@ -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) {

2
log.c
View File

@ -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) {

View File

@ -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)