Reflect latest interface changes.
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
#include <glibtop/procargs.h>
|
#include <glibtop/procargs.h>
|
||||||
|
|
||||||
static const unsigned long _glibtop_sysdeps_proc_args =
|
static const unsigned long _glibtop_sysdeps_proc_args =
|
||||||
(1L << GLIBTOP_PROC_ARGS_SIZE);
|
(1L << GLIBTOP_ARRAY_NUMBER) + (1L << GLIBTOP_ARRAY_SIZE);
|
||||||
|
|
||||||
/* Init function. */
|
/* Init function. */
|
||||||
|
|
||||||
@@ -43,55 +43,64 @@ glibtop_init_proc_args_s (glibtop *server)
|
|||||||
|
|
||||||
/* Provides detailed information about a process. */
|
/* Provides detailed information about a process. */
|
||||||
|
|
||||||
char *
|
char **
|
||||||
glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
|
glibtop_get_proc_args_s (glibtop *server, glibtop_array *array, pid_t pid)
|
||||||
pid_t pid, unsigned max_len)
|
|
||||||
{
|
{
|
||||||
char fn [BUFSIZ], buffer [BUFSIZ];
|
char fn [BUFSIZ], buffer [BUFSIZ], *ptr = NULL, *pos, **ptrlist;
|
||||||
int cmdline, len, total = 0;
|
size_t count = 0, max_len, total, len;
|
||||||
char *retval = NULL;
|
int cmdline, i;
|
||||||
|
|
||||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_ARGS, 0);
|
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_ARGS, 0);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_args));
|
memset (array, 0, sizeof (glibtop_array));
|
||||||
|
|
||||||
|
max_len = BUFSIZ;
|
||||||
|
ptr = glibtop_malloc_r (server, max_len + 1);
|
||||||
|
|
||||||
sprintf (fn, "/proc/%d/cmdline", pid);
|
sprintf (fn, "/proc/%d/cmdline", pid);
|
||||||
|
|
||||||
cmdline = open (fn, O_RDONLY);
|
cmdline = open (fn, O_RDONLY);
|
||||||
if (cmdline < 0) return NULL;
|
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) {
|
while (1) {
|
||||||
len = read (cmdline, buffer, BUFSIZ-1);
|
len = read (cmdline, buffer, BUFSIZ-1);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
glibtop_free_r (server, retval);
|
glibtop_free_r (server, ptr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
retval = glibtop_realloc_r (server, retval, total+len+1);
|
ptr = glibtop_realloc_r (server, ptr, total+len+1);
|
||||||
memcpy (retval+total, buffer, len);
|
memcpy (ptr+total, buffer, len);
|
||||||
*(retval+total+len) = 0;
|
*(ptr+total+len) = 0;
|
||||||
total += len;
|
total += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
close (cmdline);
|
close (cmdline);
|
||||||
|
|
||||||
buf->size = total;
|
ptr [total] = '\0';
|
||||||
buf->flags = _glibtop_sysdeps_proc_args;
|
|
||||||
|
for (i = 0; i <= total; i++) {
|
||||||
return retval;
|
if (ptr [i]) continue;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptrlist = glibtop_calloc_r (server, count+1, sizeof (char *));
|
||||||
|
|
||||||
|
for (i = 0, pos = ptr; i < count; i++) {
|
||||||
|
ptrlist [i] = glibtop_strdup_r (server, pos);
|
||||||
|
pos += strlen (pos) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptrlist [count] = NULL;
|
||||||
|
|
||||||
|
glibtop_free_r (server, ptr);
|
||||||
|
|
||||||
|
array->number = count;
|
||||||
|
array->size = sizeof (char *);
|
||||||
|
array->flags = _glibtop_sysdeps_proc_args;
|
||||||
|
|
||||||
|
return ptrlist;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user