Skip Menu |
 

This queue is for tickets about the Proc-ProcessTable CPAN distribution.

Report information
The Basics
Id: 36283
Status: resolved
Priority: 0/
Queue: Proc-ProcessTable

People
Owner: Nobody in particular
Requestors: radford [...] blackbean.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] Proc-ProcessTable-0.42: ARG_MAX not defined
Date: Thu, 29 May 2008 11:50:23 -0700
To: bug-Proc-ProcessTable [...] rt.cpan.org
From: Jim Radford <radford [...] blackbean.org>
Download (untitled) / with headers
text/plain 544b
When ARG_MAX isn't a constant (on linux it's sometimes dynamically configurable), you need to use sysconf to find its value. -Jim --- Proc-ProcessTable-0.42/os/Linux.h~ 2008-05-29 11:01:16.000000000 -0700 +++ Proc-ProcessTable-0.42/os/Linux.h 2008-05-29 11:36:42.000000000 -0700 @@ -14,6 +14,10 @@ #include <sys/param.h> #include <limits.h> +#ifndef ARG_MAX +#define ARG_MAX sysconf(_SC_ARG_MAX) +#endif + /****************************************/ /* Process state strings that we return */ /****************************************/
From: pinkavaj [...] vscht.cz
There will be probably better define global variable and not call sysconf every time.
Download glibc-2.8-fix.patch
text/x-diff 2.5k
--- os/Linux.c.orig 2008-06-16 18:40:13.000000000 +0200 +++ os/Linux.c 2008-06-16 18:45:53.000000000 +0200 @@ -6,6 +6,8 @@ #define JIFFIES_TO_MICROSECONDS(x) (((x)*1e6)/Hertz) static int init_Hertz_value(void); +int arg_max; + /* Given a path to a /proc/XXX/stat file and a pointer to a procstat struct, fill the struct */ struct procstat* get_procstat( char* path, struct procstat* prs) @@ -82,6 +84,9 @@ if( statfs("/proc", &sfs) == -1 ) return no_proc; + arg_max = sysconf ( _SC_ARG_MAX ); + /* if( arg_max <= 0 ) error checking ... ? but this may never happends */ + /* Get boottime from /proc/stat */ Btime = 0; if( (fp = fopen( "/proc/stat", "r" )) != NULL ){ @@ -129,7 +134,7 @@ char fname[NAME_MAX]; unsigned long start; char state[32]; - char cmndline[ARG_MAX]; + char cmndline[arg_max]; char pctmem[32]; char pctcpu[32]; char cbuf[1024]; @@ -139,10 +144,10 @@ /* used by exec, added by scip */ int size; - char exec[ARG_MAX]; + char exec[arg_max]; /* used by cwd, added by scip */ - char curdir[ARG_MAX]; + char curdir[arg_max]; /* used by the euid/egid stuff, added by scip */ int dummyid, euid, suid, fuid, egid, sgid, fgid, i; @@ -243,12 +248,12 @@ * we could simply not have permissions to read the link * which then simply results in an empty "exec" field. * - * Should have been ARG_MAX not PATH_MAX + * Should have been ARG_MAX (arg_max) not PATH_MAX * * Also... we check the return value of readlink. */ sprintf(pathbuf, "%s%s%s", "/proc/", procdirp->d_name, "/exe"); - if ((size = readlink(pathbuf, exec, ARG_MAX - 1)) >= 0) { + if ((size = readlink(pathbuf, exec, arg_max - 1)) >= 0) { exec[size] = '\0'; format[F_EXEC] = tolower(format[F_EXEC]); } @@ -298,7 +303,7 @@ * get the cwd info, added by scip */ sprintf(pathbuf, "%s%s%s", "/proc/", procdirp->d_name, "/cwd"); - if ((size = readlink(pathbuf, curdir, ARG_MAX - 1)) >= 0) { + if ((size = readlink(pathbuf, curdir, arg_max - 1)) >= 0) { curdir[size] = '\0'; format[F_CWD] = tolower(format[F_CWD]); } @@ -307,9 +312,9 @@ sprintf(pathbuf, "%s%s%s", "/proc/", procdirp->d_name, "/cmdline"); if( (fp = fopen( pathbuf, "r" )) != NULL ) { size_t got; - if( (got = fread(cmndline, sizeof(char), ARG_MAX, fp)) < 1 ) { - strncpy(cmndline, fname, ARG_MAX); - cmndline[ARG_MAX - 1] = '\0'; + if( (got = fread(cmndline, sizeof(char), arg_max, fp)) < 1 ) { + strncpy(cmndline, fname, arg_max); + cmndline[arg_max - 1] = '\0'; } else { size_t i; for(i = 0; i < got; i++)


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.