opkg: trivial, clean up obsolete code, and some typo
[oweals/opkg-lede.git] / libopkg / opkg_cmd.c
index 6eb01eb3638e8799bad08e96a8aa57aa217d20e5..8386fcea50091136b7a9818f8736952162b35b90 100644 (file)
@@ -288,7 +288,7 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
          free (tmp_file_name);
          free (url);
 #else
-         opkg_message (conf, OPKG_NOTICE, "Signiture check for %s skipped "
+         opkg_message (conf, OPKG_NOTICE, "Signature check for %s skipped "
               "because GPG support was not enabled in this build\n", src->name);
 #endif
          free(list_file_name);
@@ -312,11 +312,18 @@ typedef struct opkg_intercept *opkg_intercept_t;
 static opkg_intercept_t opkg_prep_intercepts(opkg_conf_t *conf)
 {
     opkg_intercept_t ctx;
+    char *oldpath;
     char *newpath;
     int gen;
 
     ctx = malloc (sizeof (*ctx));
-    ctx->oldpath = strdup (getenv ("PATH"));
+    oldpath = getenv ("PATH");
+    if (oldpath) {
+        ctx->oldpath = strdup (oldpath);
+    } else {
+        ctx->oldpath = 0;
+    }
+
 
     sprintf_alloc (&newpath, "%s/opkg/intercept:%s", DATADIR, ctx->oldpath);
     setenv ("PATH", newpath, 1);
@@ -344,8 +351,12 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx)
     DIR *dir;
     int err = 0;
 
-    setenv ("PATH", ctx->oldpath, 1);
-    free (ctx->oldpath);
+    if (ctx->oldpath) {
+        setenv ("PATH", ctx->oldpath, 1);
+        free (ctx->oldpath);
+    } else {
+        unsetenv("PATH"); 
+    }
 
     dir = opendir (ctx->statedir);
     if (dir) {
@@ -369,7 +380,7 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx)
        perror (ctx->statedir);
        
     sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir);
-    system (cmd);
+    err = system (cmd);
     free (cmd);
 
     free (ctx->statedir);
@@ -909,9 +920,9 @@ static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv)
 
     done = 0;
 
-     available = pkg_vec_alloc();
      pkg_info_preinstall_check(conf);
      if ( argc > 0 ) {
+        available = pkg_vec_alloc();
         pkg_hash_fetch_all_installed(&conf->pkg_hash, available);
         for (i=0; i < argc; i++) {
            pkg_name = malloc(strlen(argv[i])+2);