diff --git a/ChangeLog b/ChangeLog index f7f66678..ad774abc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +1998-12-09 Martin Baulig + + * include/glibtop/procargs.h (glibtop_get_proc_args): Make the + return value a `char *' instead of a `const char *'. + 1998-12-09 Martin Baulig * LIBGTOP-VERSION: Set version number to 0.29.1. diff --git a/examples/first.c b/examples/first.c index 9ad1ec5f..aabf7884 100644 --- a/examples/first.c +++ b/examples/first.c @@ -44,8 +44,8 @@ main (int argc, char *argv []) glibtop_sysdeps sysdeps; unsigned c, method, count, port, i, *ptr; char buffer [BUFSIZ]; - const char *args; pid_t pid, ppid; + char *args; count = PROFILE_COUNT; @@ -334,6 +334,11 @@ main (int argc, char *argv []) args = glibtop_get_proc_args (&data.proc_args, pid, 0); + for (i = 0; i < data.proc_args.size; i++) { + if (args [i]) continue; + args [i] = '|'; + } + printf ("Proc_Args PID %5d (0x%08lx): %lu - '%s'\n", (int) pid, (unsigned long) data.proc_args.flags, (unsigned long) data.proc_args.size, @@ -439,6 +444,11 @@ main (int argc, char *argv []) args = glibtop_get_proc_args (&data.proc_args, ppid, 0); + for (i = 0; i < data.proc_args.size; i++) { + if (args [i]) continue; + args [i] = '|'; + } + printf ("Proc_Args PID %5d (0x%08lx): %lu - '%s'\n", (int) ppid, (unsigned long) data.proc_args.flags, (unsigned long) data.proc_args.size, @@ -545,6 +555,11 @@ main (int argc, char *argv []) args = glibtop_get_proc_args (&data.proc_args, 1, 0); + for (i = 0; i < data.proc_args.size; i++) { + if (args [i]) continue; + args [i] = '|'; + } + printf ("Proc_Args PID %5d (0x%08lx): %lu - '%s'\n", 1, (unsigned long) data.proc_args.flags, (unsigned long) data.proc_args.size, diff --git a/examples/second.c b/examples/second.c index faa658fa..e997ec46 100644 --- a/examples/second.c +++ b/examples/second.c @@ -36,13 +36,15 @@ output (pid_t pid) { glibtop_union data; char *args; + unsigned i; + #if HAVE_LIBGTOP_SMP unsigned long total; double p_total, p_utime, p_stime; double b_total, b_utime, b_stime; double s_total, s_utime, s_stime; double my_utime, my_stime; - int ncpu, i; + int ncpu; #endif printf ("\n"); @@ -138,6 +140,11 @@ output (pid_t pid) args = glibtop_get_proc_args (&data.proc_args, pid, 0); + for (i = 0; i < data.proc_args.size; i++) { + if (args [i]) continue; + args [i] = '|'; + } + printf ("Proc_Args PID %5d (0x%08lx): %lu - '%s'\n", (int) pid, (unsigned long) data.proc_args.flags, (unsigned long) data.proc_args.size, diff --git a/features.def b/features.def index a5645ed5..eedaf73a 100644 --- a/features.def +++ b/features.def @@ -14,7 +14,7 @@ void|proc_time|long(start_time,rtime,utime,stime,cutime,cstime,timeout,it_real_v void|proc_signal|ulong(signal[2],blocked[2],sigignore[2],sigcatch[2])|pid_t(pid) void|proc_kernel|ulong(k_flags,min_flt,maj_flt,cmin_flt,cmaj_flt,kstk_esp,kstk_eip,nwchan):str(wchan)|pid_t(pid) void|proc_segment|ulong(text_rss,shlib_rss,data_rss,stack_rss,dirty_size,start_code,end_code,start_stack)|pid_t(pid) -const char *|proc_args|ulong(size)|pid_t(pid):unsigned(max_len) +char *|proc_args|ulong(size)|pid_t(pid):unsigned(max_len) glibtop_map_entry *|proc_map|ulong(number,size,total)|pid_t(pid) glibtop_mountentry *|@mountlist|ulong(number,size,total)|int(all_fs) void|@fsusage|ulong(blocks,bfree,bavail,files,ffree)|string|mount_dir diff --git a/include/glibtop/procargs.h b/include/glibtop/procargs.h index 1ec6f5b7..0c68ac4c 100644 --- a/include/glibtop/procargs.h +++ b/include/glibtop/procargs.h @@ -47,14 +47,14 @@ struct _glibtop_proc_args #define glibtop_get_proc_args_r glibtop_get_proc_args_s #endif -extern const char *glibtop_get_proc_args_l __P((glibtop *, glibtop_proc_args *, pid_t, unsigned)); +extern char *glibtop_get_proc_args_l __P((glibtop *, glibtop_proc_args *, pid_t, unsigned)); #if GLIBTOP_SUID_PROC_ARGS extern void glibtop_init_proc_args_p __P((glibtop *)); -extern const char *glibtop_get_proc_args_p __P((glibtop *, glibtop_proc_args *, pid_t, unsigned)); +extern char *glibtop_get_proc_args_p __P((glibtop *, glibtop_proc_args *, pid_t, unsigned)); #else extern void glibtop_init_proc_args_s __P((glibtop *)); -extern const char *glibtop_get_proc_args_s __P((glibtop *, glibtop_proc_args *, pid_t, unsigned)); +extern char *glibtop_get_proc_args_s __P((glibtop *, glibtop_proc_args *, pid_t, unsigned)); #endif #ifdef GLIBTOP_NAMES diff --git a/sysdeps/freebsd/procargs.c b/sysdeps/freebsd/procargs.c index 542885d9..8312e474 100644 --- a/sysdeps/freebsd/procargs.c +++ b/sysdeps/freebsd/procargs.c @@ -43,7 +43,7 @@ glibtop_init_proc_args_p (glibtop *server) /* Provides detailed information about a process. */ -const char * +char * glibtop_get_proc_args_p (glibtop *server, glibtop_proc_args *buf, pid_t pid, unsigned max_len) { diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog index 2e0b8771..bea7a9c0 100644 --- a/sysdeps/linux/ChangeLog +++ b/sysdeps/linux/ChangeLog @@ -1,3 +1,8 @@ +1998-12-09 Martin Baulig + + * procargs.c (glibtop_get_proc_args_s): Added implementation + for this function. + 1998-12-03 Martin Baulig * netload.c: No longer include , but use diff --git a/sysdeps/linux/procargs.c b/sysdeps/linux/procargs.c index dea49cb4..a62161f2 100644 --- a/sysdeps/linux/procargs.c +++ b/sysdeps/linux/procargs.c @@ -24,7 +24,8 @@ #include #include -static const unsigned long _glibtop_sysdeps_proc_args = 0; +static const unsigned long _glibtop_sysdeps_proc_args = +(1 << GLIBTOP_PROC_ARGS_SIZE); /* Init function. */ @@ -36,10 +37,55 @@ glibtop_init_proc_args_s (glibtop *server) /* Provides detailed information about a process. */ -const char * +char * glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf, pid_t pid, unsigned max_len) { + char fn [BUFSIZ], buffer [BUFSIZ]; + int cmdline, len, total = 0; + char *retval = NULL; + + glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_ARGS, 0); + memset (buf, 0, sizeof (glibtop_proc_args)); - return NULL; + + sprintf (fn, "/proc/%d/cmdline", pid); + + cmdline = open (fn, O_RDONLY); + if (cmdline < 0) return NULL; + + if (max_len) { + retval = glibtop_malloc_r (server, max_len+1); + + len = read (cmdline, retval, max_len); + if (len < 0) { + glibtop_free_r (server, retval); + return NULL; + } + + return retval; + } + + while (1) { + len = read (cmdline, buffer, BUFSIZ-1); + if (len < 0) { + glibtop_free_r (server, retval); + return NULL; + } + + if (len == 0) + break; + + retval = glibtop_realloc_r (server, retval, total+len+1); + memcpy (retval+total, buffer, len); + *(retval+total+len) = 0; + total += len; + } + + close (cmdline); + + buf->size = total; + buf->flags = _glibtop_sysdeps_proc_args; + + return retval; } diff --git a/sysdeps/stub/procargs.c b/sysdeps/stub/procargs.c index dea49cb4..11e350c0 100644 --- a/sysdeps/stub/procargs.c +++ b/sysdeps/stub/procargs.c @@ -36,7 +36,7 @@ glibtop_init_proc_args_s (glibtop *server) /* Provides detailed information about a process. */ -const char * +char * glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf, pid_t pid, unsigned max_len) { diff --git a/sysdeps/stub_suid/procargs.c b/sysdeps/stub_suid/procargs.c index 7d6b7764..ab527d48 100644 --- a/sysdeps/stub_suid/procargs.c +++ b/sysdeps/stub_suid/procargs.c @@ -36,7 +36,7 @@ glibtop_init_proc_args_p (glibtop *server) /* Provides detailed information about a process. */ -const char * +char * glibtop_get_proc_args_p (glibtop *server, glibtop_proc_args *buf, pid_t pid, unsigned max_len) {