summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas François <nicolas.francois@centraliens.net>2013-08-25 16:27:58 +0200
committerNicolas François <nicolas.francois@centraliens.net>2013-08-25 16:27:58 +0200
commit5e87ff0615bbd8de2b709eb3d53d12dfaedb4dbc (patch)
tree7c3c7a91db85ea1de3e5dda39bd3bf957e7d1fa9
parentd409947e9a4433df474e21011d1213c98773e5aa (diff)
Improve vipw error report when editor fails
* src/vipw.c: After waitpid(), use errno only if waitpid returned -1. Debian#688260 * src/vipw.c: Likewise for system().
-rw-r--r--ChangeLog6
-rw-r--r--src/vipw.c33
2 files changed, 32 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index efc36416..201ce95d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-08-25 Nicolas François <nicolas.francois@centraliens.net>
+
+ * src/vipw.c: After waitpid(), use errno only if waitpid returned
+ -1. Debian#688260
+ * src/vipw.c: Likewise for system().
+
2013-08-23 victory <victory.deb@gmail.com>
* po/ja.po: Updated to 558t
diff --git a/src/vipw.c b/src/vipw.c
index 59b79c2c..6d730f65 100644
--- a/src/vipw.c
+++ b/src/vipw.c
@@ -180,7 +180,10 @@ static void vipwexit (const char *msg, int syserr, int ret)
if (0 != syserr) {
fprintf (stderr, ": %s", strerror (err));
}
- (void) fputs ("\n", stderr);
+ if ( (NULL != msg)
+ || (0 != syserr)) {
+ (void) fputs ("\n", stderr);
+ }
if (!quiet) {
fprintf (stdout, _("%s: %s is unchanged\n"), Prog,
filename);
@@ -297,14 +300,25 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
/* use the system() call to invoke the editor so that it accepts
command line args in the EDITOR and VISUAL environment vars */
char *buf;
+ int status;
buf = (char *) malloc (strlen (editor) + strlen (fileedit) + 2);
snprintf (buf, strlen (editor) + strlen (fileedit) + 2,
- "%s %s", editor, fileedit);
- if (system (buf) != 0) {
- fprintf (stderr, "%s: %s: %s\n", Prog, editor,
+ "%s %s", editor, fileedit);
+ status = system (buf);
+ if (-1 == status) {
+ fprintf (stderr, _("%s: %s: %s\n"), Prog, editor,
strerror (errno));
exit (1);
+ } else if ( WIFEXITED (status)
+ && (WEXITSTATUS (status) != 0)) {
+ fprintf (stderr, _("%s: %s returned with status %d\n"),
+ Prog, editor, WEXITSTATUS (status));
+ exit (WEXITSTATUS (status));
+ } else if (WIFSIGNALED (status)) {
+ fprintf (stderr, _("%s: %s killed by signal %d\n"),
+ Prog, editor, WTERMSIG (status));
+ exit (1);
} else {
exit (0);
}
@@ -323,10 +337,15 @@ vipwedit (const char *file, int (*file_lock) (void), int (*file_unlock) (void))
}
}
- if ( (-1 == pid)
- || (WIFEXITED (status) == 0)
- || (WEXITSTATUS (status) != 0)) {
+ if (-1 == pid) {
vipwexit (editor, 1, 1);
+ } else if ( WIFEXITED (status)
+ && (WEXITSTATUS (status) != 0)) {
+ vipwexit (NULL, 0, WEXITSTATUS (status));
+ } else if (WIFSIGNALED (status)) {
+ fprintf (stderr, _("%s: %s killed by signal %d\n"),
+ Prog, editor, WTERMSIG(status));
+ vipwexit (NULL, 0, 1);
}
if (stat (fileedit, &st2) != 0) {