wg: only error on wg show if all interfaces fail

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2018-07-08 19:46:05 +02:00
parent 4367cd0d3d
commit 4502f4f2b7
1 changed files with 4 additions and 1 deletions

View File

@ -14,6 +14,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <time.h> #include <time.h>
#include <netdb.h> #include <netdb.h>
@ -394,12 +395,13 @@ int show_main(int argc, char *argv[])
perror("Unable to list interfaces"); perror("Unable to list interfaces");
return 1; return 1;
} }
ret = !!*interfaces;
interface = interfaces; interface = interfaces;
for (size_t len = 0; (len = strlen(interface)); interface += len + 1) { for (size_t len = 0; (len = strlen(interface)); interface += len + 1) {
struct wgdevice *device = NULL; struct wgdevice *device = NULL;
if (ipc_get_device(&device, interface) < 0) { if (ipc_get_device(&device, interface) < 0) {
perror("Unable to access interface"); fprintf(stderr, "Unable to access interface %s: %s\n", interface, strerror(errno));
continue; continue;
} }
if (argc == 3) { if (argc == 3) {
@ -414,6 +416,7 @@ int show_main(int argc, char *argv[])
printf("\n"); printf("\n");
} }
free_wgdevice(device); free_wgdevice(device);
ret = 0;
} }
free(interfaces); free(interfaces);
} else if (!strcmp(argv[1], "interfaces")) { } else if (!strcmp(argv[1], "interfaces")) {