From 655682b5d2c0889188fe4ead06506d8fe171b313 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Thu, 18 Jan 2024 13:01:07 +0100 Subject: [PATCH] Removed syslog calls in child process after fork() --- CONTRIBUTORS | 1 + HISTORY | 1 + thread.c | 22 +++++++++------------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index b4b26618..0526c587 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -2559,6 +2559,7 @@ Markus Ehrnsperger for fixing a possible crash in cDevice::StopSectionHandler() for making using a dummy OSD if no OSD provider is available not be considered an error any more + for removing syslog calls in child process after fork() Werner Färber for reporting a bug in handling the cPluginManager::Active() result when pressing diff --git a/HISTORY b/HISTORY index 381055d3..55bf505f 100644 --- a/HISTORY +++ b/HISTORY @@ -9872,3 +9872,4 @@ Video Disk Recorder Revision History - Using a dummy OSD if no OSD provider is available is not considered an error any more (thanks to Markus Ehrnsperger). - Implemented scaling images (thanks to Andreas Baierl). +- Removed syslog calls in child process after fork() (thanks to Markus Ehrnsperger). diff --git a/thread.c b/thread.c index 93eb8c0d..98f23cdf 100644 --- a/thread.c +++ b/thread.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: thread.c 5.1 2022/11/13 15:25:52 kls Exp $ + * $Id: thread.c 5.2 2024/01/18 13:01:07 kls Exp $ */ #include "thread.h" @@ -949,11 +949,11 @@ bool cPipe::Open(const char *Command, const char *Mode) int fd[2]; if (pipe(fd) < 0) { - LOG_ERROR; + LOG_ERROR_STR(Command); return false; } if ((pid = fork()) < 0) { // fork failed - LOG_ERROR; + LOG_ERROR_STR(Command); close(fd[0]); close(fd[1]); return false; @@ -969,7 +969,7 @@ bool cPipe::Open(const char *Command, const char *Mode) } close(fd[iopipe]); if ((f = fdopen(fd[1 - iopipe], mode)) == NULL) { - LOG_ERROR; + LOG_ERROR_STR(Command); close(fd[1 - iopipe]); } return f != NULL; @@ -982,7 +982,6 @@ bool cPipe::Open(const char *Command, const char *Mode) } close(fd[iopipe]); if (dup2(fd[1 - iopipe], iofd) == -1) { // now redirect - LOG_ERROR; close(fd[1 - iopipe]); _exit(-1); } @@ -991,7 +990,6 @@ bool cPipe::Open(const char *Command, const char *Mode) for (int i = STDERR_FILENO + 1; i < MaxPossibleFileDescriptors; i++) close(i); //close all dup'ed filedescriptors if (execl("/bin/sh", "sh", "-c", Command, NULL) == -1) { - LOG_ERROR_STR(Command); close(fd[1 - iopipe]); _exit(-1); } @@ -1044,14 +1042,14 @@ int SystemExec(const char *Command, bool Detached) pid_t pid; if ((pid = fork()) < 0) { // fork failed - LOG_ERROR; + LOG_ERROR_STR(Command); return -1; } if (pid > 0) { // parent process int status = 0; if (waitpid(pid, &status, 0) < 0) { - LOG_ERROR; + LOG_ERROR_STR(Command); return -1; } return status; @@ -1064,19 +1062,17 @@ int SystemExec(const char *Command, bool Detached) // Start a new session pid_t sid = setsid(); if (sid < 0) - LOG_ERROR; + _exit(-1); // close STDIN and re-open as /dev/null int devnull = open("/dev/null", O_RDONLY); if (devnull < 0 || dup2(devnull, 0) < 0) - LOG_ERROR; + _exit(-1); } int MaxPossibleFileDescriptors = getdtablesize(); for (int i = STDERR_FILENO + 1; i < MaxPossibleFileDescriptors; i++) close(i); //close all dup'ed filedescriptors - if (execl("/bin/sh", "sh", "-c", Command, NULL) == -1) { - LOG_ERROR_STR(Command); + if (execl("/bin/sh", "sh", "-c", Command, NULL) == -1) _exit(-1); - } _exit(0); } }