Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom procfs path using ENV variable #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions netstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ int flag_ver = 0;
int flag_l2cap = 0;
int flag_rfcomm = 0;
int flag_selinux = 0;
char *path_proc = NULL;

FILE *procinfo;

Expand Down Expand Up @@ -268,10 +269,10 @@ static char prg_cache_loaded = 0;
#define LINE_MAX 4096
#endif

#define PATH_PROC "/proc"
#define DEFAULT_PATH_PROC "/proc"
#define PATH_FD_SUFF "fd"
#define PATH_FD_SUFFl strlen(PATH_FD_SUFF)
#define PATH_PROC_X_FD PATH_PROC "/%s/" PATH_FD_SUFF
#define PATH_PROC_X_FD "%s" "/%s/" PATH_FD_SUFF
#define PATH_CMDLINE "cmdline"
#define PATH_CMDLINEl strlen(PATH_CMDLINE)

Expand Down Expand Up @@ -411,14 +412,14 @@ static void prg_cache_load(void)
if (prg_cache_loaded || !flag_prg) return;
prg_cache_loaded = 1;
cmdlbuf[sizeof(cmdlbuf) - 1] = '\0';
if (!(dirproc=opendir(PATH_PROC))) goto fail;
if (!(dirproc=opendir(path_proc))) goto fail;
while (errno = 0, direproc = readdir(dirproc)) {
for (cs = direproc->d_name; *cs; cs++)
if (!isdigit(*cs))
break;
if (*cs)
continue;
procfdlen = snprintf(line,sizeof(line),PATH_PROC_X_FD,direproc->d_name);
procfdlen = snprintf(line,sizeof(line),PATH_PROC_X_FD,path_proc,direproc->d_name);
if (procfdlen <= 0 || procfdlen >= sizeof(line) - 5)
continue;
errno = 0;
Expand Down Expand Up @@ -2070,6 +2071,11 @@ int main
#endif
getroute_init(); /* Set up AF routing support */

path_proc = getenv("PATH_PROC");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that some kind of convention standard env for this? If its net tools specific, maybe have a NETTOOLS_PROCPATH instead?

if ( path_proc == NULL ) {
path_proc = DEFAULT_PATH_PROC;
}

afname[0] = '\0';
while ((i = getopt_long(argc, argv, "A:CFMacdeghilnNoprsStuUvVWw2fx64?Z", longopts, &lop)) != EOF)
switch (i) {
Expand Down