Skip to content

Commit 3b76537

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 c65af85 commit 3b76537

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
@@ -3118,3 +3118,36 @@ int getothernetns(struct shmbuf *shmp) {
31183118

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

photosyst.h

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

473474
#define PHYNETMAX 8
474475
struct snmp {

0 commit comments

Comments
 (0)