aboutsummaryrefslogtreecommitdiffstats
path: root/etc.c
diff options
context:
space:
mode:
authorFumitoshi UKAI <ukai@debian.or.jp>2003-01-17 16:57:17 +0000
committerFumitoshi UKAI <ukai@debian.or.jp>2003-01-17 16:57:17 +0000
commit439d2745a517b84993c2d8dc2eda8b168fe75d2b (patch)
treea8f3874bdc1d8cf72375c78fb35d332bf409e4fd /etc.c
parentNEWS update (diff)
downloadw3m-439d2745a517b84993c2d8dc2eda8b168fe75d2b.tar.gz
w3m-439d2745a517b84993c2d8dc2eda8b168fe75d2b.zip
[w3m-dev 03646] setup child process, local CGI
* etc.c (reset_signals): static don't ignore SIGUSR1 (close_all_fds_except): static DEV_NULL_PATH (setup_child): added (myExec): rewrite (mySystem): rewrite * file.c (readHeader): check image_source (loadGeneralFile): check image_source (doExternal): use setup_child (_doFileCopy): use setup_child (doFileSave): use setup_child (uncompress_stream): check image_source use setup_child * image.c (getCharSize): no need stderr redirect (openImgdisplay): use setup_child (loadImage): use setup_child (getImageSize): no need stderr redirect * local.c (writeLocalCookie): check Local_cookie_file (localcgi_popen_rw): added (localcgi_popen_r): deleted (localcgi_post): rewrite (localcgi_get): deleted * proto.h (localcgi_get): defined by localcgi_post (reset_signals): deleted (close_all_fds_except): deleted (close_all_fds): deleted (setup_child): added * search.c (open_migemo): use setup_child, myExec * w3mimgdisplay.c (main): use DEV_NULL_PATH From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
Diffstat (limited to '')
-rw-r--r--etc.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/etc.c b/etc.c
index 886cb1d..c48771d 100644
--- a/etc.c
+++ b/etc.c
@@ -1,4 +1,4 @@
-/* $Id: etc.c,v 1.49 2003/01/15 17:13:21 ukai Exp $ */
+/* $Id: etc.c,v 1.50 2003/01/17 16:57:18 ukai Exp $ */
#include "fm.h"
#include <pwd.h>
#include "myctype.h"
@@ -7,6 +7,7 @@
#include "hash.h"
#include "terms.h"
+#include <fcntl.h>
#include <sys/types.h>
#include <time.h>
#if defined(HAVE_WAITPID) || defined(HAVE_WAIT3)
@@ -1279,7 +1280,7 @@ romanAlphabet(int n)
#define SIGIOT SIGABRT
#endif /* not SIGIOT */
-void
+static void
reset_signals(void)
{
signal(SIGHUP, SIG_DFL); /* terminate process */
@@ -1298,23 +1299,22 @@ reset_signals(void)
#ifdef SIGPIPE
signal(SIGPIPE, SIG_IGN);
#endif
- signal(SIGUSR1, SIG_IGN);
}
#ifndef FOPEN_MAX
#define FOPEN_MAX 1024 /* XXX */
#endif
-void
+static void
close_all_fds_except(int i, int f)
{
switch (i) { /* fall through */
case 0:
- dup2(open("/dev/null", O_RDONLY), 0);
+ dup2(open(DEV_NULL_PATH, O_RDONLY), 0);
case 1:
- dup2(open("/dev/null", O_WRONLY), 1);
+ dup2(open(DEV_NULL_PATH, O_WRONLY), 1);
case 2:
- dup2(open("/dev/null", O_WRONLY), 2);
+ dup2(open(DEV_NULL_PATH, O_WRONLY), 2);
}
/* close all other file descriptors (socket, ...) */
for (i = 3; i < FOPEN_MAX; i++) {
@@ -1323,27 +1323,37 @@ close_all_fds_except(int i, int f)
}
}
-#ifdef HAVE_SETPGRP
void
-myExec(char *command)
+setup_child(int child, int i, int f)
{
reset_signals();
- SETPGRP();
+ signal(SIGINT, SIG_IGN);
+ if (!child)
+ SETPGRP();
close_tty();
- close_all_fds(0);
+ close_all_fds_except(i, f);
+ QuietMessage = TRUE;
+ fmInitialized = FALSE;
+}
+
+void
+myExec(char *command)
+{
+ signal(SIGINT, SIG_DFL);
execl("/bin/sh", "sh", "-c", command, NULL);
exit(127);
}
-#endif
void
mySystem(char *command, int background)
{
if (background) {
-#ifdef HAVE_SETPGRP
+#ifndef __EMX__
flush_tty();
- if (!fork())
+ if (!fork()) {
+ setup_child(FALSE, 0, -1);
myExec(command);
+ }
#else
Str cmd = Strnew_charp("start /f ");
Strcat_charp(cmd, command);