diff --git a/netstat.c b/netstat.c index 7ca074e..90e33d8 100644 --- a/netstat.c +++ b/netstat.c @@ -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; @@ -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) @@ -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; @@ -2070,6 +2071,11 @@ int main #endif getroute_init(); /* Set up AF routing support */ + path_proc = getenv("PATH_PROC"); + 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) {