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".
This commit is contained in:
apb 2009-09-24 16:15:20 +00:00
parent eecdf6949e
commit 29d1bfefcb
2 changed files with 35 additions and 10 deletions

View File

@ -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 @@ server:/export/swap/client none swap sw,nfsmntpt=/swap
.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

View File

@ -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 @@ do_fstab(int add)
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 @@ do_fstab(int add)
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 @@ do_fstab(int add)
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