diff options
author | Fumitoshi UKAI <ukai@debian.or.jp> | 2002-11-24 16:02:22 +0000 |
---|---|---|
committer | Fumitoshi UKAI <ukai@debian.or.jp> | 2002-11-24 16:02:22 +0000 |
commit | 5a539bf5e762a56fe8fae347f7fcee531fbbb399 (patch) | |
tree | 9d9157716e943261c150b6e60c08b19219d3548d /etc.c | |
parent | [w3m-dev 03466] Re: background download when external viewer (diff) | |
download | w3m-5a539bf5e762a56fe8fae347f7fcee531fbbb399.tar.gz w3m-5a539bf5e762a56fe8fae347f7fcee531fbbb399.zip |
[w3m-dev 03471] Re: SETPGRP()
* configure: SETPGRP() always defined
* proto.h (close_all_fds): added
(myExec): #ifdef HAVE_SETPGRP
* etc.c (close_all_fds): added
(myExec): #ifdef HAVE_SETPGRP
(mySystem): #ifndef -> #ifdef
* file.c (_doFileCopy): delete #ifdef HAVE_SETPGRP
(doFileSave): ditto
* image.c (openImgdisplay): delete #ifdef HAVE_SETPGRP
use close_all_fds()
* search.c (open_migemo): ditto
From: Fumitoshi UKAI <ukai@debian.or.jp>
Diffstat (limited to 'etc.c')
-rw-r--r-- | etc.c | 46 |
1 files changed, 29 insertions, 17 deletions
@@ -1,4 +1,4 @@ -/* $Id: etc.c,v 1.39 2002/11/22 15:57:29 ukai Exp $ */ +/* $Id: etc.c,v 1.40 2002/11/24 16:02:22 ukai Exp $ */ #include "fm.h" #include <pwd.h> #include "myctype.h" @@ -1294,39 +1294,51 @@ reset_signals(void) signal(SIGUSR1, SIG_IGN); } -void -myExec(char *command) -{ - int i; - - reset_signals(); - SETPGRP(); - close_tty(); - dup2(open("/dev/null", O_RDONLY), 0); - dup2(open("/dev/null", O_WRONLY), 1); - dup2(open("/dev/null", O_WRONLY), 2); #ifndef FOPEN_MAX #define FOPEN_MAX 1024 /* XXX */ #endif + +void +close_all_fds(int i) +{ + switch (i) { /* fall through */ + case 0: + dup2(open("/dev/null", O_RDONLY), 0); + case 1: + dup2(open("/dev/null", O_WRONLY), 1); + case 2: + dup2(open("/dev/null", O_WRONLY), 2); + } /* close all other file descriptors (socket, ...) */ for (i = 3; i < FOPEN_MAX; i++) close(i); +} + +#ifdef HAVE_SETPGRP +void +myExec(char *command) +{ + reset_signals(); + SETPGRP(); + close_tty(); + close_all_fds(0); execl("/bin/sh", "sh", "-c", command, NULL); exit(127); } +#endif void mySystem(char *command, int background) { if (background) { -#ifndef HAVE_SETPGRP - Str cmd = Strnew_charp("start /f "); - Strcat_charp(cmd, command); - system(cmd->ptr); -#else +#ifdef HAVE_SETPGRP flush_tty(); if (!fork()) myExec(command); +#else + Str cmd = Strnew_charp("start /f "); + Strcat_charp(cmd, command); + system(cmd->ptr); #endif } else |