Module Name: src
Committed By: apb
Date: Thu Sep 24 16:15:20 UTC 2009
Modified Files:
src/sbin/swapctl: swapctl.8 swapctl.c
Log Message:
Make the exit status from "swapctl -A" and "swapctl -U" tri-state:
0 for success; 1 for error; and 2 when no devices of the appropriate type
are defined in fstab(5). Previously, "no apropriate devices" was
indistinguishable from "error".
To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sbin/swapctl/swapctl.8
cvs rdiff -u -r1.34 -r1.35 src/sbin/swapctl/swapctl.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/swapctl/swapctl.8
diff -u src/sbin/swapctl/swapctl.8:1.40 src/sbin/swapctl/swapctl.8:1.41
--- src/sbin/swapctl/swapctl.8:1.40 Thu May 29 14:51:25 2008
+++ src/sbin/swapctl/swapctl.8 Thu Sep 24 16:15:20 2009
@@ -1,4 +1,4 @@
-.\" $NetBSD: swapctl.8,v 1.40 2008/05/29 14:51:25 mrg Exp $
+.\" $NetBSD: swapctl.8,v 1.41 2009/09/24 16:15:20 apb Exp $
.\"
.\" Copyright (c) 1997 Matthew R. Green
.\" All rights reserved.
@@ -24,7 +24,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd August 2, 2007
+.Dd September 24, 2009
.Dt SWAPCTL 8
.Os
.Sh NAME
@@ -323,12 +323,21 @@
.Ed
.El
.Sh EXIT STATUS
-If the requested operation was sucessful, the
+If the requested operation was successful, the
.Nm
utility exits with status 0.
If an error occurred, the exit status is 1.
.Pp
-For easy scriptability, the
+The
+.Fl A
+and
+.Fl U
+operations (add or remove swap devices listed in
+.Xr fstab 5 )
+return an exit status of 2
+to report that no suitable swap devices were found.
+.Pp
+The
.Fl z
operation (query dump device) and
.Fl l
Index: src/sbin/swapctl/swapctl.c
diff -u src/sbin/swapctl/swapctl.c:1.34 src/sbin/swapctl/swapctl.c:1.35
--- src/sbin/swapctl/swapctl.c:1.34 Sun Dec 28 20:18:53 2008
+++ src/sbin/swapctl/swapctl.c Thu Sep 24 16:15:20 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: swapctl.c,v 1.34 2008/12/28 20:18:53 christos Exp $ */
+/* $NetBSD: swapctl.c,v 1.35 2009/09/24 16:15:20 apb Exp $ */
/*
* Copyright (c) 1996, 1997, 1999 Matthew R. Green
@@ -64,7 +64,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: swapctl.c,v 1.34 2008/12/28 20:18:53 christos Exp $");
+__RCSID("$NetBSD: swapctl.c,v 1.35 2009/09/24 16:15:20 apb Exp $");
#endif
@@ -679,7 +679,8 @@
long priority;
struct stat st;
int isblk;
- int gotone = 0;
+ int success = 0; /* set to 1 after a successful operation */
+ int error = 0; /* set to 1 after an error */
#ifdef RESCUEDIR
#define PATH_MOUNT RESCUEDIR "/mount_nfs"
@@ -779,21 +780,32 @@
if (add) {
if (add_swap(spec, (int)priority)) {
- gotone = 1;
+ success = 1;
printf(
"%s: adding %s as swap device at priority %d\n",
getprogname(), fp->fs_spec, (int)priority);
+ } else {
+ error = 1;
+ fprintf(stderr,
+ "%s: failed to add %s as swap device\n",
+ getprogname(), fp->fs_spec);
}
} else {
if (delete_swap(spec)) {
- gotone = 1;
+ success = 1;
printf(
"%s: removing %s as swap device\n",
getprogname(), fp->fs_spec);
+ } else {
+ error = 1;
+ fprintf(stderr,
+ "%s: failed to remove %s as swap device\n",
+ getprogname(), fp->fs_spec);
}
if (cmd[0]) {
if (system(cmd) != 0) {
warnx("%s: umount failed", fp->fs_spec);
+ error = 1;
continue;
}
}
@@ -802,8 +814,12 @@
if (spec != fp->fs_spec)
free(spec);
}
- if (gotone == 0)
+ if (error)
exit(1);
+ else if (success)
+ exit(0);
+ else
+ exit(2); /* not really an error, but no swap devices found */
}
static void