From 339e1f4557a89739e56ef2e4bf81ad22fcaadd35 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Sun, 19 Dec 1999 14:37:49 +0000 Subject: [PATCH] Removed. (glibtop_get_proc_args_*): This now takes a `glibtop_array' 1999-12-12 Martin Baulig * include/glibtop/procargs.h (glibtop_proc_args): Removed. (glibtop_get_proc_args_*): This now takes a `glibtop_array' parameter instead of a `glibtop_proc_args one and returns a `char **'. --- ChangeLog | 6 +++++ features.def | 2 +- include/glibtop/compat_10.h | 8 ++++++ include/glibtop/procargs.h | 2 +- include/glibtop/union.h | 2 +- lib/lib.pl | 2 +- src/daemon/main.c | 2 +- sysdeps/kernel/procargs.c | 54 +++++++++++++++++++------------------ 8 files changed, 47 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2486d3da..c132ab91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +1999-12-12 Martin Baulig + + * include/glibtop/procargs.h (glibtop_proc_args): Removed. + (glibtop_get_proc_args_*): This now takes a `glibtop_array' parameter + instead of a `glibtop_proc_args one and returns a `char **'. + 1999-12-13 Martin Baulig * configure.in (LIBGTOP_LIBS): Put `-lgtop' after `-lgtop_common'. diff --git a/features.def b/features.def index 4cd6d704..92ba9537 100644 --- a/features.def +++ b/features.def @@ -14,7 +14,7 @@ retval|proc_time|long(start_time,rtime,utime,stime,cutime,cstime,timeout,it_real retval|proc_signal|ulong(signal[2],blocked[2],sigignore[2],sigcatch[2])|pid_t(pid) retval|proc_kernel|ulong(k_flags,min_flt,maj_flt,cmin_flt,cmaj_flt,kstk_esp,kstk_eip,nwchan):string(wchan)|pid_t(pid) retval|proc_segment|ulong(text_rss,shlib_rss,data_rss,stack_rss,dirty_size,start_code,end_code,start_data,end_data,start_brk,end_brk,start_stack,start_mmap,arg_start,arg_end,env_start,env_end)|pid_t(pid) -char *|proc_args|ulong(size)|pid_t(pid):unsigned(max_len) +pointer(string)|proc_args|array|pid_t(pid) array(glibtop_map_entry)|proc_map|array|pid_t(pid) array(glibtop_mountentry)|@mountlist|array|int(all_fs) retval|@fsusage|ulong(blocks,bfree,bavail,files,ffree)|string(mount_dir) diff --git a/include/glibtop/compat_10.h b/include/glibtop/compat_10.h index 4dfaf1c4..df8ffb04 100644 --- a/include/glibtop/compat_10.h +++ b/include/glibtop/compat_10.h @@ -51,6 +51,14 @@ typedef struct _glibtop_array glibtop_proclist; typedef struct _glibtop_array glibtop_mountlist; +/* glibtop_proc_args */ + +#define GLIBTOP_PROC_ARGS_SIZE 0 + +#define GLIBTOP_MAX_PROC_ARGS 1 + +typedef struct _glibtop_array glibtop_proc_args; + /* glibtop_proc_map */ #define GLIBTOP_PROC_MAP_NUMBER GLIBTOP_ARRAY_NUMBER diff --git a/include/glibtop/procargs.h b/include/glibtop/procargs.h index c14a915d..f7624cb9 100644 --- a/include/glibtop/procargs.h +++ b/include/glibtop/procargs.h @@ -34,7 +34,7 @@ BEGIN_LIBGTOP_DECLS -#define glibtop_get_proc_args(proc_args) glibtop_get_proc_args_l(glibtop_global_server, pid) +#define glibtop_get_proc_args(array,pid) glibtop_get_proc_args_l(glibtop_global_server, array, pid) #if GLIBTOP_SUID_PROC_ARGS #define glibtop_get_proc_args_r glibtop_get_proc_args_p diff --git a/include/glibtop/union.h b/include/glibtop/union.h index 68abdaf1..16ca9b5c 100644 --- a/include/glibtop/union.h +++ b/include/glibtop/union.h @@ -76,7 +76,7 @@ union _glibtop_union glibtop_proc_signal proc_signal; glibtop_proc_kernel proc_kernel; glibtop_proc_segment proc_segment; - glibtop_proc_args proc_args; + glibtop_array proc_args; glibtop_array proc_map; glibtop_array mountlist; glibtop_fsusage fsusage; diff --git a/lib/lib.pl b/lib/lib.pl index 320bf5c8..3f24b83e 100755 --- a/lib/lib.pl +++ b/lib/lib.pl @@ -113,7 +113,7 @@ sub output { } if ($retval =~ /^(array|pointer)\((.*)\)$/) { - $retval = "$2 *"; + $retval = ($2 eq 'string') ? 'char **' : "$2 *"; } $check_server_code = "\n"; diff --git a/src/daemon/main.c b/src/daemon/main.c index 3744b0b1..c5f392a4 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -164,7 +164,7 @@ handle_parent_connection (int s) memcpy (&pid, parameter, sizeof (pid_t)); ptr = glibtop_get_proc_args_l (server, &resp->u.data.proc_args, - pid, 0); + pid); do_output (s, resp, _offset_data (proc_args), ptr ? resp->u.data.proc_args.size+1 : 0, ptr, (ptr != NULL) ? 0 : -1); diff --git a/sysdeps/kernel/procargs.c b/sysdeps/kernel/procargs.c index 3e20edcd..08fc6163 100644 --- a/sysdeps/kernel/procargs.c +++ b/sysdeps/kernel/procargs.c @@ -29,7 +29,7 @@ #include static const unsigned long _glibtop_sysdeps_proc_args = -(1L << GLIBTOP_PROC_ARGS_SIZE); +(1L << GLIBTOP_ARRAY_NUMBER) + (1L << GLIBTOP_ARRAY_SIZE); /* Init function. */ @@ -43,44 +43,46 @@ glibtop_init_proc_args_s (glibtop *server) /* Provides detailed information about a process. */ -char * -glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf, - pid_t pid, unsigned max_len) +char ** +glibtop_get_proc_args_s (glibtop *server, glibtop_array *array, pid_t pid) { - char buffer [BUFSIZ]; - char *retval = NULL, *ptr; - size_t total; - int ret; + char *ptr = NULL, *pos, **ptrlist; + size_t count = 0, max_len, total; + int i, ret; - memset (buf, 0, sizeof (glibtop_proc_args)); + memset (array, 0, sizeof (glibtop_array)); - if (max_len > BUFSIZ) - retval = ptr = glibtop_malloc_r (server, max_len+1); - else - ptr = buffer; - - if (!max_len) - max_len = BUFSIZ; + max_len = PAGE_SIZE; + ptr = glibtop_malloc_r (server, max_len + 1); ret = glibtop_get_proc_data_proc_args_s (server, pid, ptr, max_len); if (ret < 0) { - if (!retval) glibtop_free_r (server, retval); + glibtop_free_r (server, ptr); return NULL; } total = ret; + ptr [total] = '\0'; - if (retval) { - retval = glibtop_realloc_r (server, retval, total+1); - } else { - retval = glibtop_malloc_r (server, total+1); - memcpy (retval, buffer, total); + for (i = 0; i <= total; i++) { + if (ptr [i]) continue; + count++; } - retval [total] = 0; + ptrlist = glibtop_calloc_r (server, count+1, sizeof (char *)); - buf->size = total; - buf->flags = _glibtop_sysdeps_proc_args; + for (i = 0, pos = ptr; i < count; i++) { + ptrlist [i] = glibtop_strdup_r (server, pos); + pos += strlen (pos) + 1; + } - return retval; + ptrlist [count] = NULL; + + glibtop_free_r (server, ptr); + + array->number = count; + array->size = sizeof (char *); + array->flags = _glibtop_sysdeps_proc_args; + + return ptrlist; }