[Nagiosplug-checkins] SF.net SVN: nagiosplug: [2012] nagiosplug/trunk/plugins-root/pst3.c
tonvoon at users.sourceforge.net
tonvoon at users.sourceforge.net
Tue Jun 17 16:19:20 CEST 2008
Revision: 2012
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2012&view=rev
Author: tonvoon
Date: 2008-06-17 07:19:17 -0700 (Tue, 17 Jun 2008)
Log Message:
-----------
Fixed possible coredump. Removed one level of subroutines (Duncan Ferguson)
Modified Paths:
--------------
nagiosplug/trunk/plugins-root/pst3.c
Modified: nagiosplug/trunk/plugins-root/pst3.c
===================================================================
--- nagiosplug/trunk/plugins-root/pst3.c 2008-06-09 19:47:36 UTC (rev 2011)
+++ nagiosplug/trunk/plugins-root/pst3.c 2008-06-17 14:19:17 UTC (rev 2012)
@@ -81,9 +81,8 @@
* Prototypes
*/
-static int output_info(struct proc *proc_kvm, psinfo_t procinfo,char **proc_argv);
-static psinfo_t get_procinfo(struct proc *proc);
-static int HandleProc(struct proc *proc);
+static void output_info(struct proc *proc_kvm,char **proc_argv);
+static void HandleProc(struct proc *proc);
/*----------------------------------------------------------------------------*/
@@ -147,12 +146,11 @@
/*----------------------------------------------------------------------------*/
-static int HandleProc(struct proc *proc)
+static void HandleProc(struct proc *proc)
{
struct pid pid;
struct user *user;
- psinfo_t procinfo;
- char **proc_argv = 0;
+ char **proc_argv = NULL;
if(kvm_kread(kd, (unsigned long) proc->p_pidp, (char *) &pid, sizeof pid) == -1) {
perror("kvm_read error");
@@ -162,39 +160,37 @@
user = kvm_getu(kd, proc);
if(kvm_getcmd(kd, proc, user, &proc_argv, NULL) == -1) {
- return FAIL;
+ return;
}
- procinfo = get_procinfo(proc);
- return output_info(proc, procinfo, proc_argv);
+ if(proc_argv == NULL) {
+ return;
+ }
+
+ output_info(proc, proc_argv);
+ free(proc_argv);
}
-static psinfo_t get_procinfo(struct proc *proc)
+static void output_info(struct proc *proc_kvm, char **proc_argv)
{
char procpath[MAX_PATH];
psinfo_t procinfo;
int fd, len;
+ char *procname;
+ int i;
- sprintf(procpath, "/proc/%d/psinfo", proc->p_pidp->pid_id);
+ sprintf(procpath, "/proc/%d/psinfo", proc_kvm->p_pidp->pid_id);
if ((fd = open(procpath, O_RDONLY)) >= 0)
{
if ((len = read(fd, &procinfo, sizeof(procinfo))) != sizeof(procinfo))
{
- fprintf(stderr,"%s: Read error of psingo structure (%d)\n", procpath, len);
+ fprintf(stderr,"%s: Read error of psinfo structure (%d)\n", procpath, len);
exit(2);
}
close(fd);
}
- return procinfo;
-}
-
-static int output_info(struct proc *proc_kvm, psinfo_t procinfo, char **proc_argv)
-{
- char *procname;
- int i;
-
if((procname = strrchr(proc_argv[0], '/')) != NULL)
procname++;
else
@@ -216,7 +212,5 @@
}
printf("\n");
-
- return OK;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list