From cdc65fdf224d19b5c7926ec6d4d4e78f57c0a0e0 Mon Sep 17 00:00:00 2001 From: Fumitoshi UKAI Date: Fri, 22 Nov 2002 15:49:42 +0000 Subject: [w3m-dev 03459] background download when external viewer * etc.c (myExec): added (mySystem): rewrite to use myExec() * file.c (doExternal): run background if BackgroundExtViewer * proto.h (myExec): added From: Hironori SAKAMOTO --- etc.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'etc.c') diff --git a/etc.c b/etc.c index 2ea7868..2484bc9 100644 --- a/etc.c +++ b/etc.c @@ -1,4 +1,4 @@ -/* $Id: etc.c,v 1.37 2002/11/08 15:54:47 ukai Exp $ */ +/* $Id: etc.c,v 1.38 2002/11/22 15:49:43 ukai Exp $ */ #include "fm.h" #include #include "myctype.h" @@ -1294,6 +1294,27 @@ 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 + /* close all other file descriptors (socket, ...) */ + for (i = 3; i < FOPEN_MAX; i++) + close(i); + execl("/bin/sh", "sh", "-c", command, NULL); + exit(127); +} + void mySystem(char *command, int background) { @@ -1303,25 +1324,9 @@ mySystem(char *command, int background) Strcat_charp(cmd, command); system(cmd->ptr); #else - int pid; flush_tty(); - if ((pid = fork()) == 0) { - 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 - /* close all other file descriptors (socket, ...) */ - for (i = 3; i < FOPEN_MAX; i++) - close(i); - execl("/bin/sh", "sh", "-c", command, NULL); - exit(127); - } + if (! fork()) + myExec(command); #endif } else -- cgit v1.2.3