properly handle return codes
authorJohn Crispin <blogic@openwrt.org>
Sat, 28 Mar 2015 17:32:22 +0000 (18:32 +0100)
committerJohn Crispin <blogic@openwrt.org>
Sat, 28 Mar 2015 17:32:22 +0000 (18:32 +0100)
Signed-off-by: John Crispin <blogic@openwrt.org>
block.c
libblkid-tiny/libblkid-tiny.c
libblkid-tiny/mkdev.c
libfstools/extroot.c
libfstools/overlay.c
libfstools/snapshot.c

diff --git a/block.c b/block.c
index 4c479c0c0b52760a007f04b474efcf15fd46e34f..a3db87bc936d782d5e8892f8be930e5a867299a2 100644 (file)
--- a/block.c
+++ b/block.c
@@ -1020,10 +1020,12 @@ static int check_extroot(char *path)
                                return -1;
                        }
 
-                       fgets(uuid, sizeof(uuid), fp);
+                       if (!fgets(uuid, sizeof(uuid), fp))
+                               ULOG_ERR("extroot: failed to read UUID from %s: %d (%s)\n",
+                                        tag, errno, strerror(errno));
                        fclose(fp);
 
-                       if (!strcasecmp(uuid, pr->uuid))
+                       if (*uuid || !strcasecmp(uuid, pr->uuid))
                                return 0;
 
                        ULOG_ERR("extroot: UUID mismatch (root: %s, %s: %s)\n",
@@ -1360,18 +1362,18 @@ static int main_swapoff(int argc, char **argv)
                        ULOG_ERR("failed to open /proc/swaps\n");
                        return -1;
                }
-               fgets(line, sizeof(line), fp);
-               while (fgets(line, sizeof(line), fp)) {
-                       char *end = strchr(line, ' ');
-                       int err;
+               if (fgets(line, sizeof(line), fp))
+                       while (fgets(line, sizeof(line), fp)) {
+                               char *end = strchr(line, ' ');
+                               int err;
 
-                       if (!end)
-                               continue;
-                       *end = '\0';
-                       err = swapoff(line);
-                       if (err)
-                               ULOG_ERR("failed to swapoff %s (%d)\n", line, err);
-               }
+                               if (!end)
+                                       continue;
+                               *end = '\0';
+                               err = swapoff(line);
+                               if (err)
+                                       ULOG_ERR("failed to swapoff %s (%d)\n", line, err);
+                       }
                fclose(fp);
        } else {
                struct stat s;
index 671c6c85b2166289c16b6d2095e5209687ab3621..f66f3a1dc16ef3d8d75e8b4092494b0510fb5fb2 100644 (file)
@@ -197,7 +197,8 @@ int probe_block(char *block, struct blkid_struct_probe *pr)
                        char magic[32] = { 0 };
 
                        lseek(pr->fd, off, SEEK_SET);
-                       read(pr->fd, magic, mag->len);
+                       if (read(pr->fd, magic, mag->len) < 0)
+                               return -1;
 
                        DEBUG("magic: %s %s %d\n", mag->magic, magic, mag->len);
                        if (!memcmp(mag->magic, magic, mag->len))
index 06c035858f07a54c23da150a305aa95f884ed5b5..f1d504f920be6a2b6c817e1f3e9d540693d869ac 100644 (file)
@@ -88,7 +88,6 @@ int mkblkdev(void)
 
        mode = 0600;
        find_devs(true);
-       chdir("/");
 
-       return 0;
+       return chdir("/");
 }
index e548bb1c345f548be4d7697483e5ab344604ec83..418df9494f7f4ba0a59f4efa3963c34c424d4f39 100644 (file)
@@ -64,7 +64,8 @@ int mount_extroot(void)
                setenv("LD_LIBRARY_PATH", ldlib_path, 1);
                snprintf(kmod_loader, sizeof(kmod_loader),
                         "/sbin/kmodloader %s/etc/modules-boot.d/", dirname(ldlib_path));
-               system(kmod_loader);
+               if (system(kmod_loader))
+                       ULOG_ERR("failed to launch kmodloader from internal overlay\n");
        }
 
        pid = fork();
index 3269a52c5322e3043460f20ec067d7a0ddf3ea35..0677c34ed3588bbc32a52c72c446ac4cd84f9626 100644 (file)
@@ -143,7 +143,10 @@ switch2jffs(struct volume *v)
                return -1;
        }
 
-       system("cp -a /tmp/root/* /rom/overlay"); /**/
+       if (system("cp -a /tmp/root/* /rom/overlay")) {
+               ULOG_ERR("failed - cp -a /tmp/root/* /rom/overlay: %s\n", strerror(errno));
+               return -1;
+       }
 
        if (pivot("/rom", "/mnt")) {
                ULOG_ERR("failed - pivot /rom /mnt: %s\n", strerror(errno));
index 1ec7b8798180f14975eb6ea050d2827df55c8446..936f2af21a76967051a903c29c60593306b68662 100644 (file)
@@ -329,13 +329,19 @@ mount_snapshot(struct volume *v)
        snapshot_sync(v);
        setenv("SNAPSHOT", "magic", 1);
        _ramoverlay("/rom", "/overlay");
-       system("/sbin/snapshot unpack");
+       if (system("/sbin/snapshot unpack") == -1) {
+               perror("system");
+               return -1;
+       }
        foreachdir("/overlay/", handle_whiteout);
        mkdir("/volatile", 0700);
        _ramoverlay("/rom", "/volatile");
        mount_move("/rom/volatile", "/volatile", "");
        mount_move("/rom/rom", "/rom", "");
-       system("/sbin/snapshot config_unpack");
+       if (system("/sbin/snapshot config_unpack")) {
+               perror("system");
+               return -1;
+       }
        foreachdir("/volatile/", handle_whiteout);
        unsetenv("SNAPSHOT");
        return -1;