diff options
Diffstat (limited to 'util-linux')
| -rw-r--r-- | util-linux/lsblk.c | 11 | ||||
| -rw-r--r-- | util-linux/mount.c | 25 |
2 files changed, 20 insertions, 16 deletions
diff --git a/util-linux/lsblk.c b/util-linux/lsblk.c index a482bfbbc..3bd40bcb4 100644 --- a/util-linux/lsblk.c +++ b/util-linux/lsblk.c | |||
| @@ -101,10 +101,10 @@ static char *get_mountpoints(const char *majmin) | |||
| 101 | 101 | ||
| 102 | mountpoints = NULL; | 102 | mountpoints = NULL; |
| 103 | len = strlen(majmin); | 103 | len = strlen(majmin); |
| 104 | p = G.mountinfo; // "/proc/self/mountinfo" | 104 | p = G.mountinfo; // contents of "/proc/self/mountinfo" |
| 105 | /* lines a-la "63 1 259:3 / /MNTPOINT per-mount_options - ext4 /dev/NAME per-superblock_options" */ | 105 | /* lines a-la "63 1 259:3 / /MNTPOINT per-mount_options - ext4 /dev/NAME per-superblock_options" */ |
| 106 | while (*p) { | 106 | while (*p) { |
| 107 | char *e, *f; | 107 | char *e; |
| 108 | 108 | ||
| 109 | p = skip_non_whitespace(p); | 109 | p = skip_non_whitespace(p); |
| 110 | if (*p != ' ') break; | 110 | if (*p != ' ') break; |
| @@ -127,12 +127,11 @@ static char *get_mountpoints(const char *majmin) | |||
| 127 | // at " /MNTPOINT" | 127 | // at " /MNTPOINT" |
| 128 | e = skip_non_whitespace(p + 1); | 128 | e = skip_non_whitespace(p + 1); |
| 129 | // e is at the end of " /MNTPOINT" | 129 | // e is at the end of " /MNTPOINT" |
| 130 | f = mountpoints; | ||
| 131 | // NO. We return " /MNT1 /MNT2 /MNT3" _with_ leading space! | 130 | // NO. We return " /MNT1 /MNT2 /MNT3" _with_ leading space! |
| 132 | // if (!f) | 131 | // if (!mountpoints) |
| 133 | // p++; | 132 | // p++; |
| 134 | mountpoints = xasprintf("%s%.*s", f ? f : "", (int)(e - p), p); | 133 | xasprintf_inplace(mountpoints, "%s%.*s", |
| 135 | free(f); | 134 | mountpoints ? mountpoints : "", (int)(e - p), p); |
| 136 | } | 135 | } |
| 137 | return mountpoints; | 136 | return mountpoints; |
| 138 | } | 137 | } |
diff --git a/util-linux/mount.c b/util-linux/mount.c index d0f0ae1ad..d0d109c09 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
| @@ -556,27 +556,33 @@ static int verbose_mount(const char *source, const char *target, | |||
| 556 | #endif | 556 | #endif |
| 557 | 557 | ||
| 558 | // Append mount options to string | 558 | // Append mount options to string |
| 559 | // ("merge two comma-separated lists" is a good candidate for libbb!) | ||
| 559 | static void append_mount_options(char **oldopts, const char *newopts) | 560 | static void append_mount_options(char **oldopts, const char *newopts) |
| 560 | { | 561 | { |
| 561 | if (*oldopts && **oldopts) { | 562 | if (*oldopts && **oldopts) { |
| 563 | //TODO: do this unconditionally? | ||
| 564 | //this way, newopts of "opt1,opt2,opt1" | ||
| 565 | //will be de-duped into "opt1,opt2" in _both_ cases | ||
| 566 | //(whether or now old opts are empty) | ||
| 567 | //the only modification needed is to not prepend extra comma | ||
| 568 | //when old opts is "". | ||
| 562 | // Do not insert options which are already there | 569 | // Do not insert options which are already there |
| 563 | while (newopts[0]) { | 570 | while (*newopts) { |
| 564 | char *p; | 571 | char *p; |
| 565 | int len; | 572 | int len; |
| 566 | 573 | ||
| 574 | //if (*newopts == ',') { newopts++; continue; } | ||
| 567 | len = strchrnul(newopts, ',') - newopts; | 575 | len = strchrnul(newopts, ',') - newopts; |
| 568 | p = *oldopts; | 576 | p = *oldopts; |
| 569 | while (1) { | 577 | while (1) { |
| 570 | if (!strncmp(p, newopts, len) | 578 | if (strncmp(p, newopts, len) == 0 |
| 571 | && (p[len] == ',' || p[len] == '\0')) | 579 | && (p[len] == ',' || p[len] == '\0')) |
| 572 | goto skip; | 580 | goto skip; |
| 573 | p = strchr(p,','); | 581 | p = strchr(p, ','); |
| 574 | if (!p) break; | 582 | if (!p) break; |
| 575 | p++; | 583 | p++; |
| 576 | } | 584 | } |
| 577 | p = xasprintf("%s,%.*s", *oldopts, len, newopts); | 585 | xasprintf_inplace(*oldopts, "%s,%.*s", *oldopts, len, newopts); |
| 578 | free(*oldopts); | ||
| 579 | *oldopts = p; | ||
| 580 | skip: | 586 | skip: |
| 581 | newopts += len; | 587 | newopts += len; |
| 582 | while (*newopts == ',') newopts++; | 588 | while (*newopts == ',') newopts++; |
| @@ -2065,12 +2071,11 @@ static int singlemount(struct mntent *mp, int ignore_busy) | |||
| 2065 | if (!is_prefixed_with(filteropts, ",ip="+1) | 2071 | if (!is_prefixed_with(filteropts, ",ip="+1) |
| 2066 | && !strstr(filteropts, ",ip=") | 2072 | && !strstr(filteropts, ",ip=") |
| 2067 | ) { | 2073 | ) { |
| 2068 | char *dotted, *ip; | 2074 | char *ip; |
| 2069 | // Insert "ip=..." option into options | 2075 | // Insert "ip=..." option into options |
| 2070 | dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa); | 2076 | ip = xmalloc_sockaddr2dotted_noport(&lsa->u.sa); |
| 2071 | if (ENABLE_FEATURE_CLEAN_UP) free(lsa); | 2077 | if (ENABLE_FEATURE_CLEAN_UP) free(lsa); |
| 2072 | ip = xasprintf("ip=%s", dotted); | 2078 | xasprintf_inplace(ip, "ip=%s", ip); |
| 2073 | if (ENABLE_FEATURE_CLEAN_UP) free(dotted); | ||
| 2074 | // Note: IPv6 scoped addresses ("host%iface", see RFC 4007) should be | 2079 | // Note: IPv6 scoped addresses ("host%iface", see RFC 4007) should be |
| 2075 | // handled by libc in getnameinfo() (inside xmalloc_sockaddr2dotted_noport()). | 2080 | // handled by libc in getnameinfo() (inside xmalloc_sockaddr2dotted_noport()). |
| 2076 | // Currently, glibc does not support that (has no NI_NUMERICSCOPE), | 2081 | // Currently, glibc does not support that (has no NI_NUMERICSCOPE), |
