summaryrefslogtreecommitdiffstats
path: root/plugins-root/pst3.c
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2008-06-17 14:19:17 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2008-06-17 14:19:17 +0000
commit2968a166e2524c5c1c557a12ae8dd6eaf698d7ea (patch)
treeb1a1f9f71a8a4a69d146dd8a5a00a99c18d89270 /plugins-root/pst3.c
parentd8577e19942b4885ac642513540fc1791a0fa38b (diff)
downloadmonitoring-plugins-2968a166e2524c5c1c557a12ae8dd6eaf698d7ea.tar.gz
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
Diffstat (limited to 'plugins-root/pst3.c')
-rw-r--r--plugins-root/pst3.c38
1 files changed, 16 insertions, 22 deletions
diff --git a/plugins-root/pst3.c b/plugins-root/pst3.c
index ee1d180e..641a9b86 100644
--- a/plugins-root/pst3.c
+++ b/plugins-root/pst3.c
@@ -81,9 +81,8 @@ static char ** myArgv;
81 * Prototypes 81 * Prototypes
82 */ 82 */
83 83
84static int output_info(struct proc *proc_kvm, psinfo_t procinfo,char **proc_argv); 84static void output_info(struct proc *proc_kvm,char **proc_argv);
85static psinfo_t get_procinfo(struct proc *proc); 85static void HandleProc(struct proc *proc);
86static int HandleProc(struct proc *proc);
87 86
88/*----------------------------------------------------------------------------*/ 87/*----------------------------------------------------------------------------*/
89 88
@@ -147,12 +146,11 @@ int main (int argc, char **argv)
147 146
148/*----------------------------------------------------------------------------*/ 147/*----------------------------------------------------------------------------*/
149 148
150static int HandleProc(struct proc *proc) 149static void HandleProc(struct proc *proc)
151{ 150{
152 struct pid pid; 151 struct pid pid;
153 struct user *user; 152 struct user *user;
154 psinfo_t procinfo; 153 char **proc_argv = NULL;
155 char **proc_argv = 0;
156 154
157 if(kvm_kread(kd, (unsigned long) proc->p_pidp, (char *) &pid, sizeof pid) == -1) { 155 if(kvm_kread(kd, (unsigned long) proc->p_pidp, (char *) &pid, sizeof pid) == -1) {
158 perror("kvm_read error"); 156 perror("kvm_read error");
@@ -162,38 +160,36 @@ static int HandleProc(struct proc *proc)
162 user = kvm_getu(kd, proc); 160 user = kvm_getu(kd, proc);
163 161
164 if(kvm_getcmd(kd, proc, user, &proc_argv, NULL) == -1) { 162 if(kvm_getcmd(kd, proc, user, &proc_argv, NULL) == -1) {
165 return FAIL; 163 return;
164 }
165
166 if(proc_argv == NULL) {
167 return;
166 } 168 }
167 169
168 procinfo = get_procinfo(proc); 170 output_info(proc, proc_argv);
169 return output_info(proc, procinfo, proc_argv); 171 free(proc_argv);
170} 172}
171 173
172static psinfo_t get_procinfo(struct proc *proc) 174static void output_info(struct proc *proc_kvm, char **proc_argv)
173{ 175{
174 char procpath[MAX_PATH]; 176 char procpath[MAX_PATH];
175 psinfo_t procinfo; 177 psinfo_t procinfo;
176 int fd, len; 178 int fd, len;
179 char *procname;
180 int i;
177 181
178 sprintf(procpath, "/proc/%d/psinfo", proc->p_pidp->pid_id); 182 sprintf(procpath, "/proc/%d/psinfo", proc_kvm->p_pidp->pid_id);
179 183
180 if ((fd = open(procpath, O_RDONLY)) >= 0) 184 if ((fd = open(procpath, O_RDONLY)) >= 0)
181 { 185 {
182 if ((len = read(fd, &procinfo, sizeof(procinfo))) != sizeof(procinfo)) 186 if ((len = read(fd, &procinfo, sizeof(procinfo))) != sizeof(procinfo))
183 { 187 {
184 fprintf(stderr,"%s: Read error of psingo structure (%d)\n", procpath, len); 188 fprintf(stderr,"%s: Read error of psinfo structure (%d)\n", procpath, len);
185 exit(2); 189 exit(2);
186 } 190 }
187 close(fd); 191 close(fd);
188 } 192 }
189 return procinfo;
190
191}
192
193static int output_info(struct proc *proc_kvm, psinfo_t procinfo, char **proc_argv)
194{
195 char *procname;
196 int i;
197 193
198 if((procname = strrchr(proc_argv[0], '/')) != NULL) 194 if((procname = strrchr(proc_argv[0], '/')) != NULL)
199 procname++; 195 procname++;
@@ -216,7 +212,5 @@ static int output_info(struct proc *proc_kvm, psinfo_t procinfo, char **proc_arg
216 } 212 }
217 213
218 printf("\n"); 214 printf("\n");
219
220 return OK;
221} 215}
222 216