[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>
This commit is contained in:
Fumitoshi UKAI
2002-09-24 17:35:52 +00:00
parent 29e57b1c5c
commit f456ed308c
2 changed files with 14 additions and 4 deletions

View File

@@ -1,3 +1,8 @@
2002-09-25 Fumitoshi UKAI <ukai@debian.or.jp>
* [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
2002-09-25 AIDA Shinra <aida-s@jcom.home.ne.jp>
* [w3m-dev 03319] mailto
@@ -3822,4 +3827,4 @@
* release-0-2-1
* import w3m-0.2.1
$Id: ChangeLog,v 1.429 2002/09/24 17:06:04 ukai Exp $
$Id: ChangeLog,v 1.430 2002/09/24 17:35:52 ukai Exp $

11
etc.c
View File

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