Skip to content

Commit 63fc86c

Browse files
committed
Add netns configuration for /etc/atoprc
The default rule is splitting netns by blank space. And make sure the netns path exits. Signed-off-by: Fei Li <[email protected]>
1 parent befa9a2 commit 63fc86c

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

atop.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ static struct {
254254
{ "atopsarflags", do_atopsarflags, 0, },
255255
{ "perfevents", do_perfevents, 0, },
256256
{ "pacctdir", do_pacctdir, 1, },
257+
{ "netns", do_netns, 1, },
257258
};
258259

259260
/*

photosyst.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,3 +3120,36 @@ int getothernetns(struct shmbuf *shmp) {
31203120

31213121
exit(0);
31223122
}
3123+
3124+
void
3125+
do_netns(char *name, char *val)
3126+
{
3127+
char *pernetns, *validnetns;
3128+
int ns = 0;
3129+
struct stat nsstat;
3130+
3131+
if ( strlen(val) == 0 )
3132+
return;
3133+
3134+
validnetns = malloc( (MAXNETNS - 1) * NETNSNAMELEN * sizeof(char) );
3135+
strncpy(validnetns, val, (MAXNETNS - 1) * NETNSNAMELEN);
3136+
3137+
/* split netns by blank space */
3138+
pernetns = strtok(validnetns, " ");
3139+
while (pernetns)
3140+
{
3141+
/* valid if this file exits, and later setns() will prove the netns is available */
3142+
if ( stat(pernetns, &nsstat) )
3143+
{
3144+
fprintf(stderr, "netns %s stat failed, errno is %d\n", pernetns, errno);
3145+
pernetns = strtok(NULL, " ");
3146+
continue;
3147+
}
3148+
3149+
strncpy(othernetns[ns], pernetns, sizeof(othernetns[ns]));
3150+
if (++ns >= MAXNETNS - 1)
3151+
break;
3152+
pernetns = strtok(NULL, " ");
3153+
}
3154+
free(validnetns);
3155+
}

photosyst.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ void photosyst (struct sstat *);
468468
void deviatsyst(struct sstat *, struct sstat *, struct sstat *, long);
469469
void totalsyst (char, struct sstat *, struct sstat *);
470470
void do_perfevents(char *, char *);
471+
void do_netns(char *, char *);
471472

472473
#define PHYNETMAX 8
473474
struct snmp {

0 commit comments

Comments
 (0)