diff options
author | Christian Perrier <bubulle@debian.org> | 2014-03-01 19:59:36 +0100 |
---|---|---|
committer | Christian Perrier <bubulle@debian.org> | 2014-03-01 19:59:36 +0100 |
commit | 65b471a2f27acb2f3ce378106eb8aeba8b496557 (patch) | |
tree | 29941e07f9b1d7c9a44a08b65782505eb6ef58a5 /src/vipw.c | |
parent | db1dc7288b64873f4f39e8404fd99c1bf55c7a8b (diff) | |
download | shadow-65b471a2f27acb2f3ce378106eb8aeba8b496557.tar.gz |
Imported Upstream version 4.2upstream/4.2
Diffstat (limited to 'src/vipw.c')
-rw-r--r-- | src/vipw.c | 41 |
1 files changed, 32 insertions, 9 deletions
@@ -5,7 +5,7 @@ Copyright (c) 1997 , Guy Maor <maor@ece.utexas.edu> Copyright (c) 1999 - 2000, Marek Michałkiewicz Copyright (c) 2002 - 2006, Tomasz Kłoczko - Copyright (c) 2007 - 2011, Nicolas François + Copyright (c) 2007 - 2013, Nicolas François All rights reserved. This program is free software; you can redistribute it and/or modify @@ -25,7 +25,7 @@ #include <config.h> -#ident "$Id: vipw.c 3654 2011-12-09 21:35:57Z nekral-guest $" +#ident "$Id$" #include <errno.h> #include <getopt.h> @@ -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) { @@ -480,6 +499,10 @@ int main (int argc, char **argv) usage (E_USAGE); } } + + if (optind != argc) { + usage (E_USAGE); + } } if (do_vipw) { |