Skip to content

Commit

Permalink
Add netns configuration for /etc/atoprc
Browse files Browse the repository at this point in the history
The default rule is splitting netns by blank space.
And make sure the netns path exits.

Signed-off-by: Fei Li <[email protected]>
  • Loading branch information
ShirleyFei committed Mar 13, 2023
1 parent befa9a2 commit 63fc86c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions atop.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ static struct {
{ "atopsarflags", do_atopsarflags, 0, },
{ "perfevents", do_perfevents, 0, },
{ "pacctdir", do_pacctdir, 1, },
{ "netns", do_netns, 1, },
};

/*
Expand Down
33 changes: 33 additions & 0 deletions photosyst.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions photosyst.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 63fc86c

Please sign in to comment.