conf: remove fgets() from lxc_chroot()

parent ebf3a6af
...@@ -1364,8 +1364,6 @@ int lxc_chroot(const struct lxc_rootfs *rootfs) ...@@ -1364,8 +1364,6 @@ int lxc_chroot(const struct lxc_rootfs *rootfs)
{ {
__do_free char *nroot = NULL; __do_free char *nroot = NULL;
int i, ret; int i, ret;
char *p, *p2;
char buf[LXC_LINELEN];
char *root = rootfs->mount; char *root = rootfs->mount;
nroot = realpath(root, NULL); nroot = realpath(root, NULL);
...@@ -1405,7 +1403,10 @@ int lxc_chroot(const struct lxc_rootfs *rootfs) ...@@ -1405,7 +1403,10 @@ int lxc_chroot(const struct lxc_rootfs *rootfs)
*/ */
for (;;) { for (;;) {
__do_fclose FILE *f = NULL; __do_fclose FILE *f = NULL;
__do_free char *line = NULL;
char *slider1, *slider2;
int progress = 0; int progress = 0;
size_t len = 0;
f = fopen("./proc/self/mountinfo", "r"); f = fopen("./proc/self/mountinfo", "r");
if (!f) { if (!f) {
...@@ -1413,27 +1414,27 @@ int lxc_chroot(const struct lxc_rootfs *rootfs) ...@@ -1413,27 +1414,27 @@ int lxc_chroot(const struct lxc_rootfs *rootfs)
return -1; return -1;
} }
while (fgets(buf, LXC_LINELEN, f)) { while (getline(&line, &len, f) > 0) {
for (p = buf, i=0; p && i < 4; i++) for (slider1 = line, i = 0; slider1 && i < 4; i++)
p = strchr(p+1, ' '); slider1 = strchr(slider1 + 1, ' ');
if (!p) if (!slider1)
continue; continue;
p2 = strchr(p+1, ' '); slider2 = strchr(slider1 + 1, ' ');
if (!p2) if (!slider2)
continue; continue;
*p2 = '\0'; *slider2 = '\0';
*p = '.'; *slider1 = '.';
if (strcmp(p + 1, "/") == 0) if (strcmp(slider1 + 1, "/") == 0)
continue; continue;
if (strcmp(p + 1, "/proc") == 0) if (strcmp(slider1 + 1, "/proc") == 0)
continue; continue;
ret = umount2(p, MNT_DETACH); ret = umount2(slider1, MNT_DETACH);
if (ret == 0) if (ret == 0)
progress++; progress++;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment