swapon.c (227081) | swapon.c (252310) |
---|---|
1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 25 unchanged lines hidden (view full) --- 34 The Regents of the University of California. All rights reserved.\n"; 35#endif /* not lint */ 36 37#ifndef lint 38static char sccsid[] = "@(#)swapon.c 8.1 (Berkeley) 6/5/93"; 39#endif /* not lint */ 40#endif 41#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 25 unchanged lines hidden (view full) --- 34 The Regents of the University of California. All rights reserved.\n"; 35#endif /* not lint */ 36 37#ifndef lint 38static char sccsid[] = "@(#)swapon.c 8.1 (Berkeley) 6/5/93"; 39#endif /* not lint */ 40#endif 41#include <sys/cdefs.h> |
42__FBSDID("$FreeBSD: head/sbin/swapon/swapon.c 227081 2011-11-04 13:36:02Z ed $"); | 42__FBSDID("$FreeBSD: head/sbin/swapon/swapon.c 252310 2013-06-27 18:28:45Z hrs $"); |
43 | 43 |
44#include <sys/stat.h> | |
45#include <sys/param.h> | 44#include <sys/param.h> |
45#include <sys/types.h> 46#include <sys/mdioctl.h> 47#include <sys/stat.h> |
|
46#include <sys/sysctl.h> | 48#include <sys/sysctl.h> |
49#include <sys/wait.h> |
|
47#include <vm/vm_param.h> 48 49#include <err.h> 50#include <errno.h> | 50#include <vm/vm_param.h> 51 52#include <err.h> 53#include <errno.h> |
54#include <fcntl.h> 55#include <fnmatch.h> |
|
51#include <fstab.h> | 56#include <fstab.h> |
57#include <libgen.h> 58#include <libutil.h> 59#include <limits.h> 60#include <paths.h> 61#include <stdarg.h> |
|
52#include <stdio.h> 53#include <stdlib.h> 54#include <string.h> 55#include <unistd.h> | 62#include <stdio.h> 63#include <stdlib.h> 64#include <string.h> 65#include <unistd.h> |
56#include <fcntl.h> 57#include <libutil.h> | |
58 59static void usage(void); | 66 67static void usage(void); |
60static int swap_on_off(char *name, int ignoreebusy); | 68static const char *swap_on_off(char *, int, char *); 69static const char *swap_on_off_gbde(char *, int); 70static const char *swap_on_off_geli(char *, char *, int); 71static const char *swap_on_off_md(char *, char *, int); 72static const char *swap_on_off_sfile(char *, int); |
61static void swaplist(int, int, int); | 73static void swaplist(int, int, int); |
74static int run_cmd(int *, const char *, ...) __printflike(2, 3); |
|
62 63static enum { SWAPON, SWAPOFF, SWAPCTL } orig_prog, which_prog = SWAPCTL; 64 | 75 76static enum { SWAPON, SWAPOFF, SWAPCTL } orig_prog, which_prog = SWAPCTL; 77 |
78static int qflag; 79 |
|
65int 66main(int argc, char **argv) 67{ 68 struct fstab *fsp; | 80int 81main(int argc, char **argv) 82{ 83 struct fstab *fsp; |
84 const char *swfile; |
|
69 char *ptr; 70 int ret; 71 int ch, doall; | 85 char *ptr; 86 int ret; 87 int ch, doall; |
72 int sflag = 0, lflag = 0, hflag = 0, qflag = 0; | 88 int sflag = 0, lflag = 0, late = 0, hflag = 0; |
73 const char *etc_fstab; 74 75 if ((ptr = strrchr(argv[0], '/')) == NULL) 76 ptr = argv[0]; 77 if (strstr(ptr, "swapon")) 78 which_prog = SWAPON; 79 else if (strstr(ptr, "swapoff")) 80 which_prog = SWAPOFF; 81 orig_prog = which_prog; 82 83 doall = 0; 84 etc_fstab = NULL; | 89 const char *etc_fstab; 90 91 if ((ptr = strrchr(argv[0], '/')) == NULL) 92 ptr = argv[0]; 93 if (strstr(ptr, "swapon")) 94 which_prog = SWAPON; 95 else if (strstr(ptr, "swapoff")) 96 which_prog = SWAPOFF; 97 orig_prog = which_prog; 98 99 doall = 0; 100 etc_fstab = NULL; |
85 while ((ch = getopt(argc, argv, "AadghklmqsUF:")) != -1) { | 101 while ((ch = getopt(argc, argv, "AadghklLmqsUF:")) != -1) { |
86 switch(ch) { 87 case 'A': 88 if (which_prog == SWAPCTL) { 89 doall = 1; 90 which_prog = SWAPON; 91 } else { 92 usage(); 93 } --- 17 unchanged lines hidden (view full) --- 111 hflag = 'H'; 112 break; 113 case 'k': 114 hflag = 'K'; 115 break; 116 case 'l': 117 lflag = 1; 118 break; | 102 switch(ch) { 103 case 'A': 104 if (which_prog == SWAPCTL) { 105 doall = 1; 106 which_prog = SWAPON; 107 } else { 108 usage(); 109 } --- 17 unchanged lines hidden (view full) --- 127 hflag = 'H'; 128 break; 129 case 'k': 130 hflag = 'K'; 131 break; 132 case 'l': 133 lflag = 1; 134 break; |
135 case 'L': 136 late = 1; 137 break; |
|
119 case 'm': 120 hflag = 'M'; 121 break; 122 case 'q': 123 if (which_prog == SWAPON || which_prog == SWAPOFF) 124 qflag = 1; 125 break; 126 case 's': --- 13 unchanged lines hidden (view full) --- 140 case '?': 141 default: 142 usage(); 143 } 144 } 145 argv += optind; 146 147 ret = 0; | 138 case 'm': 139 hflag = 'M'; 140 break; 141 case 'q': 142 if (which_prog == SWAPON || which_prog == SWAPOFF) 143 qflag = 1; 144 break; 145 case 's': --- 13 unchanged lines hidden (view full) --- 159 case '?': 160 default: 161 usage(); 162 } 163 } 164 argv += optind; 165 166 ret = 0; |
167 swfile = NULL; |
|
148 if (etc_fstab != NULL) 149 setfstab(etc_fstab); 150 if (which_prog == SWAPON || which_prog == SWAPOFF) { 151 if (doall) { 152 while ((fsp = getfsent()) != NULL) { 153 if (strcmp(fsp->fs_type, FSTAB_SW)) 154 continue; 155 if (strstr(fsp->fs_mntops, "noauto")) 156 continue; | 168 if (etc_fstab != NULL) 169 setfstab(etc_fstab); 170 if (which_prog == SWAPON || which_prog == SWAPOFF) { 171 if (doall) { 172 while ((fsp = getfsent()) != NULL) { 173 if (strcmp(fsp->fs_type, FSTAB_SW)) 174 continue; 175 if (strstr(fsp->fs_mntops, "noauto")) 176 continue; |
157 if (swap_on_off(fsp->fs_spec, 1)) { | 177 if (which_prog != SWAPOFF && 178 strstr(fsp->fs_mntops, "late") && 179 !late) 180 continue; 181 swfile = swap_on_off(fsp->fs_spec, 1, 182 fsp->fs_mntops); 183 if (swfile == NULL) { |
158 ret = 1; | 184 ret = 1; |
159 } else { 160 if (!qflag) { 161 printf("%s: %sing %s as swap device\n", 162 getprogname(), 163 which_prog == SWAPOFF ? "remov" : "add", 164 fsp->fs_spec); 165 } | 185 continue; |
166 } | 186 } |
187 if (!qflag) { 188 printf("%s: %sing %s as swap device\n", 189 getprogname(), 190 (which_prog == SWAPOFF) ? 191 "remov" : "add", swfile); 192 } |
|
167 } 168 } 169 else if (!*argv) 170 usage(); 171 for (; *argv; ++argv) { | 193 } 194 } 195 else if (!*argv) 196 usage(); 197 for (; *argv; ++argv) { |
172 if (swap_on_off(*argv, 0)) { | 198 swfile = swap_on_off(*argv, 0, NULL); 199 if (swfile == NULL) { |
173 ret = 1; | 200 ret = 1; |
174 } else if (orig_prog == SWAPCTL) { | 201 continue; 202 } 203 if (orig_prog == SWAPCTL) { |
175 printf("%s: %sing %s as swap device\n", | 204 printf("%s: %sing %s as swap device\n", |
176 getprogname(), which_prog == SWAPOFF ? "remov" : "add", 177 *argv); | 205 getprogname(), 206 (which_prog == SWAPOFF) ? "remov" : "add", 207 swfile); |
178 } 179 } 180 } else { 181 if (lflag || sflag) 182 swaplist(lflag, sflag, hflag); 183 else 184 usage(); 185 } 186 exit(ret); 187} 188 | 208 } 209 } 210 } else { 211 if (lflag || sflag) 212 swaplist(lflag, sflag, hflag); 213 else 214 usage(); 215 } 216 exit(ret); 217} 218 |
219static const char * 220swap_on_off(char *name, int doingall, char *mntops) 221{ 222 char base[PATH_MAX]; 223 224 /* Swap on vnode-backed md(4) device. */ 225 if (mntops != NULL && 226 (fnmatch(_PATH_DEV MD_NAME "[0-9]*", name, 0) != FNM_NOMATCH || 227 fnmatch(MD_NAME "[0-9]*", name, 0) != FNM_NOMATCH || 228 strncmp(_PATH_DEV MD_NAME, name, 229 sizeof(_PATH_DEV) + sizeof(MD_NAME)) == 0 || 230 strncmp(MD_NAME, name, sizeof(MD_NAME)) == 0)) 231 return (swap_on_off_md(name, mntops, doingall)); 232 233 /* Swap on encrypted device by GEOM_BDE. */ 234 basename_r(name, base); 235 if (fnmatch("*.bde", base, 0) != FNM_NOMATCH) 236 return (swap_on_off_gbde(name, doingall)); 237 238 /* Swap on encrypted device by GEOM_ELI. */ 239 if (fnmatch("*.eli", base, 0) != FNM_NOMATCH) 240 return (swap_on_off_geli(name, mntops, doingall)); 241 242 /* Swap on special file. */ 243 return (swap_on_off_sfile(name, doingall)); 244} 245 246static const char * 247swap_on_off_gbde(char *name, int doingall) 248{ 249 const char *ret; 250 char pass[64 * 2 + 1], bpass[64]; 251 char *devname, *p; 252 int i, fd, error; 253 254 devname = strdup(name); 255 p = strrchr(devname, '.'); 256 if (p == NULL) { 257 warnx("%s: Malformed device name", name); 258 return (NULL); 259 } 260 *p = '\0'; 261 262 fd = -1; 263 switch (which_prog) { 264 case SWAPON: 265 arc4random_buf(bpass, sizeof(bpass)); 266 for (i = 0; i < (int)sizeof(bpass); i++) 267 sprintf(&pass[2 * i], "%02x", bpass[i]); 268 pass[sizeof(pass) - 1] = '\0'; 269 270 error = run_cmd(&fd, "%s init %s -P %s", _PATH_GBDE, 271 devname, pass); 272 if (error) { 273 /* bde device found. Ignore it. */ 274 close(fd); 275 if (!qflag) 276 warnx("%s: Device already in use", name); 277 return (NULL); 278 } 279 close(fd); 280 error = run_cmd(&fd, "%s attach %s -p %s", _PATH_GBDE, 281 devname, pass); 282 if (error) { 283 close(fd); 284 warnx("gbde (attach) error: %s", name); 285 return (NULL); 286 } 287 break; 288 case SWAPOFF: 289 break; 290 default: 291 return (NULL); 292 break; 293 } 294 if (fd != -1) 295 close(fd); 296 ret = swap_on_off_sfile(name, doingall); 297 298 fd = -1; 299 switch (which_prog) { 300 case SWAPOFF: 301 error = run_cmd(&fd, "%s detach %s", _PATH_GBDE, devname); 302 if (error) { 303 /* bde device not found. Ignore it. */ 304 if (!qflag) 305 warnx("%s: Device not found", devname); 306 return (NULL); 307 } 308 break; 309 default: 310 return (NULL); 311 break; 312 } 313 314 if (fd != -1) 315 close(fd); 316 return (ret); 317} 318 319static const char * 320swap_on_off_geli(char *name, char *mntops, int doingall) 321{ 322 const char *ops, *aalgo, *ealgo, *keylen_str, *sectorsize_str; 323 char *devname, *p; 324 char args[4096]; 325 struct stat sb; 326 int fd, error, keylen, sectorsize; 327 u_long ul; 328 329 devname = strdup(name); 330 p = strrchr(devname, '.'); 331 if (p == NULL) { 332 warnx("%s: Malformed device name", name); 333 return (NULL); 334 } 335 *p = '\0'; 336 337 ops = strdup(mntops); 338 339 /* Default parameters for geli(8). */ 340 aalgo = "hmac/sha256"; 341 ealgo = "aes"; 342 keylen = 256; 343 sectorsize = 4096; 344 345 if ((p = strstr(ops, "aalgo=")) != NULL) { 346 aalgo = p + sizeof("aalgo=") - 1; 347 p = strchr(aalgo, ','); 348 if (p != NULL) 349 *p = '\0'; 350 } 351 if ((p = strstr(ops, "ealgo=")) != NULL) { 352 ealgo = p + sizeof("ealgo=") - 1; 353 p = strchr(ealgo, ','); 354 if (p != NULL) 355 *p = '\0'; 356 } 357 if ((p = strstr(ops, "keylen=")) != NULL) { 358 keylen_str = p + sizeof("keylen=") - 1; 359 p = strchr(keylen_str, ','); 360 if (p != NULL) 361 *p = '\0'; 362 errno = 0; 363 ul = strtoul(keylen_str, &p, 10); 364 if (errno == 0) { 365 if (*p != '\0' || ul > INT_MAX) 366 errno = EINVAL; 367 } 368 if (errno) { 369 warn("Invalid keylen: %s", keylen_str); 370 return (NULL); 371 } 372 keylen = (int)ul; 373 } 374 if ((p = strstr(ops, "sectorsize=")) != NULL) { 375 sectorsize_str = p + sizeof("sectorsize=") - 1; 376 p = strchr(sectorsize_str, ','); 377 if (p != NULL) 378 *p = '\0'; 379 errno = 0; 380 ul = strtoul(sectorsize_str, &p, 10); 381 if (errno == 0) { 382 if (*p != '\0' || ul > INT_MAX) 383 errno = EINVAL; 384 } 385 if (errno) { 386 warn("Invalid sectorsize: %s", sectorsize_str); 387 return (NULL); 388 } 389 sectorsize = (int)ul; 390 } 391 snprintf(args, sizeof(args), "-a %s -e %s -l %d -s %d -d", 392 aalgo, ealgo, keylen, sectorsize); 393 args[sizeof(args) - 1] = '\0'; 394 free((void *)ops); 395 396 fd = -1; 397 switch (which_prog) { 398 case SWAPON: 399 error = run_cmd(&fd, "%s onetime %s %s", _PATH_GELI, args, 400 devname); 401 if (error) { 402 /* eli device found. Ignore it. */ 403 close(fd); 404 if (!qflag) 405 warnx("%s: Device already in use " 406 "or invalid parameters", name); 407 return (NULL); 408 } 409 break; 410 case SWAPOFF: 411 if (stat(name, &sb) == -1 && errno == ENOENT) { 412 if (!qflag) 413 warnx("%s: Device not found", name); 414 return (NULL); 415 } 416 break; 417 default: 418 return (NULL); 419 break; 420 } 421 if (fd != -1) 422 close(fd); 423 424 return (swap_on_off_sfile(name, doingall)); 425} 426 427static const char * 428swap_on_off_md(char *name, char *mntops, int doingall) 429{ 430 FILE *sfd; 431 int fd, mdunit, error; 432 const char *ret; 433 char mdpath[PATH_MAX], linebuf[PATH_MAX]; 434 char *p, *vnodefile; 435 size_t linelen; 436 u_long ul; 437 438 fd = -1; 439 sfd = NULL; 440 if (strlen(name) == (sizeof(MD_NAME) - 1)) 441 mdunit = -1; 442 else { 443 errno = 0; 444 ul = strtoul(name + 2, &p, 10); 445 if (errno == 0) { 446 if (*p != '\0' || ul > INT_MAX) 447 errno = EINVAL; 448 } 449 if (errno) { 450 warn("Bad device unit: %s", name); 451 return (NULL); 452 } 453 mdunit = (int)ul; 454 } 455 456 vnodefile = NULL; 457 if ((p = strstr(mntops, "file=")) != NULL) { 458 vnodefile = strdup(p + sizeof("file=") - 1); 459 p = strchr(vnodefile, ','); 460 if (p != NULL) 461 *p = '\0'; 462 } 463 if (vnodefile == NULL) { 464 warnx("file option not found for %s", name); 465 return (NULL); 466 } 467 468 switch (which_prog) { 469 case SWAPON: 470 if (mdunit == -1) { 471 error = run_cmd(&fd, "%s -l -n -f %s", 472 _PATH_MDCONFIG, vnodefile); 473 if (error == 0) { 474 /* md device found. Ignore it. */ 475 close(fd); 476 if (!qflag) 477 warnx("%s: Device already in use", 478 vnodefile); 479 return (NULL); 480 } 481 error = run_cmd(&fd, "%s -a -t vnode -n -f %s", 482 _PATH_MDCONFIG, vnodefile); 483 if (error) { 484 warnx("mdconfig (attach) error: file=%s", 485 vnodefile); 486 return (NULL); 487 } 488 sfd = fdopen(fd, "r"); 489 if (sfd == NULL) { 490 warn("mdconfig (attach) fdopen error"); 491 ret = NULL; 492 goto err; 493 } 494 p = fgetln(sfd, &linelen); 495 if (p == NULL && 496 (linelen < 2 || linelen > sizeof(linebuf))) { 497 warn("mdconfig (attach) unexpected output"); 498 ret = NULL; 499 goto err; 500 } 501 strncpy(linebuf, p, linelen); 502 linebuf[linelen - 1] = '\0'; 503 errno = 0; 504 ul = strtoul(linebuf, &p, 10); 505 if (errno == 0) { 506 if (*p != '\0' || ul > INT_MAX) 507 errno = EINVAL; 508 } 509 if (errno) { 510 warn("mdconfig (attach) unexpected output: %s", 511 linebuf); 512 ret = NULL; 513 goto err; 514 } 515 mdunit = (int)ul; 516 } else { 517 error = run_cmd(&fd, "%s -l -n -f %s -u %d", 518 _PATH_MDCONFIG, vnodefile, mdunit); 519 if (error == 0) { 520 /* md device found. Ignore it. */ 521 close(fd); 522 if (!qflag) 523 warnx("md%d on %s: Device already " 524 "in use", mdunit, vnodefile); 525 return (NULL); 526 } 527 error = run_cmd(NULL, "%s -a -t vnode -u %d -f %s", 528 _PATH_MDCONFIG, mdunit, vnodefile); 529 if (error) { 530 warnx("mdconfig (attach) error: " 531 "md%d on file=%s", mdunit, vnodefile); 532 return (NULL); 533 } 534 } 535 break; 536 case SWAPOFF: 537 if (mdunit == -1) { 538 error = run_cmd(&fd, "%s -l -n -f %s", 539 _PATH_MDCONFIG, vnodefile); 540 if (error) { 541 /* md device not found. Ignore it. */ 542 close(fd); 543 if (!qflag) 544 warnx("md on %s: Device not found", 545 vnodefile); 546 return (NULL); 547 } 548 sfd = fdopen(fd, "r"); 549 if (sfd == NULL) { 550 warn("mdconfig (list) fdopen error"); 551 ret = NULL; 552 goto err; 553 } 554 p = fgetln(sfd, &linelen); 555 if (p == NULL && 556 (linelen < 2 || linelen > sizeof(linebuf) - 1)) { 557 warn("mdconfig (list) unexpected output"); 558 ret = NULL; 559 goto err; 560 } 561 strncpy(linebuf, p, linelen); 562 linebuf[linelen - 1] = '\0'; 563 p = strchr(linebuf, ' '); 564 if (p != NULL) 565 *p = '\0'; 566 errno = 0; 567 ul = strtoul(linebuf, &p, 10); 568 if (errno == 0) { 569 if (*p != '\0' || ul > INT_MAX) 570 errno = EINVAL; 571 } 572 if (errno) { 573 warn("mdconfig (list) unexpected output: %s", 574 linebuf); 575 ret = NULL; 576 goto err; 577 } 578 mdunit = (int)ul; 579 } else { 580 error = run_cmd(&fd, "%s -l -n -f %s -u %d", 581 _PATH_MDCONFIG, vnodefile, mdunit); 582 if (error) { 583 /* md device not found. Ignore it. */ 584 close(fd); 585 if (!qflag) 586 warnx("md%d on %s: Device not found", 587 mdunit, vnodefile); 588 return (NULL); 589 } 590 } 591 break; 592 default: 593 return (NULL); 594 } 595 snprintf(mdpath, sizeof(mdpath), "%s%s%d", _PATH_DEV, 596 MD_NAME, mdunit); 597 mdpath[sizeof(mdpath) - 1] = '\0'; 598 ret = swap_on_off_sfile(mdpath, doingall); 599 600 switch (which_prog) { 601 case SWAPOFF: 602 if (ret != NULL) { 603 error = run_cmd(NULL, "%s -d -u %d", 604 _PATH_MDCONFIG, mdunit); 605 if (error) 606 warn("mdconfig (detach) detach failed: %s%s%d", 607 _PATH_DEV, MD_NAME, mdunit); 608 } 609 break; 610 default: 611 break; 612 } 613err: 614 if (sfd != NULL) 615 fclose(sfd); 616 if (fd != -1) 617 close(fd); 618 return (ret); 619} 620 |
|
189static int | 621static int |
190swap_on_off(char *name, int doingall) | 622run_cmd(int *ofd, const char *cmdline, ...) |
191{ | 623{ |
192 if ((which_prog == SWAPOFF ? swapoff(name) : swapon(name)) == -1) { | 624 va_list ap; 625 char **argv, **argvp, *cmd, *p; 626 int argc, pid, status, rv; 627 int pfd[2], nfd, dup2dn; 628 629 va_start(ap, cmdline); 630 rv = vasprintf(&cmd, cmdline, ap); 631 if (rv == -1) { 632 warn("%s", __func__); 633 return (rv); 634 } 635 va_end(ap); 636 637 for (argc = 1, p = cmd; (p = strchr(p, ' ')) != NULL; p++) 638 argc++; 639 argv = (char **)malloc(sizeof(*argv) * (argc + 1)); 640 for (p = cmd, argvp = argv; (*argvp = strsep(&p, " ")) != NULL;) 641 if (**argvp != '\0' && (++argvp > &argv[argc])) { 642 *argvp = NULL; 643 break; 644 } 645 /* The argv array ends up NULL-terminated here. */ 646#if 0 647 { 648 int i; 649 650 fprintf(stderr, "DEBUG: running:"); 651 /* Should be equivalent to 'cmd' (before strsep, of course). */ 652 for (i = 0; argv[i] != NULL; i++) 653 fprintf(stderr, " %s", argv[i]); 654 fprintf(stderr, "\n"); 655 } 656#endif 657 dup2dn = 1; 658 if (ofd != NULL) { 659 if (pipe(&pfd[0]) == -1) { 660 warn("%s: pipe", __func__); 661 return (-1); 662 } 663 *ofd = pfd[0]; 664 dup2dn = 0; 665 } 666 pid = fork(); 667 switch (pid) { 668 case 0: 669 /* Child process. */ 670 if (ofd != NULL) 671 if (dup2(pfd[1], STDOUT_FILENO) < 0) 672 err(1, "dup2 in %s", __func__); 673 nfd = open(_PATH_DEVNULL, O_RDWR); 674 if (nfd == -1) 675 err(1, "%s: open %s", __func__, _PATH_DEVNULL); 676 if (dup2(nfd, STDIN_FILENO) < 0) 677 err(1, "%s: dup2", __func__); 678 if (dup2dn && dup2(nfd, STDOUT_FILENO) < 0) 679 err(1, "%s: dup2", __func__); 680 if (dup2(nfd, STDERR_FILENO) < 0) 681 err(1, "%s: dup2", __func__); 682 execv(argv[0], argv); 683 warn("exec: %s", argv[0]); 684 _exit(-1); 685 case -1: 686 err(1, "%s: fork", __func__); 687 } 688 free(cmd); 689 free(argv); 690 while (waitpid(pid, &status, 0) != pid) 691 ; 692 return (WEXITSTATUS(status)); 693} 694 695static const char * 696swap_on_off_sfile(char *name, int doingall) 697{ 698 int error; 699 700 switch (which_prog) { 701 case SWAPON: 702 error = swapon(name); 703 break; 704 case SWAPOFF: 705 error = swapoff(name); 706 break; 707 default: 708 error = 0; 709 break; 710 } 711 if (error == -1) { |
193 switch (errno) { 194 case EBUSY: 195 if (!doingall) | 712 switch (errno) { 713 case EBUSY: 714 if (!doingall) |
196 warnx("%s: device already in use", name); | 715 warnx("%s: Device already in use", name); |
197 break; 198 case EINVAL: 199 if (which_prog == SWAPON) 200 warnx("%s: NSWAPDEV limit reached", name); 201 else if (!doingall) 202 warn("%s", name); 203 break; 204 default: 205 warn("%s", name); 206 break; 207 } | 716 break; 717 case EINVAL: 718 if (which_prog == SWAPON) 719 warnx("%s: NSWAPDEV limit reached", name); 720 else if (!doingall) 721 warn("%s", name); 722 break; 723 default: 724 warn("%s", name); 725 break; 726 } |
208 return(1); | 727 return (NULL); |
209 } | 728 } |
210 return(0); | 729 return (name); |
211} 212 213static void 214usage(void) 215{ 216 fprintf(stderr, "usage: %s ", getprogname()); 217 switch(orig_prog) { 218 case SWAPON: 219 case SWAPOFF: | 730} 731 732static void 733usage(void) 734{ 735 fprintf(stderr, "usage: %s ", getprogname()); 736 switch(orig_prog) { 737 case SWAPON: 738 case SWAPOFF: |
220 fprintf(stderr, "[-F fstab] -aq | file ...\n"); | 739 fprintf(stderr, "[-F fstab] -aLq | file ...\n"); |
221 break; 222 case SWAPCTL: 223 fprintf(stderr, "[-AghklmsU] [-a file ... | -d file ...]\n"); 224 break; 225 } 226 exit(1); 227} 228 --- 101 unchanged lines hidden --- | 740 break; 741 case SWAPCTL: 742 fprintf(stderr, "[-AghklmsU] [-a file ... | -d file ...]\n"); 743 break; 744 } 745 exit(1); 746} 747 --- 101 unchanged lines hidden --- |