void detach_swap_partition(char *part_name) { int need_detach = 0; char *swap_part = nvram_safe_get("swap_part_t"); char swap_dev[16]; if (strncmp(swap_part, "sd", 2)) { return; } if (part_name && *part_name) { if (strncmp(part_name, swap_part, 3) == 0) { need_detach = 1; } } else { need_detach = 1; } // umount swap partition if (need_detach) { sprintf(swap_dev, "/dev/%s", swap_part); if ( swapoff(swap_dev) == 0 ) { nvram_set("swap_part_t", ""); } } }
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; }
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; }
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); }
static int do_swapoff(const char *orig_special, int quiet, int canonic) { const char *special = orig_special; if (verbose) printf(_("swapoff %s\n"), orig_special); if (!canonic) { char *n, *v; special = mnt_resolve_spec(orig_special, mntcache); if (!special && blkid_parse_tag_string(orig_special, &n, &v) == 0) special = swapoff_resolve_tag(n, v, mntcache); if (!special) return cannot_find(orig_special); } if (swapoff(special) == 0) return 0; /* success */ if (errno == EPERM) errx(EXIT_FAILURE, _("Not superuser.")); if (!quiet || errno == ENOMEM) warn(_("%s: swapoff failed"), orig_special); return -1; }
static int do_swapoff(const char *orig_special, int quiet) { const char *special; if (verbose) printf(_("%s on %s\n"), progname, orig_special); special = mount_get_devname(orig_special); if (!special) return cannot_find(orig_special); if (swapoff(special) == 0) return 0; /* success */ if (errno == EPERM) { fprintf(stderr, _("Not superuser.\n")); exit(1); /* any further swapoffs will also fail */ } if (!quiet || errno == ENOMEM) { fprintf(stderr, "%s: %s: %s\n", progname, orig_special, strerror(errno)); } return -1; }
int main(int argc, char *argv[]) { int i; int ret = 0; int all = 0; struct mntent *me; FILE *fp; ARGBEGIN { case 'a': all = 1; break; default: usage(); } ARGEND; if ((!all && argc < 1) || (all && argc > 0)) usage(); if (all) { fp = setmntent("/etc/fstab", "r"); if (!fp) eprintf("setmntent %s:", "/etc/fstab"); 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); ret = 1; } } } endmntent(fp); } else { for (i = 0; i < argc; i++) { if (swapoff(argv[i]) < 0) { weprintf("swapoff %s:", argv[i]); ret = 1; } } } return ret; }
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); }
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); }
int swapoff_main(int argc, char *argv[]) { if( argc != 2 ) { printf("swapoff dev_path\n"); return -1; } fprintf(stderr, "swapoff %s\n ", argv[1]); SLOGI("swapoff %s ", argv[1]); return swapoff(argv[1]); }
static PyObject * doSwapoff (PyObject * s, PyObject * args) { char * path; if (!PyArg_ParseTuple(args, "s", &path)) return NULL; if (swapoff (path)) { PyErr_SetFromErrno(PyExc_SystemError); return NULL; } Py_INCREF(Py_None); return Py_None; }
static int do_swapoff (const char *path) { int r; verbose_do ("Turning off swap on ", path); r = swapoff (path); if (r < 0) verbose_fail (errno); else if (level > 0) aa_put_title (0, "Swap turned off", path, 1); return r; }
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; }
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; }
void rem_temp_swap() { char file[PATH_MAX]; long pid; pid = getpid(); snprintf(file, PATH_MAX, "%s/swap/temp/swapfile-%ld", MOUNT_DIR, pid); if (opt_dry_run) { printf("swapoff %s\nrm -f %s\n", file, file); return; } if (swapoff(file)) WARNING("swapoff on %s failed: %s\n", file, strerror(errno)); remove(file); DEBUG("swapoff %s\n", file); }
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); }
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; }
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); }
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; }
static int do_swapoff(const char *orig_special, int quiet, int canonic) { const char *special = orig_special; 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 (swapoff(special) == 0) return 0; /* success */ if (errno == EPERM) errx(EXIT_FAILURE, _("Not superuser.")); if (!quiet || errno == ENOMEM) warn(_("%s: swapoff failed"), orig_special); return -1; }
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); }