From 4d7a10faacb9f77dd7535bc73f5c3e370a921626 Mon Sep 17 00:00:00 2001 From: Marco Peereboom Date: Tue, 31 Jan 2012 14:46:00 -0600 Subject: abstract fork and exec --- Makefile | 2 +- freebsd/Makefile | 5 ++++- xxxterm.c | 64 ++++++-------------------------------------------------- xxxterm.h | 3 +++ 4 files changed, 14 insertions(+), 60 deletions(-) diff --git a/Makefile b/Makefile index ac9d824..3557c39 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ PROG=xxxterm MAN=xxxterm.1 SRCS= cookie.c inspector.c marco.c about.c whitelist.c settings.c inputfocus.c -SRCS+= history.c completion.c tldlist.c externaleditor.c xxxterm.c +SRCS+= history.c completion.c tldlist.c externaleditor.c unix.c xxxterm.c CFLAGS+= -O2 -Wall -Wno-format-extra-args -Wunused CFLAGS+= -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare CFLAGS+= -I. -I${.CURDIR} diff --git a/freebsd/Makefile b/freebsd/Makefile index 535b51f..b5da90f 100644 --- a/freebsd/Makefile +++ b/freebsd/Makefile @@ -21,6 +21,8 @@ all: ../javascript.h xxxterm xxxterm.o: ../xxxterm.o +unix.o: ../unix.o + marco.o: ../marco.o whitelist.o: ../whitelist.o @@ -46,7 +48,8 @@ tldlist.o: ../tldlist.o ../xxxterm.o: ../javascript.h xxxterm: xxxterm.o freebsd.o marco.o about.o inspector.o whitelist.o settings.o \ - cookie.o history.o completion.o inputfocus.o tldlist.o externaleditor.o + cookie.o history.o completion.o inputfocus.o tldlist.o externaleditor.o \ + unix.o $(CC) $(LDFLAGS) -o $@ *.o $+ $(LDADD) install: all diff --git a/xxxterm.c b/xxxterm.c index fbc21b4..3c47fa4 100644 --- a/xxxterm.c +++ b/xxxterm.c @@ -1316,25 +1316,7 @@ run_page_script(struct tab *t, struct karg *args) else strlcpy(script, tmp, sizeof script); - switch (fork()) { - case -1: - show_oops(t, "can't fork to run script"); - return (1); - /* NOTREACHED */ - case 0: - break; - default: - return (0); - } - - /* child */ - execlp(script, script, uri, (void *)NULL); - - _exit(0); - - /* NOTREACHED */ - - return (0); + return (fork_exec(t, script, uri, "can't launch external script")); } int @@ -4323,25 +4305,9 @@ run_mimehandler(struct tab *t, char *mime_type, WebKitNetworkRequest *request) if (m->mt_download) return (1); - switch (fork()) { - case -1: - show_oops(t, "can't fork mime handler"); - return (1); - /* NOTREACHED */ - case 0: - break; - default: - return (0); - } - - /* child */ - execlp(m->mt_action, m->mt_action, - webkit_network_request_get_uri(request), (void *)NULL); - - _exit(0); - - /* NOTREACHED */ - return (0); + return (fork_exec(t, m->mt_action, + webkit_network_request_get_uri(request), + "can't launch MIME handler")); } char * @@ -4375,26 +4341,8 @@ run_download_mimehandler(char *mime_type, char *file) if (m == NULL) return (1); - switch (fork()) { - case -1: - show_oops(NULL, "can't fork download mime handler"); - return (1); - /* NOTREACHED */ - case 0: - break; - default: - return (0); - } - - /* child */ - if (g_str_has_prefix(file, "file://")) - file += strlen("file://"); - execlp(m->mt_action, m->mt_action, file, (void *)NULL); - - _exit(0); - - /* NOTREACHED */ - return (0); + return (fork_exec(NULL, m->mt_action, file, + "can't launch download MIME handler")); } void diff --git a/xxxterm.h b/xxxterm.h index 0eb2dd0..4c7c4d4 100644 --- a/xxxterm.h +++ b/xxxterm.h @@ -470,6 +470,9 @@ void input_focus_blur(struct tab *, void *); void *input_check_mode(struct tab *); int command_mode(struct tab *, struct karg *); +/* OS specific */ +int fork_exec(struct tab *, char *, const gchar *, char *); + /* settings */ #define XT_BM_NORMAL (0) #define XT_BM_WHITELIST (1) -- cgit 1.4.1-2-gfad0