w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

commit 006a4df7e4c83642a8209b5f6ba1c9c108f08d20
parent c7bb336c3f3f8c2383af47498bf272dacf300691
Author: ukai <ukai>
Date:   Sun, 24 Nov 2002 16:02:22 +0000

[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:
MChangeLog | 15+++++++++++++++
Mconfigure | 1+
Metc.c | 44++++++++++++++++++++++++++++----------------
Mfile.c | 4----
Mimage.c | 12++----------
Mproto.h | 3+++
Msearch.c | 12++----------
7 files changed, 51 insertions(+), 40 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,18 @@ +2002-11-25 Fumitoshi UKAI <ukai@debian.or.jp> + + * [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 + 2002-11-23 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp> * [w3m-dev 03466] Re: background download when external viewer diff --git a/configure b/configure @@ -2008,6 +2008,7 @@ EOF def_setpgrp='#define SETPGRP() setpgrp( 0, 0 )' else def_have_setpgrp='' + def_setpgrp='#define SETPGRP() /* no setpgrp() */' fi fi diff --git a/etc.c b/etc.c @@ -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 diff --git a/file.c b/file.c @@ -7274,9 +7274,7 @@ _doFileCopy(char *tmpf, char *defstr, int download) if (!pid) { reset_signals(); signal(SIGINT, SIG_IGN); -#ifdef HAVE_SETPGRP SETPGRP(); -#endif close_tty(); QuietMessage = TRUE; fmInitialized = FALSE; @@ -7374,9 +7372,7 @@ doFileSave(URLFile uf, char *defstr) if (!pid) { reset_signals(); signal(SIGINT, SIG_IGN); -#ifdef HAVE_SETPGRP SETPGRP(); -#endif close_tty(); QuietMessage = TRUE; fmInitialized = FALSE; diff --git a/image.c b/image.c @@ -107,30 +107,22 @@ openImgdisplay() goto err2; if (Imgdisplay_pid == 0) { /* child */ - int i; reset_signals(); signal(SIGINT, SIG_IGN); set_environ("W3M_TTY", ttyname_tty()); -#ifdef HAVE_SETPGRP SETPGRP(); -#endif close_tty(); close(fdr[0]); close(fdw[1]); dup2(fdw[0], 0); dup2(fdr[1], 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); + close_all_fds(2); if (!strchr(Imgdisplay, '/')) cmd = Strnew_m_charp(w3m_auxbin_dir(), "/", Imgdisplay, NULL)->ptr; else cmd = Imgdisplay; execl("/bin/sh", "sh", "-c", cmd, NULL); + /* XXX: ifndef HAVE_SETPGRP, use start /f ? */ exit(1); } close(fdr[1]); diff --git a/proto.h b/proto.h @@ -560,7 +560,10 @@ extern char *last_modified(Buffer *buf); extern Str romanNumeral(int n); extern Str romanAlphabet(int n); extern void reset_signals(void); +extern void close_all_fds(int i); +#ifdef HAVE_SETPGRP extern void myExec(char *command); +#endif extern void mySystem(char *command, int background); extern Str myExtCommand(char *cmd, char *arg, int redirect); extern Str myEditor(char *cmd, char *file, int line); diff --git a/search.c b/search.c @@ -50,24 +50,16 @@ open_migemo(char *migemo_command) goto err2; if (migemo_pid == 0) { /* child */ - int i; reset_signals(); -#ifdef HAVE_SETPGRP SETPGRP(); -#endif close_tty(); close(fdr[0]); close(fdw[1]); dup2(fdw[0], 0); dup2(fdr[1], 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); + close_all_fds(2); execl("/bin/sh", "sh", "-c", migemo_command, NULL); + /* XXX: ifndef HAVE_SETPGRP, use "start /f"? */ exit(1); } close(fdr[1]);