CVS commit: src/sbin/swapctl

2016-05-31 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Tue May 31 09:34:25 UTC 2016

Modified Files:
src/sbin/swapctl: swaplist.c

Log Message:
Minor formatting change in swapctl -l as noted in my PR bin/51155


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sbin/swapctl/swaplist.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/swaplist.c
diff -u src/sbin/swapctl/swaplist.c:1.17 src/sbin/swapctl/swaplist.c:1.18
--- src/sbin/swapctl/swaplist.c:1.17	Mon Apr  6 12:38:35 2009
+++ src/sbin/swapctl/swaplist.c	Tue May 31 09:34:25 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: swaplist.c,v 1.17 2009/04/06 12:38:35 lukem Exp $	*/
+/*	$NetBSD: swaplist.c,v 1.18 2016/05/31 09:34:25 pgoyette Exp $	*/
 
 /*
  * Copyright (c) 1997 Matthew R. Green
@@ -28,7 +28,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: swaplist.c,v 1.17 2009/04/06 12:38:35 lukem Exp $");
+__RCSID("$NetBSD: swaplist.c,v 1.18 2016/05/31 09:34:25 pgoyette Exp $");
 #endif
 
 
@@ -184,10 +184,10 @@ list_swap(int pri, int kflag, int pflag,
 			if ((humanize_number(avbuf, sizeof(avbuf), (dbtoqb(totalsize-totalinuse)),
 "", HN_AUTOSCALE, (HN_DECIMAL | HN_B | HN_NOSPACE))) == -1)
 err(1, "humanize_number");
-			(void)printf("total: %s allocated = %s used, %s available.\n",
+			(void)printf("total: %s allocated, %s used, %s available.\n",
 szbuf, usbuf, avbuf);
 		} else {
-		printf("total: %ld %s allocated = %ld %s used, "
+		printf("total: %ld %s allocated, %ld %s used, "
 			   "%ld %s available\n",
 		(long)(dbtoqb(totalsize) / blocksize), suff,
 		(long)(dbtoqb(totalinuse) / blocksize), suff,



CVS commit: src/sbin/swapctl

2015-10-11 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Oct 11 23:58:16 UTC 2015

Modified Files:
src/sbin/swapctl: swapctl.c

Log Message:
don't stop processing /etc/fstab when one entry fails, both for
add and remove loops.  now when you add a new swap file and run
"swapctl -A" it won't give up after the existing one gives EBUSY
and move on to the rest.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 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.c
diff -u src/sbin/swapctl/swapctl.c:1.39 src/sbin/swapctl/swapctl.c:1.40
--- src/sbin/swapctl/swapctl.c:1.39	Tue Jan  1 19:01:10 2013
+++ src/sbin/swapctl/swapctl.c	Sun Oct 11 23:58:16 2015
@@ -1,7 +1,7 @@
-/*	$NetBSD: swapctl.c,v 1.39 2013/01/01 19:01:10 dsl Exp $	*/
+/*	$NetBSD: swapctl.c,v 1.40 2015/10/11 23:58:16 mrg Exp $	*/
 
 /*
- * Copyright (c) 1996, 1997, 1999 Matthew R. Green
+ * Copyright (c) 1996, 1997, 1999, 2015 Matthew R. Green
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -64,7 +64,7 @@
 #include 
 
 #ifndef lint
-__RCSID("$NetBSD: swapctl.c,v 1.39 2013/01/01 19:01:10 dsl Exp $");
+__RCSID("$NetBSD: swapctl.c,v 1.40 2015/10/11 23:58:16 mrg Exp $");
 #endif
 
 
@@ -151,7 +151,7 @@ static int	pri;		/* uses 0 as default pr
 static	void change_priority(char *);
 static	int  add_swap(char *, int);
 static	int  delete_swap(char *);
-static	void set_dumpdev1(char *);
+static	int set_dumpdev1(char *);
 static	void set_dumpdev(char *);
 static	int get_dumpdev(void);
 __dead static	void do_fstab(int);
@@ -475,9 +475,10 @@ add_swap(char *path, int priority)
 
 	if (swapctl(SWAP_ON, spec, priority) < 0) {
 oops:
-		err(1, "%s", path);
+		warn("%s", path);
+		return 0;
 	}
-	return (1);
+	return 1;
 }
 
 /*
@@ -489,19 +490,23 @@ delete_swap(char *path)
 	char buf[MAXPATHLEN];
 	char *spec;
 
-	if (getfsspecname(buf, sizeof(buf), path) == NULL)
-		err(1, "%s", path);
+	if (getfsspecname(buf, sizeof(buf), path) == NULL) {
+		warn("%s", path);
+		return 0;
+	}
 	spec = buf;
 
 	if (nflag)
 		return 1;
 
-	if (swapctl(SWAP_OFF, spec, pri) < 0) 
-		err(1, "%s", path);
-	return (1);
+	if (swapctl(SWAP_OFF, spec, pri) < 0) {
+		warn("%s", path);
+		return 0;
+	}
+	return 1;
 }
 
-static void
+static int
 set_dumpdev1(char *spec)
 {
 	int rv = 0;
@@ -514,9 +519,11 @@ set_dumpdev1(char *spec)
 	}
 
 	if (rv == -1)
-		err(1, "could not set dump device to %s", spec);
+		warn("could not set dump device to %s", spec);
 	else
 		printf("%s: setting dump device to %s\n", getprogname(), spec);
+
+	return rv == -1 ? 0 : 1;
 }
 
 static void
@@ -529,7 +536,8 @@ set_dumpdev(char *path)
 		err(1, "%s", path);
 	spec = buf;
 
-	return set_dumpdev1(spec);
+	if (! set_dumpdev1(spec))
+		exit(1);
 }
 
 static int



CVS commit: src/sbin/swapctl

2013-01-01 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Tue Jan  1 19:01:11 UTC 2013

Modified Files:
src/sbin/swapctl: swapctl.c

Log Message:
Explicitly include sys/ioctl.h


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 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.c
diff -u src/sbin/swapctl/swapctl.c:1.38 src/sbin/swapctl/swapctl.c:1.39
--- src/sbin/swapctl/swapctl.c:1.38	Wed Dec 26 10:15:28 2012
+++ src/sbin/swapctl/swapctl.c	Tue Jan  1 19:01:10 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: swapctl.c,v 1.38 2012/12/26 10:15:28 mlelstv Exp $	*/
+/*	$NetBSD: swapctl.c,v 1.39 2013/01/01 19:01:10 dsl Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1999 Matthew R. Green
@@ -64,11 +64,12 @@
 #include sys/cdefs.h
 
 #ifndef lint
-__RCSID($NetBSD: swapctl.c,v 1.38 2012/12/26 10:15:28 mlelstv Exp $);
+__RCSID($NetBSD: swapctl.c,v 1.39 2013/01/01 19:01:10 dsl Exp $);
 #endif
 
 
 #include sys/param.h
+#include sys/ioctl.h
 #include sys/stat.h
 #include sys/swap.h
 #include sys/sysctl.h



CVS commit: src/sbin/swapctl

2012-12-26 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Wed Dec 26 10:15:29 UTC 2012

Modified Files:
src/sbin/swapctl: swapctl.c

Log Message:
Allow named wedges to be used on command line, also fix name lookup
for the dump device.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 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.c
diff -u src/sbin/swapctl/swapctl.c:1.37 src/sbin/swapctl/swapctl.c:1.38
--- src/sbin/swapctl/swapctl.c:1.37	Sat Apr  7 04:52:20 2012
+++ src/sbin/swapctl/swapctl.c	Wed Dec 26 10:15:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: swapctl.c,v 1.37 2012/04/07 04:52:20 christos Exp $	*/
+/*	$NetBSD: swapctl.c,v 1.38 2012/12/26 10:15:28 mlelstv 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.37 2012/04/07 04:52:20 christos Exp $);
+__RCSID($NetBSD: swapctl.c,v 1.38 2012/12/26 10:15:28 mlelstv Exp $);
 #endif
 
 
@@ -150,6 +150,7 @@ static int	pri;		/* uses 0 as default pr
 static	void change_priority(char *);
 static	int  add_swap(char *, int);
 static	int  delete_swap(char *);
+static	void set_dumpdev1(char *);
 static	void set_dumpdev(char *);
 static	int get_dumpdev(void);
 __dead static	void do_fstab(int);
@@ -445,8 +446,14 @@ static int
 add_swap(char *path, int priority)
 {
 	struct stat sb;
+	char buf[MAXPATHLEN];
+	char *spec;
 
-	if (stat(path, sb)  0)
+	if (getfsspecname(buf, sizeof(buf), path) == NULL)
+		goto oops;
+	spec = buf;
+
+	if (stat(spec, sb)  0)
 		goto oops;
 
 	if (sb.st_mode  S_IROTH) 
@@ -455,7 +462,7 @@ add_swap(char *path, int priority)
 		warnx(WARNING: %s is writable by the world, path);
 
 	if (fflag || oflag) {
-		set_dumpdev(path);
+		set_dumpdev1(spec);
 		if (oflag)
 			exit(0);
 		else
@@ -465,7 +472,7 @@ add_swap(char *path, int priority)
 	if (nflag)
 		return 1;
 
-	if (swapctl(SWAP_ON, path, priority)  0) {
+	if (swapctl(SWAP_ON, spec, priority)  0) {
 oops:
 		err(1, %s, path);
 	}
@@ -478,31 +485,50 @@ oops:
 static int
 delete_swap(char *path)
 {
+	char buf[MAXPATHLEN];
+	char *spec;
+
+	if (getfsspecname(buf, sizeof(buf), path) == NULL)
+		err(1, %s, path);
+	spec = buf;
 
 	if (nflag)
 		return 1;
 
-	if (swapctl(SWAP_OFF, path, pri)  0) 
+	if (swapctl(SWAP_OFF, spec, pri)  0) 
 		err(1, %s, path);
 	return (1);
 }
 
 static void
-set_dumpdev(char *path)
+set_dumpdev1(char *spec)
 {
 	int rv = 0;
 
 	if (!nflag) {
-		if (strcmp(path, none) == 0) 
+		if (strcmp(spec, none) == 0) 
 			rv = swapctl(SWAP_DUMPOFF, NULL, 0);
 		else
-			rv = swapctl(SWAP_DUMPDEV, path, 0);
+			rv = swapctl(SWAP_DUMPDEV, spec, 0);
 	}
 
 	if (rv == -1)
-		err(1, could not set dump device to %s, path);
+		err(1, could not set dump device to %s, spec);
 	else
-		printf(%s: setting dump device to %s\n, getprogname(), path);
+		printf(%s: setting dump device to %s\n, getprogname(), spec);
+}
+
+static void
+set_dumpdev(char *path)
+{
+	char buf[MAXPATHLEN];
+	char *spec;
+
+	if (getfsspecname(buf, sizeof(buf), path) == NULL)
+		err(1, %s, path);
+	spec = buf;
+
+	return set_dumpdev1(spec);
 }
 
 static int
@@ -706,7 +732,7 @@ do_fstab(int add)
 		cmd[0] = '\0';
 
 		if (strcmp(fp-fs_type, dp) == 0  add) {
-			set_dumpdev(spec);
+			set_dumpdev1(spec);
 			continue;
 		}
 
@@ -715,7 +741,7 @@ do_fstab(int add)
 
 		/* handle dp as mnt option */
 		if (strstr(fp-fs_mntops, dp)  add)
-			set_dumpdev(spec);
+			set_dumpdev1(spec);
 
 		isblk = 0;
 



CVS commit: src/sbin/swapctl

2011-08-27 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Aug 27 18:57:50 UTC 2011

Modified Files:
src/sbin/swapctl: swapctl.c

Log Message:
static + __dead


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 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.c
diff -u src/sbin/swapctl/swapctl.c:1.35 src/sbin/swapctl/swapctl.c:1.36
--- src/sbin/swapctl/swapctl.c:1.35	Thu Sep 24 16:15:20 2009
+++ src/sbin/swapctl/swapctl.c	Sat Aug 27 18:57:50 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: swapctl.c,v 1.35 2009/09/24 16:15:20 apb Exp $	*/
+/*	$NetBSD: swapctl.c,v 1.36 2011/08/27 18:57:50 joerg 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.35 2009/09/24 16:15:20 apb Exp $);
+__RCSID($NetBSD: swapctl.c,v 1.36 2011/08/27 18:57:50 joerg Exp $);
 #endif
 
 
@@ -88,7 +88,7 @@
 
 #include swapctl.h
 
-int	command;
+static int	command;
 
 /*
  * Commands for swapctl(8).  These are mutually exclusive.
@@ -121,45 +121,45 @@
 /*
  * Option flags, and the commands with which they are valid.
  */
-int	kflag;		/* display in 1K^x blocks */
+static int	kflag;		/* display in 1K^x blocks */
 #define	KFLAG_CMDS	(CMD_l | CMD_s)
 #define MFLAG_CMDS	(CMD_l | CMD_s)
 #define GFLAG_CMDS	(CMD_l | CMD_s)
 
-int	hflag;		/* display with humanize_number */
+static int	hflag;		/* display with humanize_number */
 #define HFLAG_CMDS	(CMD_l | CMD_s)
 
-int	pflag;		/* priority was specified */
+static int	pflag;		/* priority was specified */
 #define	PFLAG_CMDS	(CMD_A | CMD_a | CMD_c)
 
-char	*tflag;		/* swap device type (blk, noblk, auto) */
-int	autoflag;	/* 1, if tflag is auto */
+static char	*tflag;		/* swap device type (blk, noblk, auto) */
+static int	autoflag;	/* 1, if tflag is auto */
 #define	TFLAG_CMDS	(CMD_A | CMD_U)
 
-int	fflag;		/* first swap becomes dump */
+static int	fflag;		/* first swap becomes dump */
 #define	FFLAG_CMDS	(CMD_A)
 
-int	oflag;		/* only autoset dump device */
+static int	oflag;		/* only autoset dump device */
 #define	OFLAG_CMDS	(CMD_A)
 
-int	nflag;		/* no execute, just print actions */
+static int	nflag;		/* no execute, just print actions */
 #define	NFLAG_CMDS	(CMD_A | CMD_U)
 
-int	pri;		/* uses 0 as default pri */
+static int	pri;		/* uses 0 as default pri */
 
 static	void change_priority(char *);
 static	int  add_swap(char *, int);
 static	int  delete_swap(char *);
 static	void set_dumpdev(char *);
 static	int get_dumpdev(void);
-static	void do_fstab(int);
+__dead static	void do_fstab(int);
 static	int check_fstab(void);
 static	void do_localdevs(int);
 static	void do_localdisk(const char *, int);
 static	int do_wedgesofdisk(int fd, int);
 static	int do_partitionsofdisk(const char *, int fd, int);
-static	void usage(void);
-static	void swapon_command(int, char **);
+__dead static	void usage(void);
+__dead static	void swapon_command(int, char **);
 #if 0
 static	void swapoff_command(int, char **);
 #endif



CVS commit: src/sbin/swapctl

2009-09-24 Thread Alan Barrett
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