Added support for command line arguments (glibtop_proc_args).
This commit is contained in:
@@ -69,6 +69,11 @@ glibtop_get_proc_data_proc_kernel_s (glibtop *server,
|
|||||||
libgtop_proc_kernel_t *proc_kernel,
|
libgtop_proc_kernel_t *proc_kernel,
|
||||||
pid_t pid);
|
pid_t pid);
|
||||||
|
|
||||||
|
int
|
||||||
|
glibtop_get_proc_data_proc_args_s (glibtop *server, pid_t pid,
|
||||||
|
char *result, size_t max_len);
|
||||||
|
|
||||||
|
|
||||||
END_LIBGTOP_DECLS
|
END_LIBGTOP_DECLS
|
||||||
|
|
||||||
#endif __GLIBTOP_PRIVATE_H__
|
#endif __GLIBTOP_PRIVATE_H__
|
||||||
|
@@ -26,7 +26,10 @@
|
|||||||
#include <glibtop/xmalloc.h>
|
#include <glibtop/xmalloc.h>
|
||||||
#include <glibtop/procargs.h>
|
#include <glibtop/procargs.h>
|
||||||
|
|
||||||
static const unsigned long _glibtop_sysdeps_proc_args = 0;
|
#include <glibtop_private.h>
|
||||||
|
|
||||||
|
static const unsigned long _glibtop_sysdeps_proc_args =
|
||||||
|
(1 << GLIBTOP_PROC_ARGS_SIZE);
|
||||||
|
|
||||||
/* Init function. */
|
/* Init function. */
|
||||||
|
|
||||||
@@ -42,6 +45,40 @@ char *
|
|||||||
glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
|
glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
|
||||||
pid_t pid, unsigned max_len)
|
pid_t pid, unsigned max_len)
|
||||||
{
|
{
|
||||||
|
char buffer [BUFSIZ];
|
||||||
|
char *retval = NULL, *ptr;
|
||||||
|
size_t total;
|
||||||
|
int ret;
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_args));
|
memset (buf, 0, sizeof (glibtop_proc_args));
|
||||||
|
|
||||||
|
if (max_len > BUFSIZ)
|
||||||
|
retval = ptr = glibtop_malloc_r (server, max_len+1);
|
||||||
|
else
|
||||||
|
ptr = buffer;
|
||||||
|
|
||||||
|
if (!max_len)
|
||||||
|
max_len = BUFSIZ;
|
||||||
|
|
||||||
|
ret = glibtop_get_proc_data_proc_args_s (server, pid, ptr, max_len);
|
||||||
|
if (!ret) {
|
||||||
|
if (!retval) glibtop_free_r (server, retval);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
total = ret;
|
||||||
|
|
||||||
|
if (retval) {
|
||||||
|
retval = glibtop_realloc_r (server, retval, total+1);
|
||||||
|
} else {
|
||||||
|
retval = glibtop_malloc_r (server, total+1);
|
||||||
|
memcpy (retval, buffer, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
retval [total] = 0;
|
||||||
|
|
||||||
|
buf->size = total;
|
||||||
|
buf->flags = _glibtop_sysdeps_proc_args;
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
@@ -146,3 +146,18 @@ glibtop_get_proc_data_proc_kernel_s (glibtop *server,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
glibtop_get_proc_data_proc_args_s (glibtop *server, pid_t pid,
|
||||||
|
char *result, size_t max_len)
|
||||||
|
{
|
||||||
|
int name [3] = { CTL_LIBGTOP, LIBGTOP_PROC_ARGS, pid };
|
||||||
|
size_t size = max_len;
|
||||||
|
|
||||||
|
if (sysctl (name, 3, result, &size, NULL, 0)) {
|
||||||
|
glibtop_warn_io_r (server, "sysctl (libgtop/proc_args)");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user