Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/swapctl Make the exit status from "swapctl -A" and "swa...
details: https://anonhg.NetBSD.org/src/rev/eef266dc883c
branches: trunk
changeset: 747614:eef266dc883c
user: apb <apb%NetBSD.org@localhost>
date: Thu Sep 24 16:15:20 2009 +0000
description:
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".
diffstat:
sbin/swapctl/swapctl.8 | 17 +++++++++++++----
sbin/swapctl/swapctl.c | 28 ++++++++++++++++++++++------
2 files changed, 35 insertions(+), 10 deletions(-)
diffs (119 lines):
diff -r 8056c2730fad -r eef266dc883c sbin/swapctl/swapctl.8
--- a/sbin/swapctl/swapctl.8 Thu Sep 24 16:03:11 2009 +0000
+++ b/sbin/swapctl/swapctl.8 Thu Sep 24 16:15:20 2009 +0000
@@ -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
diff -r 8056c2730fad -r eef266dc883c sbin/swapctl/swapctl.c
--- a/sbin/swapctl/swapctl.c Thu Sep 24 16:03:11 2009 +0000
+++ b/sbin/swapctl/swapctl.c Thu Sep 24 16:15:20 2009 +0000
@@ -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
Home |
Main Index |
Thread Index |
Old Index