ubase/swapoff.c

60 lines
965 B
C
Raw Normal View History

2013-08-09 10:42:49 -04:00
/* See LICENSE file for copyright and license details. */
#include <sys/swap.h>
2014-06-30 14:03:41 -04:00
#include <mntent.h>
2013-08-09 10:42:49 -04:00
#include <stdio.h>
2013-10-07 14:11:40 -04:00
#include <stdlib.h>
2013-08-09 10:42:49 -04:00
#include <string.h>
2014-06-30 14:03:41 -04:00
2013-08-09 10:42:49 -04:00
#include "util.h"
static void
usage(void)
{
eprintf("usage: %s -a | device\n", argv0);
2013-08-09 10:42:49 -04:00
}
int
main(int argc, char *argv[])
{
int i;
2014-10-02 18:45:25 -04:00
int ret = 0;
2014-02-08 12:54:04 -05:00
int all = 0;
struct mntent *me;
FILE *fp;
2013-08-09 10:42:49 -04:00
ARGBEGIN {
2014-02-08 12:54:04 -05:00
case 'a':
all = 1;
break;
2013-08-09 10:42:49 -04:00
default:
usage();
} ARGEND;
if ((!all && argc < 1) || (all && argc > 0))
2013-08-09 10:42:49 -04:00
usage();
2014-02-08 12:54:04 -05:00
if (all) {
fp = setmntent("/etc/fstab", "r");
2014-02-15 13:26:01 -05:00
if (!fp)
eprintf("setmntent %s:", "/etc/fstab");
2014-02-08 12:54:04 -05:00
while ((me = getmntent(fp)) != NULL) {
if (strcmp(me->mnt_type, MNTTYPE_SWAP) == 0) {
if (swapoff(me->mnt_fsname) < 0) {
weprintf("swapoff %s:", me->mnt_fsname);
2014-10-02 18:45:25 -04:00
ret = 1;
2014-02-08 12:54:04 -05:00
}
}
}
endmntent(fp);
} else {
for (i = 0; i < argc; i++) {
if (swapoff(argv[i]) < 0) {
weprintf("swapoff %s:", argv[i]);
2014-10-02 18:45:25 -04:00
ret = 1;
2014-02-08 12:54:04 -05:00
}
2013-08-09 10:42:49 -04:00
}
}
return ret;
}