X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-script.c;h=7c03b241792ae1f91ea504215b1400526580c71b;hb=cde24e1cff5b44fa7a2ab5db414975f6c667fd34;hp=8018849b36c450b1f00db39657557e658877b8ea;hpb=1e4c821a25907f59c322fda9ea8bf66e0f54a021;p=zpackage diff --git a/zpm-script.c b/zpm-script.c index 8018849..7c03b24 100644 --- a/zpm-script.c +++ b/zpm-script.c @@ -30,11 +30,12 @@ void usage(void) { } int setdir(char *rootdir) { + if (chdir(rootdir ? rootdir : "/") == -1) { + perror("can not chdir to rootdir"); + return 0; + } +#if 0 if (rootdir && strcmp(rootdir, "/")) { - if (chdir(rootdir) == -1) { - perror("can not chdir to rootdir"); - return 0; - } if (geteuid() == 0) { /* chroot is deprecated, and not in posix. need to use * OS/kernel specific code. @@ -43,12 +44,8 @@ int setdir(char *rootdir) { } else { fprintf(stderr, "unable to chroot as non root user\n"); } - } else { - if (chdir("/") == -1) { - perror("can not chdir to /"); - return 0; - } } +#endif return 1; } @@ -143,10 +140,10 @@ int main(int ac, char **av){ char *script = "/var/tmp/zpm-script"; char *output = "/var/tmp/zpm-script.out"; char *phase = 0; + char *envvar = 0; int quiet = 0; int scriptishash = 0; int mode = RUN; - int all = 0; if (getenv("ZPMDB")) { db = getenv("ZPMDB"); @@ -155,6 +152,16 @@ int main(int ac, char **av){ rootdir = getenv("ZPM_ROOT_DIR"); + envvar = getenv("ZPM_SCRIPT_FILE"); + if (envvar) { + script = envvar; + } + + envvar = getenv("ZPM_SCRIPT_OUTPUT"); + if (envvar) { + output = envvar; + } + /* run, set, show, hash */ /* set -S, if -H set the hash, output hash, unless quiet * show: -o, or stdout, @@ -178,7 +185,6 @@ int main(int ac, char **av){ case 'l': mode = LIST; break; case 'R': rootdir = optarg; break; case 'F': required = 1; break; - case 'a': all = 1; break; case 'h': scriptishash = 1; break; case 'o': output = optarg; break; @@ -310,6 +316,7 @@ int main(int ac, char **av){ if (!zpm_extract(&zpm, hash, script, 0700)) { fprintf(stderr, "unable to extract script"); fail = HARD; + zpm_note_add(&zpm, pkgid, NULL, hash, "unable to extract %s script", phase); goto cleanup; } @@ -317,6 +324,10 @@ int main(int ac, char **av){ if (rv) { fprintf(stderr, "package %s script failed with code %d\n", pkgid, rv); + + zpm_import(&zpm, output, 0, hash); + zpm_note_add(&zpm, pkgid, NULL, hash, "package %s script failed with code %d", phase, rv); + fail = HARD; } @@ -334,5 +345,4 @@ cleanup: zpm_close(&zpm); return (fail == HARD || (required && fail)) ? EXIT_FAILURE : 0; - }