Module Name:    src
Committed By:   dholland
Date:           Thu Dec  1 00:26:45 UTC 2011

Modified Files:
        src/usr.sbin/user: user.c

Log Message:
Handle return value from system() properly.
PR 45672 from River Tarnell.


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/usr.sbin/user/user.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/user/user.c
diff -u src/usr.sbin/user/user.c:1.127 src/usr.sbin/user/user.c:1.128
--- src/usr.sbin/user/user.c:1.127	Thu Dec  1 00:15:32 2011
+++ src/usr.sbin/user/user.c	Thu Dec  1 00:26:45 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: user.c,v 1.127 2011/12/01 00:15:32 dholland Exp $ */
+/* $NetBSD: user.c,v 1.128 2011/12/01 00:26:45 dholland Exp $ */
 
 /*
  * Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
@@ -33,12 +33,13 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1999\
  The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: user.c,v 1.127 2011/12/01 00:15:32 dholland Exp $");
+__RCSID("$NetBSD: user.c,v 1.128 2011/12/01 00:26:45 dholland Exp $");
 #endif
 
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/stat.h>
+#include <sys/wait.h>
 
 #include <ctype.h>
 #include <dirent.h>
@@ -265,8 +266,13 @@ asystem(const char *fmt, ...)
 	if (verbose) {
 		(void)printf("Command: %s\n", buf);
 	}
-	if ((ret = system(buf)) != 0) {
+	ret = system(buf);
+	if (ret == -1) {
 		warn("Error running `%s'", buf);
+	} else if (WIFSIGNALED(ret)) {
+		warnx("Error running `%s': Signal %d", buf, WTERMSIG(ret));
+	} else if (WIFEXITED(ret) && WEXITSTATUS(ret) != 0) {
+		warnx("Error running `%s': Exit %d", buf, WEXITSTATUS(ret));
 	}
 	return ret;
 }

Reply via email to