From c8f7a754ed1e846270a895d9dc2a993d53700ade Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 27 Jul 2018 13:26:21 -0700 Subject: [PATCH 1/4] ip/address: fix bracketing in help message Signed-off-by: Stephen Hemminger --- ip/ipaddress.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index ea8211c1..6c306ab7 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -49,9 +49,9 @@ static void usage(void) __attribute__((noreturn)); static void usage(void) { - if (do_link) { + if (do_link) iplink_usage(); - } + fprintf(stderr, "Usage: ip address {add|change|replace} IFADDR dev IFNAME [ LIFETIME ]\n"); fprintf(stderr, " [ CONFFLAG-LIST ]\n"); fprintf(stderr, " ip address del IFADDR dev IFNAME [mngtmpaddr]\n"); @@ -77,7 +77,7 @@ static void usage(void) fprintf(stderr, " bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan | lowpan |\n"); fprintf(stderr, " gre | gretap | erspan | ip6gre | ip6gretap | ip6erspan | vti |\n"); fprintf(stderr, " nlmon | can | bond_slave | ipvlan | geneve | bridge_slave |\n"); - fprintf(stderr, " hsr | macsec | netdevsim\n"); + fprintf(stderr, " hsr | macsec | netdevsim }\n"); exit(-1); } From 3655f788d3c1b3a081173cbada83726cdbdfe8dd Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Tue, 24 Jul 2018 19:26:38 +0200 Subject: [PATCH 2/4] lib/namespace: avoid double-mounting a /sys This partly reverts 8f0807023d067e2bb585a2ae8da93e59689d10f1, bringing back the umount(/sys) attempt. In a LXC container we're unable to umount the sysfs instance, nor mount a read-write one. We still are able to create a new read-only instance. Nevertheless, it still makes sense to attempt the umount() even though the sysfs is mounted read-only. Otherwise we may end up attempting to mount a sysfs with the same flags as is already mounted, resulting in an EBUSY error (meaning "Already mounted"). Perhaps this is not a very likely scenario in real world, but we hit it in NetworkManager test suite and makes netns_switch() somewhat more robust. It also fixes the case, when /sys wasn't mounted at all. Signed-off-by: Lubomir Rintel Signed-off-by: Stephen Hemminger --- lib/namespace.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/namespace.c b/lib/namespace.c index 43e0fe34..06ae0a48 100644 --- a/lib/namespace.c +++ b/lib/namespace.c @@ -82,19 +82,13 @@ int netns_switch(char *name) /* Mount a version of /sys that describes the network namespace */ - if (statvfs("/sys", &fsstat) < 0) { - fprintf(stderr, "could not stat /sys (not mounted?): %s\n",strerror(errno)); - return -1; - } - if (fsstat.f_flag & ST_RDONLY) { - /* If /sys is not writable (e.g. in a container), we can't - * unmount the old /sys instance, but we can still mount a new - * read-only instance over it. */ - mountflags = MS_RDONLY; - } else { - if (umount2("/sys", MNT_DETACH) < 0) { - fprintf(stderr, "umount of /sys failed: %s\n", strerror(errno)); - return -1; + if (umount2("/sys", MNT_DETACH) < 0) { + /* If this fails, perhaps there wasn't a sysfs instance mounted. Good. */ + if (statvfs("/sys", &fsstat) == 0) { + /* We couldn't umount the sysfs, we'll attempt to overlay it. + * A read-only instance can't be shadowed with a read-write one. */ + if (fsstat.f_flag & ST_RDONLY) + mountflags = MS_RDONLY; } } if (mount(name, "/sys", "sysfs", mountflags, NULL) < 0) { From d66fdfda71e4a30c1ca0ddb7b1a048bef30fe79e Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 8 Aug 2018 09:23:48 -0700 Subject: [PATCH 3/4] tc: flush after each command in batch mode After each command flush output. Signed-off-by: Stephen Hemminger --- tc/tc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tc/tc.c b/tc/tc.c index 62d54186..3bb5910f 100644 --- a/tc/tc.c +++ b/tc/tc.c @@ -402,6 +402,7 @@ static int batch(const char *name) err = do_cmd(largc, largv, tail == NULL ? NULL : tail->buf, tail == NULL ? 0 : sizeof(tail->buf)); + fflush(stdout); if (err != 0) { fprintf(stderr, "Command failed %s:%d\n", name, cmdlineno - 1); From d56c7dde9dfb34794e983e7caf47a7ad3cf89579 Mon Sep 17 00:00:00 2001 From: Matteo Croce Date: Fri, 3 Aug 2018 19:49:33 +0200 Subject: [PATCH 4/4] ip link: don't stop batch processing When 'ip link show dev DEVICE' is processed in a batch mode, ip exits and stop processing further commands. This because ipaddr_list_flush_or_save() calls exit() to avoid printing the link information twice. Replace the exit with a classic goto out instruction. Signed-off-by: Matteo Croce Signed-off-by: Stephen Hemminger --- ip/ipaddress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 6c306ab7..b7b78f6e 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -1920,7 +1920,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action) exit(1); } delete_json_obj(); - exit(0); + goto out; } if (filter.family != AF_PACKET) {