Esempio n. 1
0
static int do_em_all(void)
{
	struct mntent *m;
	FILE *f;
	int err;

	f = setmntent("/etc/fstab", "r");
	if (f == NULL)
		bb_perror_msg_and_die("/etc/fstab");

	err = 0;
	while ((m = getmntent(f)) != NULL) {
		if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0) {
			/* swapon -a should ignore entries with noauto,
			 * but swapoff -a should process them */
			if (applet_name[5] != 'n'
			 || hasmntopt(m, MNTOPT_NOAUTO) == NULL
			) {
				err += swap_enable_disable(m->mnt_fsname);
			}
		}
	}

	if (ENABLE_FEATURE_CLEAN_UP)
		endmntent(f);

	return err;
}
Esempio n. 2
0
extern int swap_on_off_main(int argc, char **argv)
{
	if (applet_name[5] == 'f') { /* "swapoff" */
		whichApp = SWAPOFF_APP;
	}

	if (argc != 2) {
		goto usage_and_exit;
	}
	argc--;
	argv++;

	/* Parse any options */
	while (**argv == '-') {
		while (*++(*argv))
			switch (**argv) {
			case 'a':
				{
					struct stat statBuf;

					if (stat("/etc/fstab", &statBuf) < 0)
						error_msg_and_die("/etc/fstab file missing");
				}
				return do_em_all();
				break;
			default:
				goto usage_and_exit;
			}
	}
	return swap_enable_disable(*argv);

  usage_and_exit:
	show_usage();
}
Esempio n. 3
0
int swap_on_off_main(int argc UNUSED_PARAM, char **argv)
{
	int ret;

	INIT_G();

#if !ENABLE_FEATURE_SWAPON_PRI
	ret = getopt32(argv, "a");
#else
	if (applet_name[5] == 'n')
		opt_complementary = "p+";
	ret = getopt32(argv, (applet_name[5] == 'n') ? "ap:" : "a", &g_flags);

	if (ret & 2) { // -p
		g_flags = SWAP_FLAG_PREFER |
			((g_flags & SWAP_FLAG_PRIO_MASK) << SWAP_FLAG_PRIO_SHIFT);
		ret &= 1;
	}
#endif

	if (ret /* & 1: not needed */) // -a
		return do_em_all();

	argv += optind;
	if (!*argv)
		bb_show_usage();

	/* ret = 0; redundant */
	do {
		ret += swap_enable_disable(*argv);
	} while (*++argv);

	return ret;
}
static void do_em_all()
{
	struct mntent *m;
	FILE *f = setmntent("/etc/fstab", "r");

	if (f == NULL)
		perror_msg_and_die("/etc/fstab");
	while ((m = getmntent(f)) != NULL) {
		if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) {
			swap_enable_disable(m->mnt_fsname);
		}
	}
	endmntent(f);
	exit(EXIT_SUCCESS);
}
Esempio n. 5
0
int swap_on_off_main(int argc, char **argv)
{
	int ret;

	if (argc == 1)
		bb_show_usage();

	ret = bb_getopt_ulflags(argc, argv, "a");
	if (ret & DO_ALL)
		return do_em_all();

	ret = 0;
	while (*++argv)
		ret += swap_enable_disable(*argv);
	return ret;
}
Esempio n. 6
0
int swap_on_off_main(int argc, char **argv)
{
	int ret;

	if (argc == 1)
		bb_show_usage();

	ret = getopt32(argv, "a");
	if (ret)
		return do_em_all();

	/* ret = 0; redundant */
	while (*++argv)
		ret += swap_enable_disable(*argv);
	return ret;
}
Esempio n. 7
0
static int do_em_all(void)
{
	struct mntent *m;
	FILE *f = setmntent("/etc/fstab", "r");
	int err = 0;

	if (f == NULL)
		perror_msg_and_die("/etc/fstab");
	while ((m = getmntent(f)) != NULL) {
		if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) {
			if(swap_enable_disable(m->mnt_fsname) == EXIT_FAILURE)
				err++;
		}
	}
	endmntent(f);
	return err;
}
Esempio n. 8
0
static int do_em_all(void)
{
	struct mntent *m;
	FILE *f;
	int err;

	f = setmntent("/etc/fstab", "r");
	if (f == NULL)
		bb_perror_msg_and_die("/etc/fstab");

	err = 0;
	while ((m = getmntent(f)) != NULL)
		if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0)
			err += swap_enable_disable(m->mnt_fsname);

	endmntent(f);

	return err;
}