Index: lib/libutil/pw_util.c =================================================================== --- lib/libutil/pw_util.c +++ lib/libutil/pw_util.c @@ -291,6 +291,9 @@ struct stat st1, st2; const char *editor; int pstat; + int ret_code; + int ret_stat; + int file_changed; if ((editor = getenv("EDITOR")) == NULL) editor = _PATH_VI; @@ -343,10 +346,30 @@ sigaction(SIGINT, &sa_int, NULL); sigaction(SIGQUIT, &sa_quit, NULL); sigprocmask(SIG_SETMASK, &oldsigset, NULL); - if (stat(tempname, &st2) == -1) - return (-1); - return (st1.st_mtim.tv_sec != st2.st_mtim.tv_sec || + + /* Collect information about how the process ended */ + ret_code = WEXITSTATUS(pstat); + ret_stat = stat(tempname, &st2); + file_changed = (st1.st_mtim.tv_sec != st2.st_mtim.tv_sec || st1.st_mtim.tv_nsec != st2.st_mtim.tv_nsec); + + if (ret_code != 0) { + /* Program finished abnormally */ + editpid = -1; + fprintf(stderr, "'%s' failed with error code %d: %s\n", editor, + ret_code, strerror(ret_code)); + if (ret_stat != 0) { + /* We can not access tempname. So no changes were made */ + return (0); + } + return file_changed; + } + + /* Program finished normally */ + if (ret_stat != 0) + return (-1); + + return file_changed; } /*