diff --git a/atop.c b/atop.c index de880549..8ce6671f 100644 --- a/atop.c +++ b/atop.c @@ -254,6 +254,7 @@ static struct { { "atopsarflags", do_atopsarflags, 0, }, { "perfevents", do_perfevents, 0, }, { "pacctdir", do_pacctdir, 1, }, + { "netns", do_netns, 1, }, }; /* diff --git a/photosyst.c b/photosyst.c index 76030496..29e6b7f8 100644 --- a/photosyst.c +++ b/photosyst.c @@ -3120,3 +3120,36 @@ int getothernetns(struct shmbuf *shmp) { exit(0); } + +void +do_netns(char *name, char *val) +{ + char *pernetns, *validnetns; + int ns = 0; + struct stat nsstat; + + if ( strlen(val) == 0 ) + return; + + validnetns = malloc( (MAXNETNS - 1) * NETNSNAMELEN * sizeof(char) ); + strncpy(validnetns, val, (MAXNETNS - 1) * NETNSNAMELEN); + + /* split netns by blank space */ + pernetns = strtok(validnetns, " "); + while (pernetns) + { + /* valid if this file exits, and later setns() will prove the netns is available */ + if ( stat(pernetns, &nsstat) ) + { + fprintf(stderr, "netns %s stat failed, errno is %d\n", pernetns, errno); + pernetns = strtok(NULL, " "); + continue; + } + + strncpy(othernetns[ns], pernetns, sizeof(othernetns[ns])); + if (++ns >= MAXNETNS - 1) + break; + pernetns = strtok(NULL, " "); + } + free(validnetns); +} diff --git a/photosyst.h b/photosyst.h index 5bcc40be..82ea62bf 100644 --- a/photosyst.h +++ b/photosyst.h @@ -468,6 +468,7 @@ void photosyst (struct sstat *); void deviatsyst(struct sstat *, struct sstat *, struct sstat *, long); void totalsyst (char, struct sstat *, struct sstat *); void do_perfevents(char *, char *); +void do_netns(char *, char *); #define PHYNETMAX 8 struct snmp {