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 unified 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,17 +1,17 @@ @@ -1,17 +1,17 @@
1/* $NetBSD: swapctl.c,v 1.39 2013/01/01 19:01:10 dsl Exp $ */ 1/* $NetBSD: swapctl.c,v 1.40 2015/10/11 23:58:16 mrg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, 1997, 1999 Matthew R. Green 4 * Copyright (c) 1996, 1997, 1999, 2015 Matthew R. Green
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@@ -54,27 +54,27 @@ @@ -54,27 +54,27 @@
54 * -p <pri> use this priority 54 * -p <pri> use this priority
55 * -c change priority 55 * -c change priority
56 * 56 *
57 * or, if invoked as "swapon" (compatibility mode): 57 * or, if invoked as "swapon" (compatibility mode):
58 * 58 *
59 * -a all devices listed as `sw' in /etc/fstab 59 * -a all devices listed as `sw' in /etc/fstab
60 * -t same as -t above (feature not present in old 60 * -t same as -t above (feature not present in old
61 * swapon(8) command) 61 * swapon(8) command)
62 * <dev> add this device 62 * <dev> add this device
63 */ 63 */
64#include <sys/cdefs.h> 64#include <sys/cdefs.h>
65 65
66#ifndef lint 66#ifndef lint
67__RCSID("$NetBSD: swapctl.c,v 1.39 2013/01/01 19:01:10 dsl Exp $"); 67__RCSID("$NetBSD: swapctl.c,v 1.40 2015/10/11 23:58:16 mrg Exp $");
68#endif 68#endif
69 69
70 70
71#include <sys/param.h> 71#include <sys/param.h>
72#include <sys/ioctl.h> 72#include <sys/ioctl.h>
73#include <sys/stat.h> 73#include <sys/stat.h>
74#include <sys/swap.h> 74#include <sys/swap.h>
75#include <sys/sysctl.h> 75#include <sys/sysctl.h>
76#include <sys/disk.h> 76#include <sys/disk.h>
77#include <sys/disklabel.h> 77#include <sys/disklabel.h>
78 78
79#include <unistd.h> 79#include <unistd.h>
80#include <err.h> 80#include <err.h>
@@ -141,27 +141,27 @@ static int fflag; /* first swap becomes @@ -141,27 +141,27 @@ static int fflag; /* first swap becomes
141#define FFLAG_CMDS (CMD_A) 141#define FFLAG_CMDS (CMD_A)
142 142
143static int oflag; /* only autoset dump device */ 143static int oflag; /* only autoset dump device */
144#define OFLAG_CMDS (CMD_A) 144#define OFLAG_CMDS (CMD_A)
145 145
146static int nflag; /* no execute, just print actions */ 146static int nflag; /* no execute, just print actions */
147#define NFLAG_CMDS (CMD_A | CMD_U) 147#define NFLAG_CMDS (CMD_A | CMD_U)
148 148
149static int pri; /* uses 0 as default pri */ 149static int pri; /* uses 0 as default pri */
150 150
151static void change_priority(char *); 151static void change_priority(char *);
152static int add_swap(char *, int); 152static int add_swap(char *, int);
153static int delete_swap(char *); 153static int delete_swap(char *);
154static void set_dumpdev1(char *); 154static int set_dumpdev1(char *);
155static void set_dumpdev(char *); 155static void set_dumpdev(char *);
156static int get_dumpdev(void); 156static int get_dumpdev(void);
157__dead static void do_fstab(int); 157__dead static void do_fstab(int);
158static int check_fstab(void); 158static int check_fstab(void);
159static void do_localdevs(int); 159static void do_localdevs(int);
160static void do_localdisk(const char *, int); 160static void do_localdisk(const char *, int);
161static int do_wedgesofdisk(int fd, int); 161static int do_wedgesofdisk(int fd, int);
162static int do_partitionsofdisk(const char *, int fd, int); 162static int do_partitionsofdisk(const char *, int fd, int);
163__dead static void usage(void); 163__dead static void usage(void);
164__dead static void swapon_command(int, char **); 164__dead static void swapon_command(int, char **);
165#if 0 165#if 0
166static void swapoff_command(int, char **); 166static void swapoff_command(int, char **);
167#endif 167#endif
@@ -465,81 +465,89 @@ add_swap(char *path, int priority) @@ -465,81 +465,89 @@ add_swap(char *path, int priority)
465 if (fflag || oflag) { 465 if (fflag || oflag) {
466 set_dumpdev1(spec); 466 set_dumpdev1(spec);
467 if (oflag) 467 if (oflag)
468 exit(0); 468 exit(0);
469 else 469 else
470 fflag = 0; 470 fflag = 0;
471 } 471 }
472 472
473 if (nflag) 473 if (nflag)
474 return 1; 474 return 1;
475 475
476 if (swapctl(SWAP_ON, spec, priority) < 0) { 476 if (swapctl(SWAP_ON, spec, priority) < 0) {
477oops: 477oops:
478 err(1, "%s", path); 478 warn("%s", path);
 479 return 0;
479 } 480 }
480 return (1); 481 return 1;
481} 482}
482 483
483/* 484/*
484 * delete_swap: remove the pathname to the list of swap devices. 485 * delete_swap: remove the pathname to the list of swap devices.
485 */ 486 */
486static int 487static int
487delete_swap(char *path) 488delete_swap(char *path)
488{ 489{
489 char buf[MAXPATHLEN]; 490 char buf[MAXPATHLEN];
490 char *spec; 491 char *spec;
491 492
492 if (getfsspecname(buf, sizeof(buf), path) == NULL) 493 if (getfsspecname(buf, sizeof(buf), path) == NULL) {
493 err(1, "%s", path); 494 warn("%s", path);
 495 return 0;
 496 }
494 spec = buf; 497 spec = buf;
495 498
496 if (nflag) 499 if (nflag)
497 return 1; 500 return 1;
498 501
499 if (swapctl(SWAP_OFF, spec, pri) < 0)  502 if (swapctl(SWAP_OFF, spec, pri) < 0) {
500 err(1, "%s", path); 503 warn("%s", path);
501 return (1); 504 return 0;
 505 }
 506 return 1;
502} 507}
503 508
504static void 509static int
505set_dumpdev1(char *spec) 510set_dumpdev1(char *spec)
506{ 511{
507 int rv = 0; 512 int rv = 0;
508 513
509 if (!nflag) { 514 if (!nflag) {
510 if (strcmp(spec, "none") == 0)  515 if (strcmp(spec, "none") == 0)
511 rv = swapctl(SWAP_DUMPOFF, NULL, 0); 516 rv = swapctl(SWAP_DUMPOFF, NULL, 0);
512 else 517 else
513 rv = swapctl(SWAP_DUMPDEV, spec, 0); 518 rv = swapctl(SWAP_DUMPDEV, spec, 0);
514 } 519 }
515 520
516 if (rv == -1) 521 if (rv == -1)
517 err(1, "could not set dump device to %s", spec); 522 warn("could not set dump device to %s", spec);
518 else 523 else
519 printf("%s: setting dump device to %s\n", getprogname(), spec); 524 printf("%s: setting dump device to %s\n", getprogname(), spec);
 525
 526 return rv == -1 ? 0 : 1;
520} 527}
521 528
522static void 529static void
523set_dumpdev(char *path) 530set_dumpdev(char *path)
524{ 531{
525 char buf[MAXPATHLEN]; 532 char buf[MAXPATHLEN];
526 char *spec; 533 char *spec;
527 534
528 if (getfsspecname(buf, sizeof(buf), path) == NULL) 535 if (getfsspecname(buf, sizeof(buf), path) == NULL)
529 err(1, "%s", path); 536 err(1, "%s", path);
530 spec = buf; 537 spec = buf;
531 538
532 return set_dumpdev1(spec); 539 if (! set_dumpdev1(spec))
 540 exit(1);
533} 541}
534 542
535static int 543static int
536get_dumpdev(void) 544get_dumpdev(void)
537{ 545{
538 dev_t dev; 546 dev_t dev;
539 char *name; 547 char *name;
540 548
541 if (swapctl(SWAP_GETDUMPDEV, &dev, 0) == -1) { 549 if (swapctl(SWAP_GETDUMPDEV, &dev, 0) == -1) {
542 warn("could not get dump device"); 550 warn("could not get dump device");
543 return 0; 551 return 0;
544 } else if (dev == NODEV) { 552 } else if (dev == NODEV) {
545 printf("no dump device set\n"); 553 printf("no dump device set\n");