--- 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++)