Sun Oct 11 23:58:16 2015 UTC ()
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.


(mrg)
diff -r1.39 -r1.40 src/sbin/swapctl/swapctl.c

cvs diff -r1.39 -r1.40 src/sbin/swapctl/swapctl.c (expand / switch to context diff)
--- src/sbin/swapctl/swapctl.c 2013/01/01 19:01:10 1.39
+++ src/sbin/swapctl/swapctl.c 2015/10/11 23:58:16 1.40
@@ -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 <sys/cdefs.h>
 
 #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	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 @@
 
 	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 @@
 	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 @@
 	}
 
 	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 @@
 		err(1, "%s", path);
 	spec = buf;
 
-	return set_dumpdev1(spec);
+	if (! set_dumpdev1(spec))
+		exit(1);
 }
 
 static int