X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=zpm-runscript.c;h=a3f4c2f6d07efe0e21c071483264b2deca97a301;hb=6b5150de70d70d49360fb3804af8136f442dffc1;hp=db337beef3d9d154fa090be93c36daa43f645d4a;hpb=b547a6673cbb8bf2685fa0c03e143f14d3c803ed;p=zpackage diff --git a/zpm-runscript.c b/zpm-runscript.c index db337be..a3f4c2f 100644 --- a/zpm-runscript.c +++ b/zpm-runscript.c @@ -148,17 +148,19 @@ int main(int ac, char **av){ pkgid = zpm_findpkg(&zpm, pkgstr); if (pkgid) { if (zpm_script_hash(&zpm, pkgid, phase, hash)) { - rv = zpm_extract(&zpm, hash, script, 0700); + /* since the script file name doesn't really + * mean anything, pass in the phase as arg 0 + */ - /* perhaps also pass in the phase name? or ENV? */ /* TODO sanitize environment ? */ - args[0] = script; + args[0] = phase; args[1] = pkgid; args[2] = 0; args[3] = 0; if (argn + 1 <= ac) { args[2] = av[argn+1]; } + if (rootdir) { if (chdir(rootdir) == -1) { perror("can not chdir to rootdir"); @@ -171,7 +173,7 @@ int main(int ac, char **av){ */ fprintf(stderr, "support for chroot equivalent not supported on this OS\n"); } else { - fprintf(stderr, "unable to chroot as non root use\n"); + fprintf(stderr, "unable to chroot as non root user\n"); } } else { if (chdir("/") == -1) { @@ -179,6 +181,12 @@ int main(int ac, char **av){ exit(EXIT_FAILURE); } } + + if (!zpm_extract(&zpm, hash, script, 0700)) { + fprintf(stderr, "unable to extract script"); + exit(EXIT_FAILURE); + } + rv = run(script, args, output, &status); if (rv) { // cat(output); @@ -186,8 +194,12 @@ int main(int ac, char **av){ pkgid, rv); } /* TODO log output */ - unlink(script); - unlink(output); + if (script) { + unlink(script); + } + if (output) { + unlink(output); + } if (rv) { failures++; }