Propagate errors up the call stack. Patch by Jens Erdmann <j.erdmann@road.de>.
[oweals/opkg-lede.git] / libopkg / opkg_cmd.c
index 88a0b5f13fb5e8baae7200dbb78b9ce83e6ef478..0fa471e3b43f3a7f2429d99bbb7752b62af7961c 100644 (file)
    General Public License for more details.
 */
 
+#include "config.h"
 
-#include "includes.h"
+#include <stdio.h>
 #include <dirent.h>
 #include <glob.h>
 #include <fnmatch.h>
+#include <signal.h>
+#include <unistd.h>
 
 #include "opkg_conf.h"
 #include "opkg_cmd.h"
@@ -423,7 +426,7 @@ error:
 static int
 opkg_install_cmd(int argc, char **argv)
 {
-     int i;
+     int i, r;
      char *arg;
      int err=0;
 
@@ -450,7 +453,9 @@ opkg_install_cmd(int argc, char **argv)
          }
      }
 
-     opkg_configure_packages(NULL);
+     r = opkg_configure_packages(NULL);
+     if (!err)
+         err = r;
 
      write_status_files_if_changed();
 
@@ -460,7 +465,7 @@ opkg_install_cmd(int argc, char **argv)
 static int
 opkg_upgrade_cmd(int argc, char **argv)
 {
-     int i;
+     int i, r;
      pkg_t *pkg;
      int err;
 
@@ -508,7 +513,9 @@ opkg_upgrade_cmd(int argc, char **argv)
          pkg_vec_free(installed);
      }
 
-     opkg_configure_packages(NULL);
+     r = opkg_configure_packages(NULL);
+     if (!err)
+         err = r;
 
      write_status_files_if_changed();
 
@@ -518,7 +525,7 @@ opkg_upgrade_cmd(int argc, char **argv)
 static int
 opkg_download_cmd(int argc, char **argv)
 {
-     int i, err;
+     int i, err = 0;
      char *arg;
      pkg_t *pkg;
 
@@ -542,7 +549,7 @@ opkg_download_cmd(int argc, char **argv)
          }
      }
 
-     return 0;
+     return err;
 }
 
 
@@ -695,7 +702,7 @@ opkg_configure_cmd(int argc, char **argv)
 static int
 opkg_remove_cmd(int argc, char **argv)
 {
-     int i, a, done;
+     int i, a, done, r, err = 0;
      pkg_t *pkg;
      pkg_t *pkg_to_remove;
      pkg_vec_t *available;
@@ -731,7 +738,10 @@ opkg_remove_cmd(int argc, char **argv)
                 opkg_msg(ERROR, "Package %s not installed.\n", pkg->name);
                  continue;
             }
-            opkg_remove_pkg(pkg_to_remove, 0);
+            r = opkg_remove_pkg(pkg_to_remove, 0);
+           if (!err)
+                err = r;
+
             done = 1;
         }
      }
@@ -742,7 +752,7 @@ opkg_remove_cmd(int argc, char **argv)
         opkg_msg(NOTICE, "No packages removed.\n");
 
      write_status_files_if_changed();
-     return 0;
+     return err;
 }
 
 static int