Redirect stdout and stderr to /dev/null before launching a spawned process
This commit is contained in:
parent
114b641bdd
commit
d6b7a8c21e
1 changed files with 15 additions and 2 deletions
17
src/spawn.c
17
src/spawn.c
|
@ -25,6 +25,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "tvhead.h"
|
#include "tvhead.h"
|
||||||
#include "spawn.h"
|
#include "spawn.h"
|
||||||
|
@ -134,7 +135,7 @@ int
|
||||||
spawn_and_store_stdout(const char *prog, char *const argv[], char **outp)
|
spawn_and_store_stdout(const char *prog, char *const argv[], char **outp)
|
||||||
{
|
{
|
||||||
pid_t p;
|
pid_t p;
|
||||||
int fd[2], r, totalsize = 0;
|
int fd[2], r, totalsize = 0, f;
|
||||||
char *outbuf;
|
char *outbuf;
|
||||||
struct spawn_output_buf_queue bufs;
|
struct spawn_output_buf_queue bufs;
|
||||||
spawn_output_buf_t *b = NULL;
|
spawn_output_buf_t *b = NULL;
|
||||||
|
@ -168,10 +169,22 @@ spawn_and_store_stdout(const char *prog, char *const argv[], char **outp)
|
||||||
close(fd[0]);
|
close(fd[0]);
|
||||||
dup2(fd[1], 1);
|
dup2(fd[1], 1);
|
||||||
close(fd[1]);
|
close(fd[1]);
|
||||||
|
|
||||||
|
f = open("/dev/null", O_RDWR);
|
||||||
|
if(f == -1) {
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"spawn: pid %d cannot open /dev/null for redirect %s -- %s",
|
||||||
|
getpid(), prog, strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
dup2(f, 0);
|
||||||
|
dup2(f, 2);
|
||||||
|
close(f);
|
||||||
|
|
||||||
execve(prog, argv, environ);
|
execve(prog, argv, environ);
|
||||||
syslog(LOG_ERR, "spawn: pid %d cannot execute %s -- %s",
|
syslog(LOG_ERR, "spawn: pid %d cannot execute %s -- %s",
|
||||||
getpid(), prog, strerror(errno));
|
getpid(), prog, strerror(errno));
|
||||||
close(1);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue