Use xsystem() to be consistent. Some minor cleanup too.
[oweals/opkg-lede.git] / libopkg / opkg_cmd.c
index 8b18ec203efb85e39492e166447d54752194590c..f67a2645152866689a8f8336995ae1c110b78979 100644 (file)
@@ -19,6 +19,7 @@
 #include "includes.h"
 #include <dirent.h>
 #include <glob.h>
+#include <fnmatch.h>
 
 #include "opkg_conf.h"
 #include "opkg_cmd.h"
 #include "libbb/libbb.h"
 #include "opkg_utils.h"
 #include "opkg_defines.h"
-
-#include <fnmatch.h>
-
-
 #include "opkg_download.h"
 #include "opkg_install.h"
 #include "opkg_upgrade.h"
 #include "opkg_remove.h"
 #include "opkg_configure.h"
 #include "opkg_message.h"
-
 #include "libopkg.h"
+#include "xsystem.h"
 
 static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv);
 static int opkg_upgrade_cmd(opkg_conf_t *conf, int argc, char **argv);
@@ -180,7 +177,7 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
                            "%s: ERROR: %s exists, but is not a directory\n",
                            __FUNCTION__, lists_dir);
               free(lists_dir);
-              return EINVAL;
+              return -1;
          }
          err = file_mkdir_hier(lists_dir, 0755);
          if (err) {
@@ -188,18 +185,16 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
                            "%s: ERROR: failed to make directory %s: %s\n",
                            __FUNCTION__, lists_dir, strerror(errno));
               free(lists_dir);
-              return EINVAL;
+              return -1;
          }     
      } 
 
      failures = 0;
 
-
-     tmp = xstrdup("/tmp/opkg.XXXXXX");
-
+     sprintf_alloc(&tmp, "%s/update-XXXXXX", conf->tmp_dir);
      if (mkdtemp (tmp) == NULL) {
         perror ("mkdtemp");
-        failures++;
+        return -1;
      }
 
 
@@ -340,16 +335,13 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx)
        struct dirent *de;
        while (de = readdir (dir), de != NULL) {
            char *path;
-           
+
            if (de->d_name[0] == '.')
                continue;
            
            sprintf_alloc (&path, "%s/%s", ctx->statedir, de->d_name);
            if (access (path, X_OK) == 0) {
-               if (system (path)) {
-                   err = errno;
-                   perror (de->d_name);
-               }
+               xsystem (path);
            }
            free (path);
        }
@@ -358,7 +350,7 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx)
        perror (ctx->statedir);
        
     sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
-    err = system (cmd);
+    err = xsystem (cmd);
     free (cmd);
 
     free (ctx->statedir);
@@ -485,8 +477,10 @@ static int opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
      }
 
      ic = opkg_prep_intercepts (conf);
-     if (ic == NULL)
-            return -1;
+     if (ic == NULL) {
+            err = -1;
+            goto error;
+     }
     
      for(i = 0; i < all->len; i++) {
          pkg = all->pkgs[i];
@@ -514,6 +508,7 @@ static int opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
      if (r && !err)
         err = r;
 
+error:
      pkg_vec_free(all);
      pkg_vec_free(ordered);
      pkg_vec_free(visited);