]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
utils: make detect_ramfs_rootfs() return bool
authorChristian Brauner <christian.brauner@canonical.com>
Tue, 6 Sep 2016 11:49:13 +0000 (13:49 +0200)
committerChristian Brauner <christian.brauner@canonical.com>
Tue, 27 Sep 2016 20:48:14 +0000 (22:48 +0200)
Signed-off-by: Christian Brauner <christian.brauner@canonical.com>
src/lxc/utils.c
src/lxc/utils.h

index 2029e3328b2f21725adfd72299b57bb0b90e98e7..c912fe8f00231a4dc9e9a32b2501b6ec696e9baf 100644 (file)
@@ -1158,36 +1158,40 @@ bool switch_to_ns(pid_t pid, const char *ns) {
  * IIUC, so long as we've chrooted so that rootfs is not our root,
  * the rootfs entry should always be skipped in mountinfo contents.
  */
-int detect_ramfs_rootfs(void)
+bool detect_ramfs_rootfs(void)
 {
-       char buf[LINELEN], *p;
        FILE *f;
+       char *p, *p2;
+       char *line = NULL;
+       size_t len = 0;
        int i;
-       char *p2;
 
        f = fopen("/proc/self/mountinfo", "r");
        if (!f)
-               return 0;
-       while (fgets(buf, LINELEN, f)) {
-               for (p = buf, i=0; p && i < 4; i++)
-                       p = strchr(p+1, ' ');
+               return false;
+
+       while (getline(&line, &len, f) != -1) {
+               for (p = line, i = 0; p && i < 4; i++)
+                       p = strchr(p + 1, ' ');
                if (!p)
                        continue;
-               p2 = strchr(p+1, ' ');
+               p2 = strchr(p + 1, ' ');
                if (!p2)
                        continue;
                *p2 = '\0';
-               if (strcmp(p+1, "/") == 0) {
+               if (strcmp(p + 1, "/") == 0) {
                        // this is '/'.  is it the ramfs?
-                       p = strchr(p2+1, '-');
+                       p = strchr(p2 + 1, '-');
                        if (p && strncmp(p, "- rootfs rootfs ", 16) == 0) {
+                               free(line);
                                fclose(f);
-                               return 1;
+                               return true;
                        }
                }
        }
+       free(line);
        fclose(f);
-       return 0;
+       return false;
 }
 
 char *on_path(char *cmd, const char *rootfs) {
index 88719a0f35508d0a2e257383c2db85fbaa250395..a0fa0e2a57eae3f65d9c074098d654d5765bea82 100644 (file)
@@ -293,7 +293,7 @@ extern bool dir_exists(const char *path);
 uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval);
 
 int detect_shared_rootfs(void);
-int detect_ramfs_rootfs(void);
+bool detect_ramfs_rootfs(void);
 char *on_path(char *cmd, const char *rootfs);
 bool file_exists(const char *f);
 bool cgns_supported(void);