]> pd.if.org Git - zpackage/blobdiff - zpm-runscript.c
fix pointer related bugs
[zpackage] / zpm-runscript.c
index db337beef3d9d154fa090be93c36daa43f645d4a..ccaee48c30229f062e97afd8280b63a9c2086de7 100644 (file)
@@ -148,7 +148,6 @@ 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);
 
                        /* perhaps also pass in the phase name?  or ENV? */
                        /* TODO sanitize environment ? */
@@ -159,6 +158,7 @@ int main(int ac, char **av){
                        if (argn + 1 <= ac) {
                                args[2] = av[argn+1];
                        }
+
                        if (rootdir) {
                                if (chdir(rootdir) == -1) {
                                        perror("can not chdir to rootdir");
@@ -171,7 +171,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 +179,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 +192,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++;
                        }