X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/cf37c2996a8b83ccbcb7e2e413f749f6e60a3845..00bf83c00bdd789601d0af3bad04d92d92951111:/dynamic_pager.tproj/dynamic_pager.c diff --git a/dynamic_pager.tproj/dynamic_pager.c b/dynamic_pager.tproj/dynamic_pager.c index 9c0f435..deb9379 100644 --- a/dynamic_pager.tproj/dynamic_pager.c +++ b/dynamic_pager.tproj/dynamic_pager.c @@ -43,16 +43,14 @@ clean_swap_directory(const char *path) int main(int argc, char **argv) { - char default_filename[] = "/private/var/vm/swapfile"; int ch; - int err=0; static char tmp[1024]; struct statfs sfs; char *q; char fileroot[512]; seteuid(getuid()); - strcpy(fileroot, default_filename); + fileroot[0] = '\0'; while ((ch = getopt(argc, argv, "F:")) != EOF) { switch((char)ch) { @@ -68,6 +66,25 @@ main(int argc, char **argv) } } + /* + * set vm.swapfileprefix if a fileroot was passed from the command + * line, otherwise get the value from the kernel + */ + if (fileroot[0] != '\0') { + if (sysctlbyname("vm.swapfileprefix", NULL, 0, fileroot, sizeof(fileroot)) == -1) { + perror("Failed to set swapfile name prefix"); + } + } else { + size_t fileroot_len = sizeof(fileroot); + if (sysctlbyname("vm.swapfileprefix", fileroot, &fileroot_len, NULL, 0) == -1) { + perror("Failed to get swapfile name prefix"); + /* + * can't continue without a fileroot + */ + return (0); + } + } + /* * get rid of the filename at the end of the swap file specification * we only want the portion of the pathname that should already exist @@ -93,10 +110,5 @@ main(int argc, char **argv) chown(tmp, 0, 0); - err = sysctlbyname("vm.swapfileprefix", NULL, 0, fileroot, sizeof(fileroot)); - if (err) { - (void)fprintf(stderr, "Failed to set swapfile name prefix with error: %d\n", err); - } - return (0); }