Handle failed system calls
Introduce a separate TU for utility functions util.c. Add a function exec_cmd to simplify execution of system commands with error handling. While at it, suppress a warning about unused result when executing a shell command. As we only display the command's output we do not care about the exit code. This fixes Debian bug #398989[0] [0]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=398989
This commit is contained in:
+2
-2
@@ -90,11 +90,11 @@ MODEL=@W3M_TARGET@-@W3M_LANG@
|
|||||||
SRCS=main.c file.c buffer.c display.c etc.c search.c linein.c table.c local.c \
|
SRCS=main.c file.c buffer.c display.c etc.c search.c linein.c table.c local.c \
|
||||||
form.c map.c frame.c rc.c menu.c mailcap.c image.c \
|
form.c map.c frame.c rc.c menu.c mailcap.c image.c \
|
||||||
symbol.c entity.c terms.c url.c ftp.c mimehead.c regex.c news.c \
|
symbol.c entity.c terms.c url.c ftp.c mimehead.c regex.c news.c \
|
||||||
func.c cookie.c history.c backend.c $(KEYBIND_SRC)
|
func.c cookie.c history.c backend.c util.c $(KEYBIND_SRC)
|
||||||
OBJS=main.o file.o buffer.o display.o etc.o search.o linein.o table.o local.o\
|
OBJS=main.o file.o buffer.o display.o etc.o search.o linein.o table.o local.o\
|
||||||
form.o map.o frame.o rc.o menu.o mailcap.o image.o \
|
form.o map.o frame.o rc.o menu.o mailcap.o image.o \
|
||||||
symbol.o entity.o terms.o url.o ftp.o mimehead.o regex.o news.o \
|
symbol.o entity.o terms.o url.o ftp.o mimehead.o regex.o news.o \
|
||||||
func.o cookie.o history.o backend.o $(KEYBIND_OBJ)
|
func.o cookie.o history.o backend.o util.o $(KEYBIND_OBJ)
|
||||||
LSRCS=anchor.c parsetagx.c tagtable.c istream.c
|
LSRCS=anchor.c parsetagx.c tagtable.c istream.c
|
||||||
LOBJS=anchor.o parsetagx.o tagtable.o istream.o
|
LOBJS=anchor.o parsetagx.o tagtable.o istream.o
|
||||||
LLOBJS=version.o
|
LLOBJS=version.o
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "myctype.h"
|
#include "myctype.h"
|
||||||
#include "local.h"
|
#include "local.h"
|
||||||
#include "regex.h"
|
#include "regex.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
extern Str *textarea_str;
|
extern Str *textarea_str;
|
||||||
extern int max_textarea;
|
extern int max_textarea;
|
||||||
@@ -603,9 +604,8 @@ input_textarea(FormItemList *fi)
|
|||||||
form_fputs_decode(fi->value, f);
|
form_fputs_decode(fi->value, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
fmTerm();
|
if (exec_cmd(myEditor(Editor, tmpf, 1)->ptr))
|
||||||
system(myEditor(Editor, tmpf, 1)->ptr);
|
goto input_end;
|
||||||
fmInit();
|
|
||||||
|
|
||||||
if (fi->readonly)
|
if (fi->readonly)
|
||||||
goto input_end;
|
goto input_end;
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ extern int do_getch();
|
|||||||
#endif /* defined(USE_GPM) || defined(USE_SYSMOUSE) */
|
#endif /* defined(USE_GPM) || defined(USE_SYSMOUSE) */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#ifdef __MINGW32_VERSION
|
#ifdef __MINGW32_VERSION
|
||||||
#include <winsock.h>
|
#include <winsock.h>
|
||||||
|
|
||||||
@@ -2242,7 +2244,7 @@ DEFUN(execsh, EXEC_SHELL SHELL, "Execute shell command and display output")
|
|||||||
if (cmd != NULL && *cmd != '\0') {
|
if (cmd != NULL && *cmd != '\0') {
|
||||||
fmTerm();
|
fmTerm();
|
||||||
printf("\n");
|
printf("\n");
|
||||||
system(cmd);
|
(void)!system(cmd); /* We do not care about the exit code here! */
|
||||||
/* FIXME: gettextize? */
|
/* FIXME: gettextize? */
|
||||||
printf("\n[Hit any key]");
|
printf("\n[Hit any key]");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
@@ -2792,9 +2794,7 @@ DEFUN(editBf, EDIT, "Edit local source")
|
|||||||
else
|
else
|
||||||
cmd = myEditor(Editor, shell_quote(fn),
|
cmd = myEditor(Editor, shell_quote(fn),
|
||||||
cur_real_linenumber(Currentbuf));
|
cur_real_linenumber(Currentbuf));
|
||||||
fmTerm();
|
exec_cmd(cmd->ptr);
|
||||||
system(cmd->ptr);
|
|
||||||
fmInit();
|
|
||||||
|
|
||||||
displayBuffer(Currentbuf, B_FORCE_REDRAW);
|
displayBuffer(Currentbuf, B_FORCE_REDRAW);
|
||||||
reload();
|
reload();
|
||||||
@@ -2815,10 +2815,8 @@ DEFUN(editScr, EDIT_SCREEN, "Edit rendered copy of document")
|
|||||||
}
|
}
|
||||||
saveBuffer(Currentbuf, f, TRUE);
|
saveBuffer(Currentbuf, f, TRUE);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
fmTerm();
|
exec_cmd(myEditor(Editor, shell_quote(tmpf),
|
||||||
system(myEditor(Editor, shell_quote(tmpf),
|
cur_real_linenumber(Currentbuf))->ptr);
|
||||||
cur_real_linenumber(Currentbuf))->ptr);
|
|
||||||
fmInit();
|
|
||||||
unlink(tmpf);
|
unlink(tmpf);
|
||||||
displayBuffer(Currentbuf, B_FORCE_REDRAW);
|
displayBuffer(Currentbuf, B_FORCE_REDRAW);
|
||||||
}
|
}
|
||||||
@@ -3111,10 +3109,8 @@ handleMailto(char *url)
|
|||||||
if ((pos = strchr(to->ptr, '?')) != NULL)
|
if ((pos = strchr(to->ptr, '?')) != NULL)
|
||||||
Strtruncate(to, pos - to->ptr);
|
Strtruncate(to, pos - to->ptr);
|
||||||
}
|
}
|
||||||
fmTerm();
|
exec_cmd(myExtCommand(Mailer, shell_quote(file_unquote(to->ptr)),
|
||||||
system(myExtCommand(Mailer, shell_quote(file_unquote(to->ptr)),
|
|
||||||
FALSE)->ptr);
|
FALSE)->ptr);
|
||||||
fmInit();
|
|
||||||
displayBuffer(Currentbuf, B_FORCE_REDRAW);
|
displayBuffer(Currentbuf, B_FORCE_REDRAW);
|
||||||
pushHashHist(URLHist, url);
|
pushHashHist(URLHist, url);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
#include "display.h"
|
||||||
|
#include "terms.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
exec_cmd(char *cmd)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
fmTerm();
|
||||||
|
if ((rv = system(cmd))) {
|
||||||
|
printf("\n[Hit any key]");
|
||||||
|
fflush(stdout);
|
||||||
|
fmInit();
|
||||||
|
getch();
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
fmInit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user