mirror of
https://github.com/VDR4Arch/vdr.git
synced 2023-10-10 13:36:52 +02:00
Closing all open file descriptors when calling external programs
This commit is contained in:
parent
312764a7ab
commit
60ee85bf17
1
HISTORY
1
HISTORY
@ -821,3 +821,4 @@ Video Disk Recorder Revision History
|
||||
- Removed the "system time seen..." message.
|
||||
- Fixed a bug in the replay mode display when pressing the Green or Yellow
|
||||
button while in trick mode (thanks to Stefan Huelswitt)
|
||||
- Closing all open file descriptors when calling external programs.
|
||||
|
@ -4,7 +4,7 @@
|
||||
* See the main source file 'vdr.c' for copyright information and
|
||||
* how to reach the author.
|
||||
*
|
||||
* $Id: recording.c 1.41 2001/10/19 13:12:17 kls Exp $
|
||||
* $Id: recording.c 1.42 2001/10/20 10:28:28 kls Exp $
|
||||
*/
|
||||
|
||||
#include "recording.h"
|
||||
@ -575,7 +575,7 @@ void cRecordingUserCommand::InvokeCommand(const char *State, const char *Recordi
|
||||
char *cmd;
|
||||
asprintf(&cmd, "%s %s '%s'", command, State, RecordingFileName);
|
||||
isyslog(LOG_INFO, "executing '%s'", cmd);
|
||||
system(cmd);
|
||||
SystemExec(cmd);
|
||||
delete cmd;
|
||||
}
|
||||
}
|
||||
|
34
thread.c
34
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 1.13 2001/09/23 14:04:35 kls Exp $
|
||||
* $Id: thread.c 1.14 2001/10/20 10:26:35 kls Exp $
|
||||
*/
|
||||
|
||||
#include "thread.h"
|
||||
@ -342,3 +342,35 @@ int cPipe::Close(void)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// --- SystemExec ------------------------------------------------------------
|
||||
|
||||
int SystemExec(const char *Command)
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
if ((pid = fork()) < 0) { // fork failed
|
||||
LOG_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pid > 0) { // parent process
|
||||
int status;
|
||||
if (waitpid(pid, &status, 0) < 0) {
|
||||
LOG_ERROR;
|
||||
return -1;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
else { // child process
|
||||
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);
|
||||
_exit(-1);
|
||||
}
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
7
thread.h
7
thread.h
@ -4,7 +4,7 @@
|
||||
* See the main source file 'vdr.c' for copyright information and
|
||||
* how to reach the author.
|
||||
*
|
||||
* $Id: thread.h 1.9 2001/09/15 12:46:52 kls Exp $
|
||||
* $Id: thread.h 1.10 2001/10/20 10:25:19 kls Exp $
|
||||
*/
|
||||
|
||||
#ifndef __THREAD_H
|
||||
@ -104,4 +104,9 @@ public:
|
||||
int Close(void);
|
||||
};
|
||||
|
||||
// SystemExec() implements a 'system()' call that closes all unnecessary file
|
||||
// descriptors in the child process.
|
||||
|
||||
int SystemExec(const char *Command);
|
||||
|
||||
#endif //__THREAD_H
|
||||
|
4
vdr.c
4
vdr.c
@ -22,7 +22,7 @@
|
||||
*
|
||||
* The project's page is at http://www.cadsoft.de/people/kls/vdr
|
||||
*
|
||||
* $Id: vdr.c 1.84 2001/10/19 13:37:24 kls Exp $
|
||||
* $Id: vdr.c 1.85 2001/10/20 10:26:54 kls Exp $
|
||||
*/
|
||||
|
||||
#include <getopt.h>
|
||||
@ -509,7 +509,7 @@ int main(int argc, char *argv[])
|
||||
char *cmd;
|
||||
asprintf(&cmd, "%s %ld %ld %d '%s'", Shutdown, Next, Delta, Channel, File);
|
||||
isyslog(LOG_INFO, "executing '%s'", cmd);
|
||||
system(cmd);
|
||||
SystemExec(cmd);
|
||||
delete cmd;
|
||||
}
|
||||
else if (WatchdogTimeout > 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user