Esempio n. 1
0
static int
do_swapon(const char *orig_special, int prio, int canonic) {
	int status;
	const char *special = orig_special;
	int flags = 0;

	if (verbose)
		printf(_("%s on %s\n"), progname, orig_special);

	if (!canonic) {
		special = fsprobe_get_devname_by_spec(orig_special);
		if (!special)
			return cannot_find(orig_special);
	}

	if (swapon_checks(special))
		return -1;

#ifdef SWAP_FLAG_PREFER
	if (prio >= 0) {
		if (prio > SWAP_FLAG_PRIO_MASK)
			prio = SWAP_FLAG_PRIO_MASK;
		flags = SWAP_FLAG_PREFER
			| ((prio & SWAP_FLAG_PRIO_MASK)
			   << SWAP_FLAG_PRIO_SHIFT);
	}
#endif
	status = swapon(special, flags);
	if (status < 0)
		warn(_("%s: swapon failed"), orig_special);

	return status;
}
Esempio n. 2
0
static int swap_enable_disable(const char *device)
{
	int status;
	struct stat st;

	if (stat(device, &st) < 0) {
		bb_perror_msg_and_die("cannot stat %s", device);
	}

	/* test for holes */
	if (S_ISREG(st.st_mode)) {
		if (st.st_blocks * 512 < st.st_size) {
			bb_error_msg_and_die("swap file has holes");
		}
	}

	if (whichApp == SWAPON_APP)
		status = swapon(device, 0);
	else
		status = swapoff(device);

	if (status != 0) {
		bb_perror_msg("%s", device);
		return EXIT_FAILURE;
	}
	return EXIT_SUCCESS;
}
Esempio n. 3
0
static int swap_enable_disable(char *device)
{
	int status;
	struct stat st;

	resolve_mount_spec(&device);
	xstat(device, &st);

#if ENABLE_DESKTOP
	/* test for holes */
	if (S_ISREG(st.st_mode))
		if (st.st_blocks * (off_t)512 < st.st_size)
			bb_error_msg("warning: swap file has holes");
#endif

	if (applet_name[5] == 'n')
		status = swapon(device, g_flags);
	else
		status = swapoff(device);

	if (status != 0) {
		bb_simple_perror_msg(device);
		return 1;
	}

	return 0;
}
Esempio n. 4
0
static const char *
swap_on_off_sfile(const char *name, int doingall)
{
	int error;

	if (which_prog == SWAPON)
		error = swapon(name);
	else /* SWAPOFF */
		error = swapoff(name);

	if (error == -1) {
		switch (errno) {
		case EBUSY:
			if (doingall == 0)
				warnx("%s: Device already in use", name);
			break;
		case EINVAL:
			if (which_prog == SWAPON)
				warnx("%s: NSWAPDEV limit reached", name);
			else if (doingall == 0)
				warn("%s", name);
			break;
		default:
			warn("%s", name);
			break;
		}
		return (NULL);
	}
	return (name);
}
Esempio n. 5
0
int swapon_main(int argc, char *argv[])
{
   
	if( argc != 2 ) {
		printf("swapon dev_path\n");
		return -1;
	}

	fprintf(stderr, "swapon %s\n ", argv[1]);
	return swapon(argv[1], 0);
}
static void swap_enable_disable(char *device)
{
	int status;

	if (whichApp == SWAPON_APP)
		status = swapon(device, 0);
	else
		status = swapoff(device);

	if (status != 0)
		perror_msg_and_die(applet_name);
}
Esempio n. 7
0
void syscall_helper(int argc, char **argv) {
    (void) argc;

    if (strcmp(argv[2], "mount") == 0) {
        int rv = mount(NULL, NULL, NULL, 0, NULL);
        (void) rv;
        printf("\nUGLY: mount syscall permitted.\n");
    }
    else if (strcmp(argv[2], "umount2") == 0) {
        umount2(NULL, 0);
        printf("\nUGLY: umount2 syscall permitted.\n");
    }
    else if (strcmp(argv[2], "ptrace") == 0) {
        ptrace(0, 0, NULL, NULL);
        printf("\nUGLY: ptrace syscall permitted.\n");
    }
    else if (strcmp(argv[2], "swapon") == 0) {
        swapon(NULL, 0);
        printf("\nUGLY: swapon syscall permitted.\n");
    }
    else if (strcmp(argv[2], "swapoff") == 0) {
        swapoff(NULL);
        printf("\nUGLY: swapoff syscall permitted.\n");
    }
    else if (strcmp(argv[2], "init_module") == 0) {
        init_module(NULL, 0, NULL);
        printf("\nUGLY: init_module syscall permitted.\n");
    }
    else if (strcmp(argv[2], "delete_module") == 0) {
        delete_module(NULL, 0);
        printf("\nUGLY: delete_module syscall permitted.\n");
    }
    else if (strcmp(argv[2], "chroot") == 0) {
        int rv = chroot("/blablabla-57281292");
        (void) rv;
        printf("\nUGLY: chroot syscall permitted.\n");
    }
    else if (strcmp(argv[2], "pivot_root") == 0) {
        pivot_root(NULL, NULL);
        printf("\nUGLY: pivot_root syscall permitted.\n");
    }
#if defined(__i386__) || defined(__x86_64__)
    else if (strcmp(argv[2], "iopl") == 0) {
        iopl(0L);
        printf("\nUGLY: iopl syscall permitted.\n");
    }
    else if (strcmp(argv[2], "ioperm") == 0) {
        ioperm(0, 0, 0);
        printf("\nUGLY: ioperm syscall permitted.\n");
    }
#endif
    exit(0);
}
Esempio n. 8
0
File: swap.c Progetto: 5kg/systemtap
int main()
{
  swapon("foobar_swap", 0);
  //staptest// swapon ("foobar_swap", 0) =

  swapon("foobar_swap", ((1 << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK) | SWAP_FLAG_PREFER);
  //staptest// swapon ("foobar_swap", 32769) =

  swapon("foobar_swap", ((7 << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK) | SWAP_FLAG_PREFER);
  //staptest// swapon ("foobar_swap", 32775) =

  swapon(0, 0);
  //staptest// swapon ( *(null), 0) =

  swapoff("foobar_swap");
  //staptest// swapoff ("foobar_swap") =

  swapoff(0);
  //staptest// swapoff ( *(null)) =

  return 0;
}
Esempio n. 9
0
static PyObject * doSwapon (PyObject * s, PyObject * args) {
    char * path;

    if (!PyArg_ParseTuple(args, "s", &path)) return NULL;

    if (swapon (path, 0)) {
	PyErr_SetFromErrno(PyExc_SystemError);
	return NULL;
    }
    
    Py_INCREF(Py_None);
    return Py_None;
}
Esempio n. 10
0
static int swap_enable_disable(const char *device)
{
	int status;

	if (whichApp == SWAPON_APP)
		status = swapon(device, 0);
	else
		status = swapoff(device);

	if (status != 0) {
		perror_msg("%s", device);
		return EXIT_FAILURE;
	}
	return EXIT_SUCCESS;
}
Esempio n. 11
0
int swapon_main(int argc, char **argv)
{
    int err = 0;
    int flags = 0;
    int prio;

    opterr = 0;
    do {
        int c = getopt(argc, argv, "hp:");
        if (c == -1)
            break;

        switch (c) {
            case 'p':
                if (optarg != NULL)
                    prio = parse_prio(optarg);
                else
                    prio = -1;

                if (prio < 0) {
                    usage(argv[0]);
                    return -EINVAL;
                }
                flags |= SWAP_FLAG_PREFER;
                flags |= (prio << SWAP_FLAG_PRIO_SHIFT) & SWAP_FLAG_PRIO_MASK;
                break;
            case 'h':
                usage(argv[0]);
                return 0;
            case '?':
                fprintf(stderr, "unknown option: %c\n", optopt);
                return -EINVAL;
        }
    } while (1);

    if (optind != argc - 1) {
        usage(argv[0]);
        return -EINVAL;
    }

    err = swapon(argv[argc - 1], flags);
    if (err) {
        fprintf(stderr, "swapon failed for %s\n", argv[argc - 1]);
    }

    return err;
}
Esempio n. 12
0
static int
swap_on_off(char *name, int doingall, int trim)
{
	if (which_prog == SWAPON && trim){
		char sysctl_name[64];
		int trim_enabled = 0;
		size_t olen = sizeof(trim_enabled);
		char *dev_name = strdup(name);
		dev_name = strtok(dev_name + strlen("/dev/da"),"s");
		sprintf(sysctl_name, "kern.cam.da.%s.trim_enabled", dev_name);
		sysctlbyname(sysctl_name, &trim_enabled, &olen, NULL, 0);
		if(errno == ENOENT) {
			printf("Device:%s does not support the TRIM command\n",
			    name);
			usage();
		}
		if(!trim_enabled) {
			printf("Erase device option selected, but sysctl (%s) "
			    "is not enabled\n",sysctl_name);
			usage();
		}

		trim_volume(name);

	}
	if ((which_prog == SWAPOFF ? swapoff(name) : swapon(name)) == -1) {
		switch(errno) {
		case EBUSY:
			if (!doingall)
				warnx("%s: device already in use", name);
			break;
		case EINVAL:
			if (which_prog == SWAPON)
				warnx("%s: NSWAPDEV limit reached", name);
			else if (!doingall)
				warn("%s", name);
			break;
		default:
			warn("%s", name);
			break;
		}
		return(1);
	}
	return(0);
}
Esempio n. 13
0
static int
swap (const char *special)
{
  int status;

  if (verbose)
    printf("%s on device %s\n", program_name, special);

  if (streq (program_name, "swapon"))
    status = swapon (special,0);
  else
    status = swapoff (special);

  if (status < 0)
    fprintf (stderr, "%s: %s: %s\n", program_name, special, strerror (errno));

  return status;
}
Esempio n. 14
0
static int
swap (const char *special)
{
  int status;

#ifdef HAVE_SWAPOFF
  if (streq (progname, "swapon"))
#endif
    status = swapon (special);
#ifdef HAVE_SWAPOFF
  else
    status = swapoff (special);
#endif

  if (status < 0)
    fprintf (stderr, "%s: %s: %s\n", progname, special, strerror (errno));

  return status;
}
Esempio n. 15
0
static int
swap_on_off(char *name, int doingall)
{
	if ((which_prog == SWAPOFF ? swapoff(name) : swapon(name)) == -1) {
		switch (errno) {
		case EBUSY:
			if (!doingall)
				warnx("%s: device already in use", name);
			break;
		case EINVAL:
			if (which_prog == SWAPON)
				warnx("%s: NSWAPDEV limit reached", name);
			else if (!doingall)
				warn("%s", name);
			break;
		default:
			warn("%s", name);
			break;
		}
		return(1);
	}
	return(0);
}
Esempio n. 16
0
static ssize_t initstate_store(struct device *dev,
				struct device_attribute *attr, const char *buf,
				size_t len)
{
	int ret;
	unsigned long do_init;
	struct zram *zram = dev_to_zram(dev);

	if (zram->init_done) {
		pr_info("the device is initialized device\n");
		return -EBUSY;
	}

	ret = strict_strtoul(buf, 10, &do_init);
	if (ret)
		return ret;
	if (!do_init)
		return -EINVAL;

	zram_init_device(zram);
	swapon("/dev/block/zram0", 0);
	return len;
}
Esempio n. 17
0
static int swap_enable_disable(const char *device)
{
	int status;
	struct stat st;

	xstat(device, &st);

	/* test for holes */
	if (S_ISREG(st.st_mode))
		if (st.st_blocks * 512 < st.st_size)
			bb_error_msg_and_die("swap file has holes");

	if (bb_applet_name[5] == 'n')
		status = swapon(device, 0);
	else
		status = swapoff(device);

	if (status != 0) {
		bb_perror_msg("%s", device);
		return 1;
	}

	return 0;
}
Esempio n. 18
0
/* This must be called after mount_all, because the mkswap command needs to be
 * available.
 */
int fs_mgr_swapon_all(struct fstab *fstab)
{
    int i = 0;
    int flags = 0;
    int err = 0;
    int ret = 0;
    int status;
    char *mkswap_argv[2] = {
        MKSWAP_BIN,
        NULL
    };

    if (!fstab) {
        return -1;
    }

    for (i = 0; i < fstab->num_entries; i++) {
        /* Skip non-swap entries */
        if (strcmp(fstab->recs[i].fs_type, "swap")) {
            continue;
        }

        if (fstab->recs[i].zram_size > 0) {
            /* A zram_size was specified, so we need to configure the
             * device.  There is no point in having multiple zram devices
             * on a system (all the memory comes from the same pool) so
             * we can assume the device number is 0.
             */
            FILE *zram_fp;

            zram_fp = fopen(ZRAM_CONF_DEV, "r+");
            if (zram_fp == NULL) {
                ERROR("Unable to open zram conf device %s\n", ZRAM_CONF_DEV);
                ret = -1;
                continue;
            }
            fprintf(zram_fp, "%d\n", fstab->recs[i].zram_size);
            fclose(zram_fp);
        }

        if (fstab->recs[i].fs_mgr_flags & MF_WAIT) {
            wait_for_file(fstab->recs[i].blk_device, WAIT_TIMEOUT);
        }

        /* Initialize the swap area */
        mkswap_argv[1] = fstab->recs[i].blk_device;
        err = android_fork_execvp_ext(ARRAY_SIZE(mkswap_argv), mkswap_argv,
                                      &status, true, LOG_KLOG, false, NULL);
        if (err) {
            ERROR("mkswap failed for %s\n", fstab->recs[i].blk_device);
            ret = -1;
            continue;
        }

        /* If -1, then no priority was specified in fstab, so don't set
         * SWAP_FLAG_PREFER or encode the priority */
        if (fstab->recs[i].swap_prio >= 0) {
            flags = (fstab->recs[i].swap_prio << SWAP_FLAG_PRIO_SHIFT) &
                    SWAP_FLAG_PRIO_MASK;
            flags |= SWAP_FLAG_PREFER;
        } else {
            flags = 0;
        }
        err = swapon(fstab->recs[i].blk_device, flags);
        if (err) {
            ERROR("swapon failed for %s\n", fstab->recs[i].blk_device);
            ret = -1;
        }
    }

    return ret;
}
Esempio n. 19
0
int main(int argc, char **argv)
{	int	x = 0;
	char	*args[10];

	setuid(2);

	signal(SIGCHLD, sigchld);
	do_signals();

	x += getpid();
	x += getppid();
	x += getuid();
	x += getgid();
	x += setsid();
	x += seteuid();
	x += setegid();
	lseek(0, 0, -1);
	kill(0, 0);
	signal(99, 0);
	signal(SIGINT, int_handler);
	signal(SIGSEGV, segv_handler);
//	*(int *) 0 = 0;
	pipe(0);
	munmap(0, 0);
	mincore(0, 0);
	shmget(0);
	shmat(0);

	line = __LINE__;
	poll(-1, 0, 0);
	signal(SIGSEGV, SIG_IGN);
//	ppoll(-1, -1, -1, 0);
	signal(SIGSEGV, SIG_DFL);
	sched_yield();
	readv(-1, 0, 0, 0);
	writev(-1, 0, 0, 0);
	msync(0, 0, 0);
	fsync(-1);
	fdatasync(-1);
	semget(0, 0, 0);
	semctl(0, 0, 0);
	uselib(NULL);
	pivot_root(0, 0);
	personality(-1);
	setfsuid(-1);
	flock(-1, 0);
	shmdt(0, 0, 0);
	times(0);
	mremap(0, 0, 0, 0, 0);
	madvise(0, 0, 0);
	fchown(-1, 0, 0);
	lchown(0, 0, 0);
	setreuid();
	setregid();
	link("/nonexistant", "/also-nonexistant");

	do_slow();

	symlink("/nothing", "/");
	rename("/", "/");
	mkdir("/junk/stuff////0", 0777);
	geteuid();
	getsid();
	getpgid();
	getresuid();
	getresgid();
	getpgid();
	ptrace(-1, 0, 0, 0);
	semop(0, 0, 0);
	capget(0, 0);

	line = __LINE__;
	gettimeofday(0, 0);
	settimeofday(0, 0);
	dup(-1);
	dup2(-1, -1);
	shmctl(0, 0, 0, 0);
	execve("/bin/nothing", "/bin/nothing", 0);
	alarm(9999);
	bind(0, 0, 0);
	socket(0, 0, 0);
	accept(0, 0, 0);
	listen(0);
	shutdown(0);
	getsockname(0, 0, 0);
	getpeername(0, 0, 0);
	truncate(0, 0);
	ftruncate(0, 0);
	line = __LINE__;
	if (vfork() == 0)
		exit(0);
	line = __LINE__;
	x = opendir("/", 0, 0);
	line = __LINE__;
	readdir(x, 0, 0);
	line = __LINE__;
	closedir(x);
	line = __LINE__;
	chroot("/");
	line = __LINE__;
	sigaction(0, 0, 0);
	line = __LINE__;
	sigprocmask(0, 0, 0);
	x += open("/nothing", 0);
	x += chdir("/nothing");
	x += mknod("/nothing/nothing", 0);
	x += ioctl();
	execve("/nothing", NULL, NULL);
	line = __LINE__;
	x += close(-2);
	line = __LINE__;
	if (fork() == 0)
		exit(0);
	line = __LINE__;
	clone(clone_func, 0, 0, 0);
	line = __LINE__;
	brk(0);
	sbrk(0);
	line = __LINE__;
	mmap(0, 0, 0, 0, 0);
	line = __LINE__;
	uname(0);
	line = __LINE__;
	getcwd(0, 0);
	line = __LINE__;
	iopl(3);
	ioperm(0, 0, 0);
	mount(0, 0, 0, 0, 0);
	umount(0, 0);
	umount(0, 0, 0);
	swapon(0, 0);
	swapoff(0);
	sethostname(0);
	line = __LINE__;
	time(NULL);
	unlink("/nothing");
	line = __LINE__;
	rmdir("/nothing");
	chmod(0, 0);
	line = __LINE__;
# if defined(__i386) || defined(__amd64)
	modify_ldt(0);
# endif

	stat("/doing-nice", 0);
	nice(0);

	args[0] = "/bin/df";
	args[1] = "-l";
	args[2] = NULL;
	close(1);
	open("/dev/null", O_WRONLY);
	/***********************************************/
	/*   Some  syscalls  arent  available  direct  */
	/*   from  libc,  so get them here. We mostly  */
	/*   care  about  the  ones which have caused  */
	/*   implementation   difficulty  and  kernel  */
	/*   crashes - eventually we can be complete.  */
	/***********************************************/
	line = __LINE__;
	open("/system-dependent-syscalls-follow", 0);
	line = __LINE__;
	if (fork() == 0)
		exit(0);

	{int status;
	while (wait(&status) >= 0)
		;
	}

	sigaltstack(0, 0);

	/*vm86(0, 0);*/

	/***********************************************/
	/*   Some syscalls arent directly accessible,  */
	/*   e.g. legacy.			       */
	/***********************************************/
#if defined(__x86_64__)
	trace(__LINE__, "x64 syscalls");
	syscall(174, 0, 0, 0); // create_module
	syscall(176, 0, 0, 0); // delete_module
	syscall(178, 0, 0, 0); // query_module
#else
	trace(__LINE__, "x32 syscalls");
	syscall(0, 0, 0, 0); // restart_syscall
	syscall(34, 0, 0, 0); // nice
	syscall(59, 0, 0, 0); // oldolduname	
	syscall(109, 0, 0, 0); // olduname	
	if (fork() == 0)
		syscall(1, 0, 0, 0); // exit
#endif
	line = __LINE__;
	execve("/bin/df", args, NULL);

	fprintf(stderr, "Error: should not get here -- %s\n", strerror(errno));

	exit(1);
}
Esempio n. 20
0
static int
do_swapon(const char *orig_special, int prio) {
    int status;
    struct stat st;
    const char *special;

    if (verbose)
        printf(_("%s on %s\n"), progname, orig_special);

    special = mount_get_devname(orig_special);
    if (!special) {
        fprintf(stderr, _("%s: cannot find the device for %s\n"),
                progname, orig_special);
        return -1;
    }

    if (stat(special, &st) < 0) {
        int errsv = errno;
        fprintf(stderr, _("%s: cannot stat %s: %s\n"),
                progname, special, strerror(errsv));
        return -1;
    }

    /* people generally dislike this warning - now it is printed
       only when `verbose' is set */
    if (verbose) {
        int permMask = (S_ISBLK(st.st_mode) ? 07007 : 07077);

        if ((st.st_mode & permMask) != 0) {
            fprintf(stderr, _("%s: warning: %s has "
                              "insecure permissions %04o, "
                              "%04o suggested\n"),
                    progname, special, st.st_mode & 07777,
                    ~permMask & 0666);
        }
    }

    /* test for holes by LBT */
    if (S_ISREG(st.st_mode)) {
        if (st.st_blocks * 512 < st.st_size) {
            fprintf(stderr,
                    _("%s: Skipping file %s - it appears "
                      "to have holes.\n"),
                    progname, special);
            return -1;
        }
    }

#ifdef SWAPON_NEEDS_TWO_ARGS
    {
        int flags = 0;

#ifdef SWAP_FLAG_PREFER
        if (prio >= 0) {
            if (prio > SWAP_FLAG_PRIO_MASK)
                prio = SWAP_FLAG_PRIO_MASK;
            flags = SWAP_FLAG_PREFER
                    | ((prio & SWAP_FLAG_PRIO_MASK)
                       << SWAP_FLAG_PRIO_SHIFT);
        }
#endif
        status = swapon(special, flags);
    }
#else
    status = swapon(special);
#endif
    if (status < 0) {
        int errsv = errno;
        fprintf(stderr, "%s: %s: %s\n",
                progname, orig_special, strerror(errsv));
    }

    return status;
}
Esempio n. 21
0
static int
do_swapon(const char *orig_special, int prio, int canonic) {
	int status;
	struct stat st;
	const char *special = orig_special;

	if (verbose)
		printf(_("%s on %s\n"), progname, orig_special);

	if (!canonic) {
		special = fsprobe_get_devname(orig_special);
		if (!special)
			return cannot_find(orig_special);
	}

	if (stat(special, &st) < 0) {
		int errsv = errno;
		fprintf(stderr, _("%s: cannot stat %s: %s\n"),
			progname, special, strerror(errsv));
		return -1;
	}

	/* We have to reinitialize swap with old (=useless) software suspend
	 * data. The problem is that if we don't do it, then we get data
	 * corruption the next time an attempt at unsuspending is made.
	 */
	if (swap_is_suspend(special)) {
		fprintf(stdout, _("%s: %s: software suspend data detected. "
					"Reinitializing the swap.\n"),
			progname, special);
		if (swap_reinitialize(special) < 0)
			return -1;
	}

	/* people generally dislike this warning - now it is printed
	   only when `verbose' is set */
	if (verbose) {
		int permMask = (S_ISBLK(st.st_mode) ? 07007 : 07077);

		if ((st.st_mode & permMask) != 0) {
			fprintf(stderr, _("%s: warning: %s has "
					  "insecure permissions %04o, "
					  "%04o suggested\n"),
				progname, special, st.st_mode & 07777,
				~permMask & 0666);
		}
	}

	/* test for holes by LBT */
	if (S_ISREG(st.st_mode)) {
		if (st.st_blocks * 512 < st.st_size) {
			fprintf(stderr,
				_("%s: Skipping file %s - it appears "
				  "to have holes.\n"),
				progname, special);
			return -1;
		}
	}

	{
		int flags = 0;

#ifdef SWAP_FLAG_PREFER
		if (prio >= 0) {
			if (prio > SWAP_FLAG_PRIO_MASK)
				prio = SWAP_FLAG_PRIO_MASK;
			flags = SWAP_FLAG_PREFER
				| ((prio & SWAP_FLAG_PRIO_MASK)
				   << SWAP_FLAG_PRIO_SHIFT);
		}
#endif
		status = swapon(special, flags);
	}

	if (status < 0) {
		int errsv = errno;
		fprintf(stderr, "%s: %s: %s\n",
			progname, orig_special, strerror(errsv));
	}

	return status;
}
Esempio n. 22
0
void add_temp_swap(long page_size)
{
	char path[PATH_MAX];
	char file[PATH_MAX];
	char mkswap_cmd[PATH_MAX];
	FILE *f;
	char *buf;
	long swap_size;
	long pid;
	int ret;
	int num_pages;

	if (geteuid() != 0) {
		ERROR("Swap can only be manipulated by root\n");
		exit(EXIT_FAILURE);
	}

	pid = getpid();
	snprintf(path, PATH_MAX, "%s/swap/temp", MOUNT_DIR);
	snprintf(file, PATH_MAX, "%s/swapfile-%ld", path, pid);

	/* swapsize is 5 hugepages */
	if (opt_temp_swap == -1)
		num_pages = 5;
	else
		num_pages = opt_temp_swap;
	swap_size = num_pages * page_size;

	if (ensure_dir(path, S_IRWXU | S_IRGRP | S_IXGRP, 0, 0))
		exit(EXIT_FAILURE);

	if (opt_dry_run) {
		printf("dd bs=1024 count=%ld if=/dev/zero of=%s\n",
			swap_size / 1024, file);
		printf("mkswap %s\nswapon %s\n", file, file);
		return;
	}

	f = fopen(file, "wx");
	if (!f) {
		WARNING("Couldn't open %s: %s\n", file, strerror(errno));
		opt_temp_swap = 0;
		return;
	}

	buf = malloc(swap_size);
	memset(buf, 0, swap_size);
	fwrite(buf, sizeof(char), swap_size, f);
	free(buf);
	fclose(f);

	snprintf(mkswap_cmd, PATH_MAX, "mkswap %s", file);
	ret = system(mkswap_cmd);
	if (WIFSIGNALED(ret)) {
		WARNING("Call to mkswap failed\n");
		opt_temp_swap = 0;
		return;
	} else if (WIFEXITED(ret)) {
		ret = WEXITSTATUS(ret);
		if (ret) {
			WARNING("Call to mkswap failed\n");
			opt_temp_swap = 0;
			return;
		}
	}

	DEBUG("swapon %s\n", file);
	if (swapon(file, 0)) {
		WARNING("swapon on %s failed: %s\n", file, strerror(errno));
		opt_temp_swap = 0;
	}
}