diff --git a/sysdeps/solaris/procargs.c b/sysdeps/solaris/procargs.c index 7e0bcec5..8dd11292 100644 --- a/sysdeps/solaris/procargs.c +++ b/sysdeps/solaris/procargs.c @@ -26,58 +26,70 @@ #include #include +#include + static const unsigned long _glibtop_sysdeps_proc_args = -(1L << GLIBTOP_PROC_ARGS_SIZE); +(1L << GLIBTOP_ARRAY_SIZE) + (1L << GLIBTOP_ARRAY_NUMBER); /* Init function. */ int glibtop_init_proc_args_s (glibtop *server) { - server->sysdeps.proc_args = _glibtop_sysdeps_proc_args; + server->sysdeps.proc_args = _glibtop_sysdeps_proc_args; + + return 0; } /* 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) { #ifdef HAVE_PROCFS_H - struct psinfo pinfo; + struct psinfo pinfo; #else - struct prpsinfo pinfo; + struct prpsinfo pinfo; #endif - int len, i; - char *ret, *p; + int retval, len, i, count; + char *ret, *p, **ptrlist; - memset (buf, 0, sizeof (glibtop_proc_args)); + memset (array, 0, sizeof (glibtop_array)); - if(glibtop_get_proc_data_psinfo_s(server, &pinfo, pid)) - return NULL; + retval = glibtop_get_proc_data_psinfo_s(server, &pinfo, pid); + if (retval) { + server->glibtop_errno = retval; + return NULL; + } - for(len = 0; len < PRARGSZ; ++len) - if(!(pinfo.pr_psargs[len])) - break; - if(max_len) - { - ret = glibtop_malloc_r(server, max_len + 1); - if(max_len < len) - len = max_len; - memcpy(ret, pinfo.pr_psargs, len); - ret[len] = 0; + for(len = 0; len < PRARGSZ; ++len) + if(!(pinfo.pr_psargs[len])) + break; + + ret = glibtop_malloc_r (server, len+1); + memcpy(ret, pinfo.pr_psargs, len); + ret[len] = 0; + + count = 0; + for(p = ret; *p; ++p) + if(*p == ' ') { + *p = 0; count++; } - else - { - ret = glibtop_malloc_r(server, len + 1); - memcpy(ret, pinfo.pr_psargs, len); - ret[len] = 0; - buf->size = len; - buf->flags = _glibtop_sysdeps_proc_args; - } - for(p = ret; *p; ++p) - if(*p == ' ') - *p = 0; - return ret; + ptrlist = glibtop_calloc_r(server, len+1, sizeof (char *)); + + for (i = 0, p = ret; i < count; i++) { + ptrlist [i] = glibtop_strdup_r (server, p); + p += strlen (p) + 1; + } + + ptrlist [count] = NULL; + + glibtop_free_r (server, ret); + + array->number = count; + array->size = sizeof (char *); + array->flags = _glibtop_sysdeps_proc_args; + + return ptrlist; } diff --git a/sysdeps/solaris/prockernel.c b/sysdeps/solaris/prockernel.c index 885f8851..1d9709ce 100644 --- a/sysdeps/solaris/prockernel.c +++ b/sysdeps/solaris/prockernel.c @@ -31,7 +31,9 @@ static const unsigned long _glibtop_sysdeps_proc_kernel = 0; int glibtop_init_proc_kernel_s (glibtop *server) { - server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel; + server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel; + + return 0; } /* Provides detailed information about a process. */ @@ -40,5 +42,7 @@ int glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid) { - memset (buf, 0, sizeof (glibtop_proc_kernel)); + memset (buf, 0, sizeof (glibtop_proc_kernel)); + + return 0; } diff --git a/sysdeps/solaris/proclist.c b/sysdeps/solaris/proclist.c index e22876d9..50dce0af 100644 --- a/sysdeps/solaris/proclist.c +++ b/sysdeps/solaris/proclist.c @@ -30,11 +30,11 @@ #include #include -#define GLIBTOP_PROCLIST_FLAGS 3 +#include static const unsigned long _glibtop_sysdeps_proclist = -(1L << GLIBTOP_PROCLIST_TOTAL) + (1L << GLIBTOP_PROCLIST_NUMBER) + -(1L << GLIBTOP_PROCLIST_SIZE); +(1L << GLIBTOP_ARRAY_TOTAL) + (1L << GLIBTOP_ARRAY_NUMBER) + +(1L << GLIBTOP_ARRAY_SIZE); /* Init function. */ @@ -42,6 +42,8 @@ int glibtop_init_proclist_s (glibtop *server) { server->sysdeps.proclist = _glibtop_sysdeps_proclist; + + return 0; } #define BLOCK_COUNT 256 @@ -55,7 +57,7 @@ glibtop_init_proclist_s (glibtop *server) * each buf->size big. The total size is stored in buf->total. */ unsigned * -glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf, +glibtop_get_proclist_s (glibtop *server, glibtop_array *array, int64_t which, int64_t arg) { DIR *proc; @@ -65,15 +67,17 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf, unsigned pids [BLOCK_COUNT], *pids_chain = NULL; unsigned pids_size = 0, pids_offset = 0, new_size; struct stat statb; - int len, i, ok; + int len, ok; - memset (buf, 0, sizeof (glibtop_proclist)); + memset (array, 0, sizeof (glibtop_array)); mask = which & ~GLIBTOP_KERN_PROC_MASK; which &= GLIBTOP_KERN_PROC_MASK; /* Check if the user wanted only one process */ if(which == GLIBTOP_KERN_PROC_PID) { + pid = arg; + if(mask) { #ifdef HAVE_PROCFS_H struct psinfo psinfo; @@ -89,13 +93,17 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf, if(mask & GLIBTOP_EXCLUDE_NOTTY && psinfo.pr_ttydev == PRNODEV) return NULL; } else { - sprintf(buffer, "/proc/%d", arg); + sprintf(buffer, "/proc/%ld", (long)arg); if(s_stat(buffer, &statb) < 0) return NULL; } - if(!(pids_chain = glibtop_malloc(sizeof(unsigned)))) + if(!(pids_chain = glibtop_calloc_r(server, 1, sizeof(unsigned)))) return NULL; *pids_chain = pid; + array->number = 1; + array->size = sizeof(unsigned); + array->total = array->number * array->size; + array->flags = _glibtop_sysdeps_proclist; return pids_chain; } @@ -235,15 +243,15 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf, pids_offset += BLOCK_COUNT; - /* Since everything is ok now, we can set buf->flags, fill in the + /* Since everything is ok now, we can set array->flags, fill in the * remaining fields and return the `pids_chain'. */ - buf->flags = _glibtop_sysdeps_proclist; + array->flags = _glibtop_sysdeps_proclist; - buf->size = sizeof (unsigned); - buf->number = total; + array->size = sizeof (unsigned); + array->number = total; - buf->total = total * sizeof (unsigned); + array->total = array->number * array->size; return pids_chain; } diff --git a/sysdeps/solaris/procmap.c b/sysdeps/solaris/procmap.c index 5dd83816..eada9b63 100644 --- a/sysdeps/solaris/procmap.c +++ b/sysdeps/solaris/procmap.c @@ -30,41 +30,42 @@ #include #include -#include "safeio.h" - +#include static const unsigned long _glibtop_sysdeps_proc_map = -(1L << GLIBTOP_PROC_MAP_NUMBER) + (1L << GLIBTOP_PROC_MAP_TOTAL) + -(1L << GLIBTOP_PROC_MAP_SIZE); +(1L << GLIBTOP_ARRAY_NUMBER) + (1L << GLIBTOP_ARRAY_TOTAL) + +(1L << GLIBTOP_ARRAY_SIZE); + static const unsigned long _glibtop_sysdeps_map_entry = (1L << GLIBTOP_MAP_ENTRY_START) + (1L << GLIBTOP_MAP_ENTRY_END) + (1L << GLIBTOP_MAP_ENTRY_OFFSET) + (1L << GLIBTOP_MAP_ENTRY_PERM); static const unsigned long _glibtop_sysdeps_map_device = (1L << GLIBTOP_MAP_ENTRY_DEVICE) + (1L << GLIBTOP_MAP_ENTRY_INODE); - /* Init function. */ int glibtop_init_proc_map_s (glibtop *server) { - server->sysdeps.proc_map = _glibtop_sysdeps_proc_map; + server->sysdeps.proc_map = _glibtop_sysdeps_proc_map; + + return 0; } /* Provides detailed information about a process. */ glibtop_map_entry * -glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid) +glibtop_get_proc_map_s (glibtop *server, glibtop_array *array, pid_t pid) { - int fd, i, nmaps, pr_err, heap; + int fd, i, nmaps, pr_err, heap; #if GLIBTOP_SOLARIS_RELEASE >= 560 - prxmap_t *maps; - struct ps_prochandle *Pr; + prxmap_t *maps; + struct ps_prochandle *Pr = NULL; #else - prmap_t *maps; + prmap_t *maps; #endif - /* A few defines, to make it shorter down there */ + /* A few defines, to make it shorter down there */ #ifdef HAVE_PROCFS_H # define OFFSET pr_offset @@ -72,136 +73,125 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid) # define OFFSET pr_off #endif - glibtop_map_entry *entry; - struct stat inode; - char buffer[BUFSIZ]; + glibtop_map_entry *entry; + struct stat inode; + char buffer[BUFSIZ]; - memset (buf, 0, sizeof (glibtop_proc_map)); + memset (array, 0, sizeof (glibtop_array)); #ifdef HAVE_PROCFS_H - sprintf(buffer, "/proc/%d/xmap", (int)pid); + sprintf(buffer, "/proc/%d/xmap", (int)pid); #else - sprintf(buffer, "/proc/%d", (int)pid); + sprintf(buffer, "/proc/%d", (int)pid); #endif - if((fd = s_open(buffer, O_RDONLY)) < 0) - { - if(errno != EPERM && errno != EACCES) - glibtop_warn_io_r(server, "open (%s)", buffer); - return NULL; - } + if((fd = s_open(buffer, O_RDONLY)) < 0) { + if(errno != EPERM && errno != EACCES) + glibtop_warn_io_r(server, "open (%s)", buffer); + return NULL; + } #ifdef HAVE_PROCFS_H - if(fstat(fd, &inode) < 0) - { - if(errno != EOVERFLOW) - glibtop_warn_io_r(server, "fstat (%s)", buffer); - /* else call daemon for 64-bit support */ - s_close(fd); - return NULL; - } - maps = alloca(inode.st_size); - nmaps = inode.st_size / sizeof(prxmap_t); - if(s_pread(fd, maps, inode.st_size, 0) != inode.st_size) - { - glibtop_warn_io_r(server, "pread (%s)", buffer); - s_close(fd); - return NULL; - } -#else - if(ioctl(fd, PIOCNMAP, &nmaps) < 0) - { - glibtop_warn_io_r(server, "ioctl(%s, PIOCNMAP)", buffer); - s_close(fd); - return NULL; - } - maps = alloca((nmaps + 1) * sizeof(prmap_t)); - if(ioctl(fd, PIOCMAP, maps) < 0) - { - glibtop_warn_io_r(server, "ioctl(%s, PIOCMAP)", buffer); - s_close(fd); - return NULL; - } -#endif - if(!(entry = glibtop_malloc_r(server, - nmaps * sizeof(glibtop_map_entry)))) - return NULL; - buf->number = nmaps; - buf->size = sizeof(glibtop_map_entry); - buf->total = nmaps * sizeof(glibtop_map_entry); - - memset(entry, 0, nmaps * sizeof(glibtop_map_entry)); - -#if GLIBTOP_SOLARIS_RELEASE >= 560 - - if(server->_priv->machine.objname && server->_priv->machine.pgrab && - server->_priv->machine.pfree) - Pr = (server->_priv->machine.pgrab)(pid, 1, &pr_err); -#endif - for(heap = 0,i = 0; i < nmaps; ++i) - { - int len; - - entry[i].start = maps[i].pr_vaddr; - entry[i].end = maps[i].pr_vaddr + maps[i].pr_size; - -#if GLIBTOP_SOLARIS_RELEASE >= 560 - - if(maps[i].pr_dev != PRNODEV) - { - entry[i].device = maps[i].pr_dev; - entry[i].inode = maps[i].pr_ino; - entry[i].flags |= _glibtop_sysdeps_map_device; - } -#endif - entry[i].offset = maps[i].OFFSET; - if(maps[i].pr_mflags & MA_READ) - entry[i].perm |= GLIBTOP_MAP_PERM_READ; - if(maps[i].pr_mflags & MA_WRITE) - entry[i].perm |= GLIBTOP_MAP_PERM_WRITE; - if(maps[i].pr_mflags & MA_EXEC) - entry[i].perm |= GLIBTOP_MAP_PERM_EXECUTE; - if(maps[i].pr_mflags & MA_SHARED) - entry[i].perm |= GLIBTOP_MAP_PERM_SHARED; - else - entry[i].perm |= GLIBTOP_MAP_PERM_PRIVATE; - entry[i].flags = _glibtop_sysdeps_map_entry; - -#if GLIBTOP_SOLARIS_RELEASE >= 560 - - if(maps[i].pr_mflags & MA_ANON) - { - if(!heap) - { - ++heap; - strcpy(entry[i].filename, "[ heap ]"); - } - else - if(i == nmaps - 1) - strcpy(entry[i].filename, "[ stack ]"); - else - strcpy(entry[i].filename, "[ anon ]"); - entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); - } - else - if(Pr) - { - server->_priv->machine.objname(Pr, maps[i].pr_vaddr, buffer, - BUFSIZ); - if((len = resolvepath(buffer, entry[i].filename, - GLIBTOP_MAP_FILENAME_LEN)) > 0) - { - entry[i].filename[len] = 0; - entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); - } - } -#endif - } - -#if GLIBTOP_SOLARIS_RELEASE >= 560 - - if(Pr) - server->_priv->machine.pfree(Pr); -#endif - buf->flags = _glibtop_sysdeps_proc_map; + if(fstat(fd, &inode) < 0) { + if(errno != EOVERFLOW) + glibtop_warn_io_r(server, "fstat (%s)", buffer); + /* else call daemon for 64-bit support */ s_close(fd); - return entry; + return NULL; + } + maps = alloca(inode.st_size); + nmaps = inode.st_size / sizeof(prxmap_t); + if(s_pread(fd, maps, inode.st_size, 0) != inode.st_size) { + glibtop_warn_io_r(server, "pread (%s)", buffer); + s_close(fd); + return NULL; + } +#else + if(ioctl(fd, PIOCNMAP, &nmaps) < 0) { + glibtop_warn_io_r(server, "ioctl(%s, PIOCNMAP)", buffer); + s_close(fd); + return NULL; + } + maps = alloca((nmaps + 1) * sizeof(prmap_t)); + if(ioctl(fd, PIOCMAP, maps) < 0) { + glibtop_warn_io_r(server, "ioctl(%s, PIOCMAP)", buffer); + s_close(fd); + return NULL; + } +#endif + if(!(entry = glibtop_malloc_r(server, + nmaps * sizeof(glibtop_map_entry)))) + return NULL; + array->number = nmaps; + array->size = sizeof(glibtop_map_entry); + array->total = nmaps * sizeof(glibtop_map_entry); + + memset(entry, 0, nmaps * sizeof(glibtop_map_entry)); + +#if GLIBTOP_SOLARIS_RELEASE >= 560 + + if(server->_priv->machine.objname && server->_priv->machine.pgrab && + server->_priv->machine.pfree) + Pr = (server->_priv->machine.pgrab)(pid, 1, &pr_err); +#endif + for(heap = 0,i = 0; i < nmaps; ++i) { + int len; + + entry[i].start = maps[i].pr_vaddr; + entry[i].end = maps[i].pr_vaddr + maps[i].pr_size; + +#if GLIBTOP_SOLARIS_RELEASE >= 560 + + if(maps[i].pr_dev != PRNODEV) { + entry[i].device = maps[i].pr_dev; + entry[i].inode = maps[i].pr_ino; + entry[i].flags |= _glibtop_sysdeps_map_device; + } +#endif + entry[i].offset = maps[i].OFFSET; + if(maps[i].pr_mflags & MA_READ) + entry[i].perm |= GLIBTOP_MAP_PERM_READ; + if(maps[i].pr_mflags & MA_WRITE) + entry[i].perm |= GLIBTOP_MAP_PERM_WRITE; + if(maps[i].pr_mflags & MA_EXEC) + entry[i].perm |= GLIBTOP_MAP_PERM_EXECUTE; + if(maps[i].pr_mflags & MA_SHARED) + entry[i].perm |= GLIBTOP_MAP_PERM_SHARED; + else + entry[i].perm |= GLIBTOP_MAP_PERM_PRIVATE; + entry[i].flags = _glibtop_sysdeps_map_entry; + +#if GLIBTOP_SOLARIS_RELEASE >= 560 + + if(maps[i].pr_mflags & MA_ANON) { + if(!heap) { + ++heap; + strcpy(entry[i].filename, "[ heap ]"); + } else { + if(i == nmaps - 1) + strcpy(entry[i].filename, "[ stack ]"); + else + strcpy(entry[i].filename, "[ anon ]"); + } + entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); + } else { + if(Pr) { + server->_priv->machine.objname(Pr, maps[i].pr_vaddr, buffer, + BUFSIZ); + if((len = resolvepath(buffer, entry[i].filename, + GLIBTOP_MAP_FILENAME_LEN)) > 0) { + entry[i].filename[len] = 0; + entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); + } +#endif + } + } + } + +#if GLIBTOP_SOLARIS_RELEASE >= 560 + if(Pr) + server->_priv->machine.pfree(Pr); +#endif + + array->flags = _glibtop_sysdeps_proc_map; + s_close(fd); + return entry; } diff --git a/sysdeps/solaris/procmem.c b/sysdeps/solaris/procmem.c index 57253287..61a52d3b 100644 --- a/sysdeps/solaris/procmem.c +++ b/sysdeps/solaris/procmem.c @@ -24,6 +24,8 @@ #include #include +#include + static const unsigned long _glibtop_sysdeps_proc_mem = (1L << GLIBTOP_PROC_MEM_SIZE) + (1L << GLIBTOP_PROC_MEM_VSIZE) + (1L << GLIBTOP_PROC_MEM_RESIDENT) + (1L << GLIBTOP_PROC_MEM_RSS); @@ -33,7 +35,9 @@ static const unsigned long _glibtop_sysdeps_proc_mem = int glibtop_init_proc_mem_s (glibtop *server) { - server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem; + server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem; + + return 0; } /* Provides detailed information about a process. */ @@ -42,23 +46,26 @@ int glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid) { #ifdef HAVE_PROCFS_H - struct psinfo psinfo; + struct psinfo psinfo; #else - struct prpsinfo psinfo; - int pagesize = server->_priv->machine.pagesize; + struct prpsinfo psinfo; + int pagesize = server->_priv->machine.pagesize; #endif + int retval; - memset (buf, 0, sizeof (glibtop_proc_mem)); + memset (buf, 0, sizeof (glibtop_proc_mem)); - if(glibtop_get_proc_data_psinfo_s(server, &psinfo, pid)) - return; + retval = glibtop_get_proc_data_psinfo_s(server, &psinfo, pid); + if (retval) return retval; #ifdef HAVE_PROCFS_H - buf->size = buf->vsize = psinfo.pr_size << 10; - buf->resident = buf->rss = psinfo.pr_rssize << 10; + buf->size = buf->vsize = psinfo.pr_size << 10; + buf->resident = buf->rss = psinfo.pr_rssize << 10; #else - buf->size = buf->vsize = psinfo.pr_size << pagesize << 10; - buf->resident = buf->rss = psinfo.pr_rssize << pagesize << 10; + buf->size = buf->vsize = psinfo.pr_size << pagesize << 10; + buf->resident = buf->rss = psinfo.pr_rssize << pagesize << 10; #endif - buf->flags = _glibtop_sysdeps_proc_mem; + buf->flags = _glibtop_sysdeps_proc_mem; + + return 0; } diff --git a/sysdeps/solaris/procsegment.c b/sysdeps/solaris/procsegment.c index cff57511..93577fe6 100644 --- a/sysdeps/solaris/procsegment.c +++ b/sysdeps/solaris/procsegment.c @@ -31,7 +31,9 @@ static const unsigned long _glibtop_sysdeps_proc_segment = 0; int glibtop_init_proc_segment_s (glibtop *server) { - server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment; + server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment; + + return 0; } /* Provides detailed information about a process. */ @@ -40,5 +42,7 @@ int glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf, pid_t pid) { - memset (buf, 0, sizeof (glibtop_proc_segment)); + memset (buf, 0, sizeof (glibtop_proc_segment)); + + return 0; } diff --git a/sysdeps/solaris/procsignal.c b/sysdeps/solaris/procsignal.c index 1096a57c..5fdcd0c0 100644 --- a/sysdeps/solaris/procsignal.c +++ b/sysdeps/solaris/procsignal.c @@ -34,7 +34,9 @@ static const unsigned long _glibtop_sysdeps_proc_signal = int glibtop_init_proc_signal_s (glibtop *server) { - server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal; + server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal; + + return 0; } /* Provides detailed information about a process. */ @@ -44,31 +46,33 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid) { #ifdef HAVE_PROCFS_H - struct pstatus pstatus; + struct pstatus pstatus; #else - struct prstatus pstatus; + struct prstatus pstatus; #endif - int size; + int retval, size; - memset (buf, 0, sizeof (glibtop_proc_signal)); + memset (buf, 0, sizeof (glibtop_proc_signal)); - if(glibtop_get_proc_status_s(server, &pstatus, pid)) - return; + retval = glibtop_get_proc_status_s(server, &pstatus, pid); + if (retval) return retval; - if(sizeof(buf->signal) < sizeof(sigset_t)) - size = sizeof(buf->signal); - else - size = sizeof(sigset_t); + if(sizeof(buf->signal) < sizeof(sigset_t)) + size = sizeof(buf->signal); + else + size = sizeof(sigset_t); - memcpy(buf->signal, &pstatus.pr_sigpend, size); + memcpy(buf->signal, &pstatus.pr_sigpend, size); #ifdef HAVE_PROCFS_H - memcpy(buf->blocked, &pstatus.pr_lwp.pr_lwphold, size); + memcpy(buf->blocked, &pstatus.pr_lwp.pr_lwphold, size); #else - memcpy(buf->blocked, &pstatus.pr_lwppend, size); + memcpy(buf->blocked, &pstatus.pr_lwppend, size); #endif - /* Technically, most of this is meaningless on a process level, - but this should be a good enough approximation. */ + /* Technically, most of this is meaningless on a process level, + but this should be a good enough approximation. */ - buf->flags = _glibtop_sysdeps_proc_signal; + buf->flags = _glibtop_sysdeps_proc_signal; + + return 0; } diff --git a/sysdeps/solaris/procstate.c b/sysdeps/solaris/procstate.c index dd10e802..ae093981 100644 --- a/sysdeps/solaris/procstate.c +++ b/sysdeps/solaris/procstate.c @@ -40,7 +40,9 @@ static const unsigned long _glibtop_sysdeps_proc_state = int glibtop_init_proc_state_s (glibtop *server) { - server->sysdeps.proc_state = _glibtop_sysdeps_proc_state; + server->sysdeps.proc_state = _glibtop_sysdeps_proc_state; + + return 0; } /* Provides detailed information about a process. */ @@ -49,45 +51,56 @@ int glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid) { #ifdef HAVE_PROCFS_H - struct psinfo psinfo; + struct psinfo psinfo; #else - struct prpsinfo psinfo; + struct prpsinfo psinfo; #endif + unsigned state; + int retval; - memset (buf, 0, sizeof (glibtop_proc_state)); + memset (buf, 0, sizeof (glibtop_proc_state)); - if (glibtop_get_proc_data_psinfo_s (server, &psinfo, pid)) - return; + retval = glibtop_get_proc_data_psinfo_s (server, &psinfo, pid); + if (retval) return retval; + + buf->uid = psinfo.pr_euid; + buf->gid = psinfo.pr_egid; + buf->ruid = psinfo.pr_uid; + buf->rgid = psinfo.pr_gid; - buf->uid = psinfo.pr_euid; - buf->gid = psinfo.pr_egid; - buf->ruid = psinfo.pr_uid; - buf->rgid = psinfo.pr_gid; #ifdef HAVE_PROCFS_H - switch(psinfo.pr_lwp.pr_state) + state = psinfo.pr_lwp.pr_state; #else - switch(psinfo.pr_state) + state = psinfo.pr_state; #endif - { - case SONPROC: + switch(state) { + case SONPROC: #ifdef HAVE_PROCFS_H - buf->has_cpu = 1; - buf->processor = psinfo.pr_lwp.pr_onpro; + buf->has_cpu = 1; + buf->processor = psinfo.pr_lwp.pr_onpro; #endif - case SRUN: buf->state = GLIBTOP_PROCESS_RUNNING; - break; - case SZOMB: buf->state = GLIBTOP_PROCESS_ZOMBIE; - break; - case SSLEEP: buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE; - break; - case SSTOP: buf->state = GLIBTOP_PROCESS_STOPPED; - break; - case SIDL: buf->state = GLIBTOP_PROCESS_UNINTERRUPTIBLE; - } + break; + case SRUN: + buf->state = GLIBTOP_PROCESS_RUNNING; + break; + case SZOMB: + buf->state = GLIBTOP_PROCESS_ZOMBIE; + break; + case SSLEEP: + buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE; + break; + case SSTOP: + buf->state = GLIBTOP_PROCESS_STOPPED; + break; + case SIDL: + buf->state = GLIBTOP_PROCESS_UNINTERRUPTIBLE; + } #ifdef HAVE_PROCFS_H - buf->last_processor = psinfo.pr_lwp.pr_onpro; + buf->last_processor = psinfo.pr_lwp.pr_onpro; #endif - strncpy (buf->cmd, psinfo.pr_fname, 39); + strncpy (buf->cmd, psinfo.pr_fname, 39); - buf->flags = _glibtop_sysdeps_proc_state; + buf->flags = _glibtop_sysdeps_proc_state; + + return 0; } diff --git a/sysdeps/solaris/proctime.c b/sysdeps/solaris/proctime.c index 9e9bf001..491a1838 100644 --- a/sysdeps/solaris/proctime.c +++ b/sysdeps/solaris/proctime.c @@ -35,7 +35,9 @@ static const unsigned long _glibtop_sysdeps_proc_time = int glibtop_init_proc_time_s (glibtop *server) { - server->sysdeps.proc_time = _glibtop_sysdeps_proc_time; + server->sysdeps.proc_time = _glibtop_sysdeps_proc_time; + + return 0; } /* Provides detailed information about a process. */ @@ -44,26 +46,29 @@ int glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid) { - struct prusage prusage; + struct prusage prusage; + int retval; - memset (buf, 0, sizeof (glibtop_proc_time)); + memset (buf, 0, sizeof (glibtop_proc_time)); - /* Don't do it for scheduler, we don't want to frighten our users */ + /* Don't do it for scheduler, we don't want to frighten our users */ - if(pid) - { - if (glibtop_get_proc_data_usage_s (server, &prusage, pid)) - return; + if (!pid) + return -GLIBTOP_ERROR_INVALID_ARGUMENT; - buf->start_time = prusage.pr_create.tv_sec; + retval = glibtop_get_proc_data_usage_s (server, &prusage, pid); + if (retval) return retval; - buf->rtime = prusage.pr_rtime.tv_sec * 1E+6 + - prusage.pr_rtime.tv_nsec / 1E+3; - buf->utime = prusage.pr_utime.tv_sec * 1E+6 + - prusage.pr_utime.tv_nsec / 1E+3; - buf->stime = prusage.pr_stime.tv_sec * 1E+6 + - prusage.pr_stime.tv_nsec / 1E+3; - } + buf->start_time = prusage.pr_create.tv_sec; - buf->flags = _glibtop_sysdeps_proc_time; + buf->rtime = prusage.pr_rtime.tv_sec * 1E+6 + + prusage.pr_rtime.tv_nsec / 1E+3; + buf->utime = prusage.pr_utime.tv_sec * 1E+6 + + prusage.pr_utime.tv_nsec / 1E+3; + buf->stime = prusage.pr_stime.tv_sec * 1E+6 + + prusage.pr_stime.tv_nsec / 1E+3; + + buf->flags = _glibtop_sysdeps_proc_time; + + return 0; } diff --git a/sysdeps/solaris/procuid.c b/sysdeps/solaris/procuid.c index cf33e84f..1e0eda61 100644 --- a/sysdeps/solaris/procuid.c +++ b/sysdeps/solaris/procuid.c @@ -44,8 +44,10 @@ static const unsigned long _glibtop_sysdeps_proc_uid_prcred = int glibtop_init_proc_uid_s (glibtop *server) { - server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid_psinfo + - _glibtop_sysdeps_proc_uid_prcred; + server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid_psinfo + + _glibtop_sysdeps_proc_uid_prcred; + + return 0; } /* Provides detailed information about a process. */ @@ -53,64 +55,67 @@ glibtop_init_proc_uid_s (glibtop *server) int glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid) { - struct prcred prcred; + struct prcred prcred; #ifdef HAVE_PROCFS_H - struct psinfo psinfo; - gid_t groups[GLIBTOP_MAX_GROUPS]; + struct psinfo psinfo; + gid_t groups[GLIBTOP_MAX_GROUPS]; #else - struct prpsinfo psinfo; - gid_t groups[1]; /* dummy for consistent function prototype */ + struct prpsinfo psinfo; + gid_t groups[1]; /* dummy for consistent function prototype */ #endif + int retval; - memset (buf, 0, sizeof (glibtop_proc_uid)); + memset (buf, 0, sizeof (glibtop_proc_uid)); - if (glibtop_get_proc_data_psinfo_s (server, &psinfo, pid)) - return; + retval = glibtop_get_proc_data_psinfo_s (server, &psinfo, pid); + if (retval) return retval; - buf->euid = psinfo.pr_euid; - buf->uid = psinfo.pr_uid; - buf->egid = psinfo.pr_egid; - buf->gid = psinfo.pr_gid; + buf->euid = psinfo.pr_euid; + buf->uid = psinfo.pr_uid; + buf->egid = psinfo.pr_egid; + buf->gid = psinfo.pr_gid; - buf->pid = psinfo.pr_pid; - buf->ppid = psinfo.pr_ppid; + buf->pid = psinfo.pr_pid; + buf->ppid = psinfo.pr_ppid; #ifdef HAVE_PROCFS_H - buf->pgrp = psinfo.pr_pgid; + buf->pgrp = psinfo.pr_pgid; #else - buf->pgrp = psinfo.pr_pgrp; + buf->pgrp = psinfo.pr_pgrp; #endif - buf->session = psinfo.pr_sid; - buf->tty = psinfo.pr_ttydev; + buf->session = psinfo.pr_sid; + buf->tty = psinfo.pr_ttydev; #ifdef HAVE_PROCFS_H - buf->priority = psinfo.pr_lwp.pr_pri; - buf->nice = psinfo.pr_lwp.pr_nice - NZERO; + buf->priority = psinfo.pr_lwp.pr_pri; + buf->nice = psinfo.pr_lwp.pr_nice - NZERO; #else - buf->priority = psinfo.pr_pri; - buf->nice = psinfo.pr_nice - NZERO; + buf->priority = psinfo.pr_pri; + buf->nice = psinfo.pr_nice - NZERO; #endif - buf->flags = _glibtop_sysdeps_proc_uid_psinfo; + buf->flags = _glibtop_sysdeps_proc_uid_psinfo; - if(glibtop_get_proc_credentials_s(server, &prcred, groups, pid)) - return; + retval = glibtop_get_proc_credentials_s(server, &prcred, groups, pid); + if (retval) return retval; - buf->suid = prcred.pr_suid; - buf->sgid = prcred.pr_sgid; - buf->ngroups = (prcred.pr_ngroups <= GLIBTOP_MAX_GROUPS) ? - prcred.pr_ngroups : GLIBTOP_MAX_GROUPS; + buf->suid = prcred.pr_suid; + buf->sgid = prcred.pr_sgid; + buf->ngroups = (prcred.pr_ngroups <= GLIBTOP_MAX_GROUPS) ? + prcred.pr_ngroups : GLIBTOP_MAX_GROUPS; #ifdef HAVE_PROCFS_H - if(sizeof(int) == sizeof(gid_t)) - memcpy(buf->groups, &groups, buf->ngroups * sizeof(gid_t)); - else - { - int i; + if(sizeof(int) == sizeof(gid_t)) + memcpy(buf->groups, &groups, buf->ngroups * sizeof(gid_t)); + else { + int i; - for(i = 0; i < buf->ngroups; ++i) - buf->groups[i] = groups[i]; - } + for(i = 0; i < buf->ngroups; ++i) + buf->groups[i] = groups[i]; + } #endif - buf->flags += _glibtop_sysdeps_proc_uid_prcred; + + buf->flags |= _glibtop_sysdeps_proc_uid_prcred; + + return 0; }