Changeset View
Changeset View
Standalone View
Standalone View
sbin/swapon/swapon.c
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/disk.h> | #include <sys/disk.h> | ||||
#include <sys/disklabel.h> | #include <sys/disklabel.h> | ||||
#include <sys/mdioctl.h> | #include <sys/mdioctl.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/wait.h> | #include <sys/wait.h> | ||||
#include <vm/vm_param.h> | #include <vm/vm_param.h> | ||||
#include <vm/swap_pager.h> | |||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <fnmatch.h> | #include <fnmatch.h> | ||||
#include <fstab.h> | #include <fstab.h> | ||||
#include <libgen.h> | #include <libgen.h> | ||||
#include <libutil.h> | #include <libutil.h> | ||||
Show All 11 Lines | |||||
static const char *swap_on_off_geli(const char *, char *, int); | static const char *swap_on_off_geli(const char *, char *, int); | ||||
static const char *swap_on_off_md(const char *, char *, int); | static const char *swap_on_off_md(const char *, char *, int); | ||||
static const char *swap_on_off_sfile(const char *, int); | static const char *swap_on_off_sfile(const char *, int); | ||||
static void swaplist(int, int, int); | static void swaplist(int, int, int); | ||||
static int run_cmd(int *, const char *, ...) __printflike(2, 3); | static int run_cmd(int *, const char *, ...) __printflike(2, 3); | ||||
static enum { SWAPON, SWAPOFF, SWAPCTL } orig_prog, which_prog = SWAPCTL; | static enum { SWAPON, SWAPOFF, SWAPCTL } orig_prog, which_prog = SWAPCTL; | ||||
static int Eflag, qflag; | static int Eflag, fflag, qflag; | ||||
int | int | ||||
main(int argc, char **argv) | main(int argc, char **argv) | ||||
{ | { | ||||
struct fstab *fsp; | struct fstab *fsp; | ||||
const char *swfile; | const char *swfile; | ||||
char *ptr; | char *ptr; | ||||
int ret, ch, doall; | int ret, ch, doall; | ||||
int sflag, lflag, late, hflag; | int sflag, lflag, late, hflag; | ||||
const char *etc_fstab; | const char *etc_fstab; | ||||
sflag = lflag = late = hflag = 0; | sflag = lflag = late = hflag = 0; | ||||
if ((ptr = strrchr(argv[0], '/')) == NULL) | if ((ptr = strrchr(argv[0], '/')) == NULL) | ||||
ptr = argv[0]; | ptr = argv[0]; | ||||
if (strstr(ptr, "swapon") != NULL) | if (strstr(ptr, "swapon") != NULL) | ||||
which_prog = SWAPON; | which_prog = SWAPON; | ||||
else if (strstr(ptr, "swapoff") != NULL) | else if (strstr(ptr, "swapoff") != NULL) | ||||
which_prog = SWAPOFF; | which_prog = SWAPOFF; | ||||
orig_prog = which_prog; | orig_prog = which_prog; | ||||
doall = 0; | doall = 0; | ||||
etc_fstab = NULL; | etc_fstab = NULL; | ||||
while ((ch = getopt(argc, argv, "AadEghklLmqsUF:")) != -1) { | while ((ch = getopt(argc, argv, "AadEfghklLmqsUF:")) != -1) { | ||||
switch(ch) { | switch(ch) { | ||||
case 'A': | case 'A': | ||||
if (which_prog == SWAPCTL) { | if (which_prog == SWAPCTL) { | ||||
doall = 1; | doall = 1; | ||||
which_prog = SWAPON; | which_prog = SWAPON; | ||||
} else | } else | ||||
usage(); | usage(); | ||||
break; | break; | ||||
Show All 10 Lines | case 'd': | ||||
usage(); | usage(); | ||||
break; | break; | ||||
case 'E': | case 'E': | ||||
if (which_prog == SWAPON) | if (which_prog == SWAPON) | ||||
Eflag = 2; | Eflag = 2; | ||||
else | else | ||||
usage(); | usage(); | ||||
break; | break; | ||||
case 'f': | |||||
if (which_prog == SWAPOFF) | |||||
fflag = 1; | |||||
else | |||||
usage(); | |||||
break; | |||||
case 'g': | case 'g': | ||||
hflag = 'G'; | hflag = 'G'; | ||||
break; | break; | ||||
case 'h': | case 'h': | ||||
hflag = 'H'; | hflag = 'H'; | ||||
break; | break; | ||||
case 'k': | case 'k': | ||||
hflag = 'K'; | hflag = 'K'; | ||||
▲ Show 20 Lines • Show All 638 Lines • ▼ Show 20 Lines | swapon_trim(const char *name) | ||||
*/ | */ | ||||
close(fd); | close(fd); | ||||
return (error); | return (error); | ||||
} | } | ||||
static const char * | static const char * | ||||
swap_on_off_sfile(const char *name, int doingall) | swap_on_off_sfile(const char *name, int doingall) | ||||
{ | { | ||||
struct swapoff_new_args sa; | |||||
int error; | int error; | ||||
if (which_prog == SWAPON) | if (which_prog == SWAPON) | ||||
error = Eflag ? swapon_trim(name) : swapon(name); | error = Eflag ? swapon_trim(name) : swapon(name); | ||||
else /* SWAPOFF */ | else { /* SWAPOFF */ | ||||
error = swapoff(name); | bzero(&sa, sizeof(sa)); | ||||
sa.name = name; | |||||
if (fflag) | |||||
sa.flags |= SWAPOFF_FORCE; | |||||
error = swapoff((const char *)&sa); | |||||
} | |||||
markj: Doesn't it need to be `swapoff(&sa)`? | |||||
if (error == -1) { | if (error == -1) { | ||||
switch (errno) { | switch (errno) { | ||||
case EBUSY: | case EBUSY: | ||||
if (doingall == 0) | if (doingall == 0) | ||||
warnx("%s: Device already in use", name); | warnx("%s: Device already in use", name); | ||||
break; | break; | ||||
case EINVAL: | case EINVAL: | ||||
Show All 16 Lines | |||||
{ | { | ||||
fprintf(stderr, "usage: %s ", getprogname()); | fprintf(stderr, "usage: %s ", getprogname()); | ||||
switch(orig_prog) { | switch(orig_prog) { | ||||
case SWAPON: | case SWAPON: | ||||
fprintf(stderr, "[-F fstab] -aLq | [-E] file ...\n"); | fprintf(stderr, "[-F fstab] -aLq | [-E] file ...\n"); | ||||
break; | break; | ||||
case SWAPOFF: | case SWAPOFF: | ||||
fprintf(stderr, "[-F fstab] -aLq | file ...\n"); | fprintf(stderr, "[-F fstab] -afLq | file ...\n"); | ||||
break; | break; | ||||
case SWAPCTL: | case SWAPCTL: | ||||
fprintf(stderr, "[-AghklmsU] [-a file ... | -d file ...]\n"); | fprintf(stderr, "[-AghklmsU] [-a file ... | -d file ...]\n"); | ||||
break; | break; | ||||
} | } | ||||
exit(1); | exit(1); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines |
Doesn't it need to be swapoff(&sa)?