aboutsummaryrefslogtreecommitdiffstats
path: root/etc.c
diff options
context:
space:
mode:
authorFumitoshi UKAI <ukai@debian.or.jp>2002-09-24 17:35:52 +0000
committerFumitoshi UKAI <ukai@debian.or.jp>2002-09-24 17:35:52 +0000
commitf456ed308c2f41c671279c4574b1c5f922f6f8c8 (patch)
tree21b6da64fc1a7225ccd21fba29d1a1f0340b20b2 /etc.c
parent[w3m-dev 03319] mailto (diff)
downloadw3m-f456ed308c2f41c671279c4574b1c5f922f6f8c8.tar.gz
w3m-f456ed308c2f41c671279c4574b1c5f922f6f8c8.zip
[w3m-dev 03321] Bug#162104: file descriptors 1 and 2 are closed rather than reopened to /dev/null
* etc.c (mySystem): fd 0,1,2 redirect /dev/null, close all other fds From: Fumitoshi UKAI <ukai@debian.or.jp>
Diffstat (limited to 'etc.c')
-rw-r--r--etc.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/etc.c b/etc.c
index 08affeb..0879c4b 100644
--- a/etc.c
+++ b/etc.c
@@ -1,4 +1,4 @@
-/* $Id: etc.c,v 1.23 2002/09/24 16:35:02 ukai Exp $ */
+/* $Id: etc.c,v 1.24 2002/09/24 17:35:52 ukai Exp $ */
#include "fm.h"
#include <pwd.h>
#include "myctype.h"
@@ -1208,11 +1208,16 @@ mySystem(char *command, int background)
int pid;
flush_tty();
if ((pid = fork()) == 0) {
+ int fd, i;
reset_signals();
SETPGRP();
close_tty();
- fclose(stdout);
- fclose(stderr);
+ dup2(open("/dev/null", O_RDONLY), 0);
+ dup2(open("/dev/null", O_WRONLY), 1);
+ dup2(fd = open("/dev/null", O_WRONLY), 2);
+ /* close all other file descriptors (socket, ...) */
+ for (i = 3; i <= fd; i++)
+ close(i);
execl("/bin/sh", "sh", "-c", command, NULL);
exit(127);
}