From 2968a166e2524c5c1c557a12ae8dd6eaf698d7ea Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Tue, 17 Jun 2008 14:19:17 +0000 Subject: Fixed possible coredump. Removed one level of subroutines (Duncan Ferguson) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2012 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/plugins-root/pst3.c b/plugins-root/pst3.c index ee1d180..641a9b8 100644 --- a/plugins-root/pst3.c +++ b/plugins-root/pst3.c @@ -81,9 +81,8 @@ static char ** myArgv; * 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 @@ int main (int argc, char **argv) /*----------------------------------------------------------------------------*/ -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,38 +160,36 @@ static int HandleProc(struct proc *proc) user = kvm_getu(kd, proc); if(kvm_getcmd(kd, proc, user, &proc_argv, NULL) == -1) { - return FAIL; + return; + } + + if(proc_argv == NULL) { + return; } - procinfo = get_procinfo(proc); - return output_info(proc, procinfo, proc_argv); + 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++; @@ -216,7 +212,5 @@ static int output_info(struct proc *proc_kvm, psinfo_t procinfo, char **proc_arg } printf("\n"); - - return OK; } -- cgit v0.10-9-g596f