diff -x CVS -ur monit.orig/configure.ac monit/configure.ac --- monit.orig/configure.ac 2004-07-15 02:03:28.000000000 +0200 +++ monit/configure.ac 2004-07-27 13:50:43.000000000 +0200 @@ -66,6 +66,7 @@ arpa/inet.h \ asm/page.h \ asm/param.h \ + cf.h \ ctype.h \ crypt.h \ errno.h \ @@ -97,6 +98,8 @@ string.h \ strings.h \ stropts.h \ + sys/cfgodm.h \ + sys/cfgdb.h \ sys/filio.h \ sys/ioctl.h \ sys/loadavg.h \ @@ -314,6 +317,7 @@ then ARCH="AIX" CFLAGS="$CFLAGS -D _REENTRANT" + LIBS="$LIBS -lodm" else AC_MSG_WARN([Architecture not supported: `uname`.]) CFLAGS="$CFLAGS -D _REENTRANT" diff -x CVS -ur monit.orig/gc.c monit/gc.c --- monit.orig/gc.c 2004-04-16 14:00:31.000000000 +0200 +++ monit/gc.c 2004-07-27 14:53:49.000000000 +0200 @@ -29,6 +29,7 @@ #include "monitor.h" #include "protocol.h" +#include "process.h" #include "ssl.h" #include "engine.h" @@ -79,6 +80,11 @@ gc_protocols(); + if(Run.doprocess) { + delprocesstree(oldptree, oldptreesize); + delprocesstree(ptree, ptreesize); + } + if(servicelist) _gc_service_list(&servicelist); diff -x CVS -ur monit.orig/monitor.h monit/monitor.h --- monit.orig/monitor.h 2004-07-15 14:20:12.000000000 +0200 +++ monit/monitor.h 2004-07-27 15:13:37.000000000 +0200 @@ -252,17 +252,26 @@ } *Auth_T; -/** Defines process tree */ +/** Defines process tree - data storage backend*/ typedef struct myprocesstree { int pid; int ppid; + int status_flag; + int visited; long mem_kbyte; int children_num; int children_sum; long mem_kbyte_sum; + int cpu_percent; + int cpu_percent_sum; /** For internal use */ + double time; /**< 1/10 seconds */ + double time_prev; /**< 1/10 seconds */ + long cputime; /**< 1/10 seconds */ + long cputime_prev; /**< 1/10 seconds */ + struct myprocesstree *parent; struct myprocesstree **children; } ProcessTree_T; @@ -471,22 +480,18 @@ } *Gid_T; -/** Defines procfs (or other mechanism) data */ +/** Defines procfs (or other mechanism) data - user frontend */ typedef struct myprocinfo { int pid; int ppid; int status_flag; - long mem_kbyte; - int mem_percent; /**< pecentage * 10 */ - int cpu_percent; /**< pecentage * 10 */ int children; + long mem_kbyte; long total_mem_kbyte; + int mem_percent; /**< pecentage * 10 */ int total_mem_percent; /**< pecentage * 10 */ - - /* private for calculating cpu_percent */ - double time_prev; /**< 1/10 seconds */ - long cputime; /**< 1/10 seconds */ - long cputime_prev; /**< 1/10 seconds */ + int cpu_percent; /**< pecentage * 10 */ + int total_cpu_percent; /**< pecentage * 10 */ } *ProcInfo_T; @@ -597,10 +602,13 @@ struct myrun Run; /**< Struct holding runtime constants */ Service_T servicelist; /**< The service list (created in p.y) */ Service_T servicelist_conf; /**< The service list in conf file (c. in p.y) */ -ProcessTree_T *ptree; /**< Global process information */ -int ptreesize; /**< Global process information */ +extern ProcessTree_T *ptree; +extern int ptreesize; +extern ProcessTree_T *oldptree; +extern int oldptreesize; + /* ------------------------------------------------------- Public prototypes */ diff -x CVS -ur monit.orig/process/process_common.c monit/process/process_common.c --- monit.orig/process/process_common.c 2004-02-29 23:24:45.000000000 +0100 +++ monit/process/process_common.c 2004-07-27 14:44:21.000000000 +0200 @@ -126,78 +126,6 @@ } -/** - * Get the proc infomation (CPU percentage, MEM in MByte and percent, - * status) - * @param p proc information structure to work with. - * @return TRUE if succeeded otherwise FALSE. - */ -int get_process_info(ProcInfo_T p) { - double temp_time; - - /* get the actual time */ - - temp_time = get_float_time(); - - /* get the system dependant proc data */ - - if ( ! get_process_info_sysdep(p) ) { - - return FALSE; - - } - - /* check if it is the first run */ - - if ( p->time_prev == 0.0 ) { - - p->cpu_percent= 0; - - } else { - - /* Calculate CPU percentage */ - - p->cpu_percent= (int) (( p->cputime - p->cputime_prev ) * 1000) / - ( temp_time - p->time_prev ) / num_cpus; - - } - - p->time_prev = temp_time; - - - return TRUE; - -} - - - -/** - * Write process data in processtree entry - * @param pid pid of the process - * @param entry process tree - * @return TRUE if succeeded otherwise FALSE. - */ -int getdatafromproc(int pid, ProcessTree_T *entry) { - - ProcInfo_T pi=NEW(pi); - - pi->pid=pid; - - if (! get_process_info_sysdep(pi)) { - - return FALSE; - - } - - entry->pid=pid; - entry->mem_kbyte=pi->mem_kbyte; - entry->ppid=pi->ppid; - - FREE(pi); - return TRUE; - -} - /** * Connects child and parent in a process treee @@ -259,6 +187,7 @@ pt->visited= 1; pt->children_sum= pt->children_num; pt->mem_kbyte_sum= pt->mem_kbyte; + pt->cpu_percent_sum= pt->cpu_percent; for( i = 0; i < pt->children_num; i++) { @@ -271,34 +200,12 @@ parent_pt=pt->parent; parent_pt->children_sum+=pt->children_sum; parent_pt->mem_kbyte_sum+=pt->mem_kbyte_sum; + parent_pt->cpu_percent_sum+=pt->cpu_percent_sum; + /* Numerical inaccuracy force us to limit the cpu load to 100%*/ + parent_pt->cpu_percent_sum=(pt->cpu_percent_sum>1000?1000: + parent_pt->cpu_percent_sum); } - } -/** - * Transfer child information from process tree to process info structre - * @param pi process info structure - * @param pt process tree - * @param treesize size of the process tree - * @return TRUE if succeeded otherwise FALSE. - */ -int enterchildinfo(ProcInfo_T pi, ProcessTree_T * pt, int treesize) { - - ProcessTree_T *leaf; - - leaf = findprocess(pi->pid, pt, treesize); - - if (NULL == (leaf = findprocess(pi->pid, pt, treesize))) { - - return FALSE; - - } - - pi->children = leaf->children_sum; - pi->total_mem_kbyte = leaf->mem_kbyte_sum; - - return TRUE; - -} diff -x CVS -ur monit.orig/process/process_sysdep.h monit/process/process_sysdep.h --- monit.orig/process/process_sysdep.h 2004-02-29 23:24:45.000000000 +0100 +++ monit/process/process_sysdep.h 2004-07-27 14:12:35.000000000 +0200 @@ -20,9 +20,7 @@ #ifndef MONIT_PROCESS_SYSDEP_H #define MONIT_PROCESS_SYSDEP_H -int get_process_info(ProcInfo_T); -int get_process_info_sysdep(ProcInfo_T); - +int get_process_info_sysdep(ProcessTree_T *); int init_process_info_sysdep(void); int init_proc_info_sysdep(void); diff -x CVS -ur monit.orig/process/sysdep_AIX.c monit/process/sysdep_AIX.c --- monit.orig/process/sysdep_AIX.c 2004-02-29 23:24:45.000000000 +0100 +++ monit/process/sysdep_AIX.c 2004-07-28 12:04:38.000000000 +0200 @@ -70,6 +70,18 @@ #include #endif +#ifdef HAVE_CF_H +#include +#endif + +#ifdef HAVE_SYS_CFGODM_H +#include +#endif + +#ifdef HAVE_SYS_CFGDB_H +#include +#endif + #include "monitor.h" #include "process.h" @@ -100,7 +112,17 @@ int init_process_info_sysdep(void) { - mem_kbyte_max = 0; + struct CuAt* odmobj; + int results; + + if (odm_initialize() == 0) { + odmobj = (struct CuAt*)getattr ("sys0", "realmem", 0, &results); + mem_kbyte_max = strtoull(odmobj->value, 0, 10); + odm_terminate(); + } else { + mem_kbyte_max = 0; + } + num_cpus= sysconf( _SC_NPROCESSORS_ONLN); return (getuid()==0); @@ -113,68 +135,6 @@ } -int get_process_info_sysdep(ProcInfo_T p) { - - int nproc; - int i,rv; - struct userinfo user; - - memset(&user,0,sizeof(struct userinfo)); - nproc=getproc(procs,NPROCS,sizeof(struct procinfo)); - for(i=0;ipid==procs[i].pi_pid) { - - if(procs[i].pi_stat==SZOMB) { - -empty: - - p->cputime_prev= p->cputime = 0; - p->mem_kbyte= 0; - p->mem_percent= 0.0; - p->status_flag |= PROCESS_ZOMBIE; - - } else { - - rv=getuser(&(procs[i]),sizeof(struct procinfo), - &user,sizeof(struct userinfo)); - - if(rv== -1) { - - goto empty; - - } - - p->mem_percent = user.ui_prm*10; - p->mem_kbyte = (user.ui_drss+user.ui_trss)*4; - - p->cputime_prev= p->cputime; - p->cputime= ( timestruc_to_tseconds(user.ui_ru.ru_utime) + - timestruc_to_tseconds(user.ui_ru.ru_stime)); - - if( include_children ) { - p->cputime+= ( - timestruc_to_tseconds(user.ui_cru.ru_utime)+ - timestruc_to_tseconds(user.ui_cru.ru_stime)); - } - /* first run ? */ - if ( p->time_prev == 0.0 ) { - - p->cputime_prev= p->cputime; - - } - } - - return TRUE; - - } - } - - return FALSE; - -} - - /*************************************************************************** * DATA CAPTURE FUNCTIONS * ***************************************************************************/ @@ -216,41 +176,6 @@ */ int getloadavg_sysdep (double *loadv, int nelem) { - /* - static int initted=0; - int avenrun[3]; - static int no_avenrun_here = 0; - static struct nlist kernelnames[] = { - {"avenrun", 0, 0, 0, 0, 0}, - {NULL, 0, 0, 0, 0, 0} - }; - - if (no_avenrun_here) - return FALSE; - - if (!initted) { - - initted = 1; - if (knlist(kernelnames, 1, sizeof(struct nlist)) == -1){ - - no_avenrun_here = 1; - return -1; - - } - - } - - getkmemdata(&avenrun, sizeof(avenrun), (caddr_t) kernelnames->n_value); - if (nelem > 0) - loadv[0] = avenrun[0] / 65536.0; - if (nelem > 1) - loadv[1] = avenrun[1] / 65536.0; - if (nelem > 2) - loadv[2] = avenrun[2] / 65536.0; - - return TRUE; - */ - return getloadavg(loadv, nelem); } @@ -279,6 +204,7 @@ /* Allocate the tree */ pt = xcalloc(sizeof(ProcessTree_T), treesize); + memset(pt, 0, sizeof(ProcessTree_T) * treesize); /* Insert data from /proc directory */ @@ -289,23 +215,30 @@ if(procs[i].pi_stat==SZOMB) { + pt[i].cputime = 0; pt[i].mem_kbyte= 0; - - } else { + pt[i].status_flag |= PROCESS_ZOMBIE; + + } else { rv=getuser(&(procs[i]),sizeof(struct procinfo), - &user,sizeof(struct userinfo)); - + &user,sizeof(struct userinfo)); + if(rv== -1) { - - pt[i].mem_kbyte= 0; - + + pt[i].cputime = 0; + pt[i].mem_kbyte= 0; + } else { pt[i].mem_kbyte = (user.ui_drss+user.ui_trss)*4; - + pt[i].cputime= ( timestruc_to_tseconds(user.ui_ru.ru_utime) + + timestruc_to_tseconds(user.ui_ru.ru_stime)); + } + } + } * reference = pt; diff -x CVS -ur monit.orig/process/sysdep_DARWIN.c monit/process/sysdep_DARWIN.c --- monit.orig/process/sysdep_DARWIN.c 2004-02-29 23:24:45.000000000 +0100 +++ monit/process/sysdep_DARWIN.c 2004-07-28 12:15:24.000000000 +0200 @@ -196,109 +196,6 @@ } -int get_process_info_sysdep(ProcInfo_T p) { - - struct kinfo_proc *pinfo; - /* struct pstats pstats; */ - struct plimit plimit; - struct vmspace *vms; - /* register struct rusage *rup; */ - long stat_utime=0; - long stat_stime=0; - long stat_cutime=0; - long stat_cstime=0; - - u_int64_t rss_lim; - - int count; - - /* Put this here until fixed */ - return FALSE; - - /* Got it from libgtop */ - - pinfo = kvm_getprocs(kvm_handle, KERN_PROC_PID, p->pid, &count); - - if ((pinfo == NULL) || (count < 1)) { - - return FALSE; - - } - - /* ----------------------------- CPU TIMING ----------------------------*/ - /* Got it from libgtop/sysdep/freebsd/proctime.c */ - - /* if ((pinfo [0].kp_proc.p_flag & P_INMEM) && - kvm_read (kvm_handle, &(pinfo [0]).kp_proc, - (unsigned long) &u_addr->u_stats, - (char *) &pstats, sizeof (pstats)) == sizeof (pstats)) { - - rup = &pstats.p_ru; - calcru(&(pinfo [0]).kp_proc, - &rup->ru_utime, &rup->ru_stime, NULL); - - stat_utime = tv2sec (pstats.p_ru.ru_utime); - stat_stime = tv2sec (pstats.p_ru.ru_stime); - - stat_cutime = tv2sec (pstats.p_cru.ru_utime); - stat_cstime = tv2sec (pstats.p_cru.ru_stime); - - } else { - - return FALSE; - - } */ - - p->cputime_prev= p->cputime; - p->cputime= ( stat_utime + stat_stime ); - - if( include_children ) { - - p->cputime+= ( stat_cutime + stat_cstime ); - - } - - /* first run ? */ - - if ( p->time_prev == 0.0 ) { - - p->cputime_prev= p->cputime; - - } - - /* ----------------------------- MEMORY --------------------------------*/ - /* Got it from libgtop/sysdep/freebsd/procmem.c */ - - /* if (kvm_read (kvm_handle, - (unsigned long) pinfo [0].kp_proc.p_limit, - (char *) &plimit, sizeof (plimit)) != sizeof (plimit)) { - - return FALSE; - - } - */ - rss_lim = (u_int64_t) - (plimit.pl_rlimit [RLIMIT_RSS].rlim_cur); - - vms = &pinfo [0].kp_eproc.e_vm; - - p->mem_kbyte= (u_int64_t) pagetok (vms->vm_rssize); - /* <status_flag |= PROCESS_ZOMBIE; - - } - - p->mem_percent = (int) ((double) p->mem_kbyte * 1000. / mem_kbyte_max); - - return TRUE; - -} /** * Read all processes of the proc files system to initilize @@ -310,11 +207,14 @@ int initprocesstree_sysdep(ProcessTree_T ** reference) { struct kinfo_proc *pinfo; - - /* Only needed for older versions of BSD that use kvm_uread */ - /* struct user *u_addr = (struct user *)USRSTACK; */ + /* struct pstats pstats; */ struct plimit plimit; struct vmspace *vms; + /* register struct rusage *rup; */ + long stat_utime=0; + long stat_stime=0; + long stat_cutime=0; + long stat_cstime=0; u_int64_t rss_lim; @@ -324,6 +224,11 @@ ProcessTree_T * pt; /* Got it from libgtop */ + /* Put this here until fixed */ + +#warning initprocesstree_sysdep: needs to be fixed! + return 0; + pinfo = kvm_getprocs(kvm_handle, KERN_PROC_ALL, 0, &treesize); if ((pinfo == NULL) || (treesize < 1)) { @@ -335,6 +240,7 @@ /* Allocate the tree */ pt = xcalloc(sizeof(ProcessTree_T), treesize); + memset(pt, 0, sizeof(ProcessTree_T) * treesize); /* Insert data from /proc directory */ @@ -343,21 +249,69 @@ pt[i].pid = pinfo[i].kp_proc.p_pid; pt[i].ppid = pinfo[i].kp_eproc.e_ppid; - /* if (kvm_read (kvm_handle, - (unsigned long) pinfo[i].kp_proc.p_limit, - (char *) &plimit, sizeof (plimit)) != sizeof (plimit)) { + /* get the actual time */ + + pt[i].time = get_float_time(); + + /* ----------------------------- CPU TIMING ----------------------------*/ + /* Got it from libgtop/sysdep/freebsd/proctime.c */ + + /* waiting for fix */ + if ((pinfo [0].kp_proc.p_flag & P_INMEM) && + kvm_read (kvm_handle, &(pinfo [0]).kp_proc, + (unsigned long) &u_addr->u_stats, + (char *) &pstats, sizeof (pstats)) == sizeof (pstats)) { + + rup = &pstats.p_ru; + calcru(&(pinfo [0]).kp_proc, + &rup->ru_utime, &rup->ru_stime, NULL); - return FALSE; + stat_utime = tv2sec (pstats.p_ru.ru_utime); + stat_stime = tv2sec (pstats.p_ru.ru_stime); - }*/ + stat_cutime = tv2sec (pstats.p_cru.ru_utime); + stat_cstime = tv2sec (pstats.p_cru.ru_stime); + pt[i].cputime= ( stat_utime + stat_stime ); - rss_lim = (u_int64_t) - (plimit.pl_rlimit [RLIMIT_RSS].rlim_cur); + } else { + + pt[i].cputime= 0; + + } + */ - vms = &pinfo [i].kp_eproc.e_vm; + + /* ----------------------------- MEMORY --------------------------------*/ + /* Got it from libgtop/sysdep/freebsd/procmem.c */ + + /* waiting for fix + if (kvm_read (kvm_handle, + (unsigned long) pinfo [0].kp_proc.p_limit, + (char *) &plimit, sizeof (plimit)) != sizeof (plimit)) { + + pt[i].mem_kbyte=0; + + } else { + + rss_lim = (u_int64_t) + (plimit.pl_rlimit [RLIMIT_RSS].rlim_cur); + + vms = &pinfo [0].kp_eproc.e_vm; + + pt[i].mem_kbyte= (u_int64_t) pagetok (vms->vm_rssize); + /* <vm_rssize); - /* <0 if succeeded otherwise =0. + */ +int initprocesstree_sysdep(ProcessTree_T ** reference) { struct kinfo_proc *pinfo; @@ -291,176 +298,120 @@ long stat_stime; long stat_cutime; long stat_cstime; - u_int64_t rss_lim; - int count; + int i=0; + int treesize; + + ProcessTree_T * pt; + /* Got it from libgtop */ - pinfo = kvm_getprocs(kvm_handle, KERN_PROC_PID, p->pid, &count); + pinfo = kvm_getprocs(kvm_handle, KERN_PROC_ALL, 0, &treesize); - if ((pinfo == NULL) || (count < 1)) { + if ((pinfo == NULL) || (treesize < 1)) { - return FALSE; + return 0; } - /* ----------------------------- CPU TIMING ----------------------------*/ - /* Got it from libgtop/sysdep/freebsd/proctime.c */ + /* Allocate the tree */ + + pt = xcalloc(sizeof(ProcessTree_T), treesize); + memset(pt, 0, sizeof(ProcessTree_T) * treesize); + + /* Insert data from /proc directory */ + + for(i=0;i 500000) - (unsigned long) &pinfo->ki_addr->u_stats, + /* looks strage to me... ?!?! */ + (unsigned long) &(pinfo [i]).ki_addr->u_stats, #else - (unsigned long) pinfo [0].kp_proc.p_stats, + (unsigned long) pinfo [i].kp_proc.p_stats, #endif - &pstats, sizeof (pstats)) == sizeof (pstats)) { + &pstats, sizeof (pstats)) == sizeof (pstats)) { - /* Need to fix for different versions of BSD - I think older ones - use kvm_uread, and newer use kvm_read */ + /* Need to fix for different versions of BSD - I think older ones + use kvm_uread, and newer use kvm_read */ - /* if ((pinfo [0].kp_proc.p_flag & P_INMEM) && - kvm_uread (kvm_handle, &(pinfo [0]).kp_proc, - (unsigned long) &u_addr->u_stats, - (char *) &pstats, sizeof (pstats)) == sizeof (pstats)) { - */ - rup = &pstats.p_ru; + /* if ((pinfo [i].kp_proc.p_flag & P_INMEM) && + kvm_uread (kvm_handle, &(pinfo [i]).kp_proc, + (unsigned long) &u_addr->u_stats, + (char *) &pstats, sizeof (pstats)) + == sizeof (pstats)) { + */ + rup = &pstats.p_ru; + #if (__FreeBSD_version > 500000) - calcru(&pinfo->ki_addr, + /* looks strage to me... ?!?! */ + calcru(&(pinfo [i]).ki_addr,&rup->ru_utime, &rup->ru_stime, NULL); #else - calcru(&(pinfo [0]).kp_proc, + calcru(&(pinfo [i]).kp_proc,&rup->ru_utime, &rup->ru_stime, NULL); #endif - &rup->ru_utime, &rup->ru_stime, NULL); + - stat_utime = tv2sec (pstats.p_ru.ru_utime); - stat_stime = tv2sec (pstats.p_ru.ru_stime); + stat_utime = tv2sec (pstats.p_ru.ru_utime); + stat_stime = tv2sec (pstats.p_ru.ru_stime); - stat_cutime = tv2sec (pstats.p_cru.ru_utime); - stat_cstime = tv2sec (pstats.p_cru.ru_stime); + stat_cutime = tv2sec (pstats.p_cru.ru_utime); + stat_cstime = tv2sec (pstats.p_cru.ru_stime); - } else { - - return FALSE; - - } + pt[i].cputime= (int)(( stat_utime + stat_stime ) / 1000); - p->cputime_prev= p->cputime; - p->cputime= (int)(( stat_utime + stat_stime ) / 1000); + } else { - if( include_children ) { + pt[i].cputime= 0; - p->cputime+= (int)(( stat_cutime + stat_cstime ) / 1000); - - } - - /* first run ? */ - - if ( p->time_prev == 0.0 ) { - - p->cputime_prev= p->cputime; + } - } - /* ----------------------------- MEMORY --------------------------------*/ - /* Got it from libgtop/sysdep/freebsd/procmem.c */ + /* ----------------------------- MEMORY --------------------------------*/ + /* Got it from libgtop/sysdep/freebsd/procmem.c */ - if (kvm_read (kvm_handle, + if (kvm_read (kvm_handle, #if (__FreeBSD_version > 500000) - (unsigned long) &pinfo->ki_addr->p_limit, + /* looks strage to me... ?!?! */ + (unsigned long) &(pinfo [i]).ki_addr->p_limit, #else - (unsigned long) pinfo [0].kp_proc.p_limit, + (unsigned long) pinfo [i].kp_proc.p_limit, #endif - (char *) &plimit, sizeof (plimit)) != sizeof (plimit)) { - - return FALSE; - - } - - rss_lim = (u_int64_t) - (plimit.pl_rlimit [RLIMIT_RSS].rlim_cur); - - vms = &pinfo [0].kp_eproc.e_vm; - - p->mem_kbyte= (u_int64_t) pagetok (vms->vm_rssize); - /* <status_flag |= PROCESS_ZOMBIE; - - } + (char *) &plimit, sizeof (plimit)) != sizeof (plimit)) { - p->mem_percent = (int) ((double) p->mem_kbyte * 1024.0 / mem_kbyte_max); - - return TRUE; - -} - -/** - * Read all processes of the proc files system to initilize - * the process tree (sysdep version... but should work for - * all procfs based unices) - * @param reference reference of ProcessTree - * @return treesize>0 if succeeded otherwise =0. - */ -int initprocesstree_sysdep(ProcessTree_T ** reference) { - - struct kinfo_proc *pinfo; - - /* Only needed for older versions of BSD that use kvm_uread */ - /* struct user *u_addr = (struct user *)USRSTACK; */ - struct plimit plimit; - struct vmspace *vms; - - u_int64_t rss_lim; - int i=0; - int treesize; - - ProcessTree_T * pt; - - - /* Got it from libgtop */ - - pinfo = kvm_getprocs(kvm_handle, KERN_PROC_ALL, 0, &treesize); - - if ((pinfo == NULL) || (treesize < 1)) { - - return 0; + pt[i].mem_kbyte= 0; + + } else { - } + rss_lim = (u_int64_t) (plimit.pl_rlimit [RLIMIT_RSS].rlim_cur); - /* Allocate the tree */ - - pt = xcalloc(sizeof(ProcessTree_T), treesize); + vms = &pinfo [0].kp_eproc.e_vm; + + pt[i].mem_kbyte= (u_int64_t) pagetok (vms->vm_rssize); + /* <vm_rssize); - /* <pid)==-1) { - - return FALSE; - - } - - /* jiffies -> seconds = 1 / HZ - HZ is defined in "asm/param.h" and it is usually 1/100s but on - alpha system it is 1/1024s */ - - p->cputime_prev = p->cputime; - p->cputime = ( ps.pst_utime + ps.pst_stime ) * 10 / HZ; - p->mem_kbyte = (long)(((double)ps.pst_rssize)/1024.0 * page_size); - p->mem_percent = (((double)p->mem_kbyte) * 1000.0 / ((double)mem_kbyte_max)); - - if ( include_children ) { - - p->cputime += ( ps.pst_child_utime.pst_sec + ps.pst_child_stime.pst_sec ) - * 10 / HZ; - - } - - /* first run ? */ - - if ( p->time_prev == 0.0 ) { - - p->cputime_prev = p->cputime; - - } - - /* State is Zombie -> then we are a Zombie ... clear or? (-: */ - - if ( ps.pst_stat || PS_ZOMBIE ) { - - p->status_flag |= PROCESS_ZOMBIE; - - } - - return TRUE; - -} - /** * This routine returns 'na' double precision floats containing * the load averages in 'a'; at most 3 values will be returned. @@ -237,7 +190,9 @@ /* Gather process data */ - if ((treesize=pstat_getproc(psall,(size_t) NPROCS* sizeof(pst_status),(size_t) NPROCS, 0))==-1) { + if ((treesize=pstat_getproc(psall, + (size_t) NPROCS* sizeof(pst_status), + (size_t) NPROCS, 0))==-1) { return 0; @@ -246,14 +201,34 @@ /* Allocate the tree */ pt = xcalloc(sizeof(ProcessTree_T), treesize); + memset(pt, 0, sizeof(ProcessTree_T) * treesize); /* Inspect data */ for (i = 0; i < tree_size; pp++, i++) { - pt[i]->pid = psall[i]->pst_pid; - pt[i]->ppid = psall[i]->pst_ppid; - p->mem_kbyte = (long)(((double)psall[i]->pst_rssize)/1024.0 * page_size); + pt[i].pid = psall[i]->pst_pid; + pt[i].ppid = psall[i]->pst_ppid; + + /* get the actual time */ + + pt[i].time = get_float_time(); + + /* jiffies -> seconds = 1 / HZ + HZ is defined in "asm/param.h" and it is usually 1/100s but on + alpha system it is 1/1024s */ + + pt[i].cputime = ( psall[i]->pst_utime + psall[i]->pst_stime ) * 10 / HZ; + pt[i].mem_kbyte = (long)(((double)psall[i]->pst_rssize)/1024.0 * + page_size); + + /* State is Zombie -> then we are a Zombie ... clear or? (-: */ + + if ( psall[i]->pst_stat || PS_ZOMBIE ) { + + pt[i].status_flag |= PROCESS_ZOMBIE; + + } } diff -x CVS -ur monit.orig/process/sysdep_LINUX.c monit/process/sysdep_LINUX.c --- monit.orig/process/sysdep_LINUX.c 2004-07-08 00:23:42.000000000 +0200 +++ monit/process/sysdep_LINUX.c 2004-07-28 12:10:39.000000000 +0200 @@ -117,7 +117,14 @@ } -int get_process_info_sysdep(ProcInfo_T p) { +/** + * Read all processes of the proc files system to initilize + * the process tree (sysdep version... but should work for + * all procfs based unices) + * @param reference reference of ProcessTree + * @return treesize>0 if succeeded otherwise =0. + */ +int initprocesstree_sysdep(ProcessTree_T ** reference) { char buf[4096]; char* tmp; @@ -134,158 +141,130 @@ #endif int stat_ppid; - if (!read_proc_file(buf,4096, "stat", p->pid)) { + int pid; + int i; + int treesize; - return FALSE; + ProcessTree_T * pt; - } + glob_t globbuf; - /* Move along the buffer to get past the process name */ + ASSERT(reference); - tmp = strrchr(buf, ')') + 2; + /* Find all processes in the /proc directory */ - /* This implementation is done by using fs/procfs/array.c as a basis - it is also worth looking into the source of the procps utils */ + if ( glob("/proc/[0-9]*", GLOB_ONLYDIR, NULL, &globbuf) != 0 ) { - sscanf(tmp,"%c %d %*d %*d %*d %*d %*u %*u" - "%*u %*u %*u %lu %lu %ld %ld %*d %*d %*d " - "%*d %*u %*u %ld %*u %*u %*u %*u %*u " - "%*u %*u %*u %*u %*u %*u %*u %*u %*d %*d\n", - &stat_item_state, &stat_ppid, - &stat_item_utime, &stat_item_stime, - &stat_item_cutime, &stat_item_cstime, &stat_item_rss); + return 0; - /* abs to please the compiler... we dont want to shift negatively. - why doesn't C understand this??? */ + } - p->ppid= stat_ppid; - - /* jiffies -> seconds = 1 / HZ - HZ is defined in "asm/param.h" and it is usually 1/100s but on - alpha system it is 1/1024s */ + treesize = globbuf.gl_pathc; - p->cputime_prev = p->cputime; - p->cputime = ( stat_item_utime + stat_item_stime ) * 10 / HZ; + /* Allocate the tree */ - if ( include_children ) { + pt = xcalloc(sizeof(ProcessTree_T), treesize); + memset(pt, 0, sizeof(ProcessTree_T) * treesize); +#warning FOOBAR + /* Insert data from /proc directory */ - p->cputime += ( stat_item_cutime + stat_item_cstime ) * 10 / HZ; + for ( i = 0; i < treesize; i ++ ) { - } + pid=atoi(globbuf.gl_pathv[i]+strlen("/proc/")); + pt[i].pid=pid; + + if (!read_proc_file(buf,4096, "stat", pid)) { - /* first run ? */ + continue; - if ( p->time_prev == 0.0 ) { + } - p->cputime_prev = p->cputime; + /* get the actual time */ - } + pt[i].time = get_float_time(); - /* State is Zombie -> then we are a Zombie ... clear or? (-: */ + /* Move along the buffer to get past the process name */ - if ( stat_item_state == 'Z' ) { + tmp = strrchr(buf, ')') + 2; - p->status_flag |= PROCESS_ZOMBIE; + /* This implementation is done by using fs/procfs/array.c as a basis + it is also worth looking into the source of the procps utils */ - } + sscanf(tmp,"%c %d %*d %*d %*d %*d %*u %*u" + "%*u %*u %*u %lu %lu %ld %ld %*d %*d %*d " + "%*d %*u %*u %ld %*u %*u %*u %*u %*u " + "%*u %*u %*u %*u %*u %*u %*u %*u %*d %*d\n", + &stat_item_state, &stat_ppid, + &stat_item_utime, &stat_item_stime, + &stat_item_cutime, &stat_item_cstime, &stat_item_rss); + + /* abs to please the compiler... we dont want to shift negatively. + why doesn't C understand this??? */ + + pt[i].ppid= stat_ppid; + + /* jiffies -> seconds = 1 / HZ + HZ is defined in "asm/param.h" and it is usually 1/100s but on + alpha system it is 1/1024s */ + + pt[i].cputime = + ((float) ( stat_item_utime + stat_item_stime ) * 10.0) / HZ; + + /* State is Zombie -> then we are a Zombie ... clear or? (-: */ + + if ( stat_item_state == 'Z' ) { + + pt[i].status_flag |= PROCESS_ZOMBIE; + + } #ifdef USE_QUICK_MEM_CALC - if ( PAGE_TO_KBYTE_SHIFT < 0 ) - { - p->mem_kbyte = (stat_item_rss >> abs(PAGE_TO_KBYTE_SHIFT)); + if ( PAGE_TO_KBYTE_SHIFT < 0 ) { + + pt[i].mem_kbyte = (stat_item_rss >> abs(PAGE_TO_KBYTE_SHIFT)); } else { - p->mem_kbyte = (stat_item_rss << abs(PAGE_TO_KBYTE_SHIFT)); + pt[i].mem_kbyte = (stat_item_rss << abs(PAGE_TO_KBYTE_SHIFT)); } #else - if (!read_proc_file(buf,4096, "statm", p->pid)) { - - return FALSE; - - } + if (!read_proc_file(buf,4096, "statm", pt[i].pid)) { + + pt[i].mem_kbyte= 0; - /* This implementation is done by using fs/procfs/array.c as a basis - it is also worth looking into the source of the procps utils. + } else { - Beware then proc man page has a wrong sorting of the entries! */ + /* This implementation is done by using fs/procfs/array.c as a basis + it is also worth looking into the source of the procps utils. + + Beware then proc man page has a wrong sorting of the entries! */ - sscanf(buf,"%*d %*d %d %d %*d %d %*d\n", - &statm_item_share,&statm_item_trs, &statm_item_drs); - - if ( PAGE_TO_KBYTE_SHIFT < 0 ) { - - p->mem_kbyte= ( statm_item_trs >> abs(PAGE_TO_KBYTE_SHIFT) ) + - ( statm_item_drs >> abs(PAGE_TO_KBYTE_SHIFT) ) - - ( statm_item_share >> abs(PAGE_TO_KBYTE_SHIFT) ); + sscanf(buf,"%*d %*d %d %d %*d %d %*d\n", + &statm_item_share,&statm_item_trs, &statm_item_drs); + + if ( PAGE_TO_KBYTE_SHIFT < 0 ) { + + pt[i].mem_kbyte= ( statm_item_trs >> abs(PAGE_TO_KBYTE_SHIFT) ) + + ( statm_item_drs >> abs(PAGE_TO_KBYTE_SHIFT) ) - + ( statm_item_share >> abs(PAGE_TO_KBYTE_SHIFT) ); + + } else { + + pt[i].mem_kbyte= ( statm_item_trs << abs(PAGE_TO_KBYTE_SHIFT) ) + + ( statm_item_drs << abs(PAGE_TO_KBYTE_SHIFT) ) - + ( statm_item_share << abs(PAGE_TO_KBYTE_SHIFT) ); + + } - } else { + } - p->mem_kbyte= ( statm_item_trs << abs(PAGE_TO_KBYTE_SHIFT) ) + - ( statm_item_drs << abs(PAGE_TO_KBYTE_SHIFT) ) - - ( statm_item_share << abs(PAGE_TO_KBYTE_SHIFT) ); - - } - #endif - p->mem_percent = (int)( (double)p->mem_kbyte * 1000.0 / mem_kbyte_max); - - return TRUE; - -} - - -/** - * Read all processes of the proc files system to initilize - * the process tree (sysdep version... but should work for - * all procfs based unices) - * @param reference reference of ProcessTree - * @return treesize>0 if succeeded otherwise =0. - */ -int initprocesstree_sysdep(ProcessTree_T ** reference) { - - int pid; - int i; - int treesize; - - ProcessTree_T * pt; - - glob_t globbuf; - - ASSERT(reference); - - /* Find all processes in the /proc directory */ - - if ( glob("/proc/[0-9]*", GLOB_ONLYDIR, NULL, &globbuf) != 0 ) { - - return 0; - - } - - treesize = globbuf.gl_pathc; - - /* Allocate the tree */ - - pt = xcalloc(sizeof(ProcessTree_T), treesize); - - /* Insert data from /proc directory */ - - for ( i = 0; i < treesize; i ++ ) { - - pid=atoi(globbuf.gl_pathv[i]+strlen("/proc/")); - - if (! getdatafromproc(pid, &pt[i] )) { - - continue; - - } - } * reference = pt; diff -x CVS -ur monit.orig/process/sysdep_OPENBSD.c monit/process/sysdep_OPENBSD.c --- monit.orig/process/sysdep_OPENBSD.c 2004-02-29 23:24:45.000000000 +0100 +++ monit/process/sysdep_OPENBSD.c 2004-07-28 12:23:47.000000000 +0200 @@ -218,7 +218,7 @@ } -int get_process_info_sysdep(ProcInfo_T p) { +int get_process_info_sysdep(ProcessTree_T *leaf) { struct kinfo_proc *pinfo; @@ -235,9 +235,13 @@ int count; + /* get the actual time */ + + leaf->time = get_float_time(); + /* Got it from libgtop */ - pinfo = kvm_getprocs(kvm_handle, KERN_PROC_PID, p->pid, &count); + pinfo = kvm_getprocs(kvm_handle, KERN_PROC_PID, leaf->pid, &count); if ((pinfo == NULL) || (count < 1)) { @@ -260,31 +264,7 @@ - p->cputime_prev= p->cputime; - p->cputime= (int)(( stat_utime + stat_stime ) / 1000); - - if( include_children ) { - - if ( getrusage(RUSAGE_CHILDREN, &crup) < 0) { - return FALSE; - } else { - - stat_cutime = tv2sec (crup.ru_utime); - stat_cstime = tv2sec (crup.ru_stime); - - } - - p->cputime+= (int)(( stat_cutime + stat_cstime ) / 1000); - - } - - /* first run ? */ - - if ( p->time_prev == 0.0 ) { - - p->cputime_prev= p->cputime; - - } + leaf->cputime= (int)(( stat_utime + stat_stime ) / 1000); /* ----------------------------- MEMORY --------------------------------*/ /* Got it from libgtop/sysdep/freebsd/procmem.c */ @@ -302,7 +282,7 @@ vms = &pinfo [0].kp_eproc.e_vm; - p->mem_kbyte= (u_int64_t) pagetok (vms->vm_rssize); + leaf->mem_kbyte= (u_int64_t) pagetok (vms->vm_rssize); /* <status_flag |= PROCESS_ZOMBIE; + leaf->status_flag |= PROCESS_ZOMBIE; } - p->mem_percent = (int) ((double) p->mem_kbyte * 1000.0 / mem_kbyte_max); - return TRUE; } @@ -331,12 +309,16 @@ struct kinfo_proc *pinfo; - /* Only needed for older versions of BSD that use kvm_uread */ - /* struct user *u_addr = (struct user *)USRSTACK; */ struct plimit plimit; struct vmspace *vms; - + struct rusage rup; + struct rusage crup; + long stat_utime; + long stat_stime; + long stat_cutime; + long stat_cstime; u_int64_t rss_lim; + int i = 0; int treesize; @@ -363,21 +345,59 @@ pt[i].pid = pinfo[i].kp_proc.p_pid; pt[i].ppid = pinfo[i].kp_eproc.e_ppid; - if (kvm_read (kvm_handle, - (unsigned long) pinfo[i].kp_proc.p_limit, - (char *) &plimit, sizeof (plimit)) != sizeof (plimit)) { - - return FALSE; + /* get the actual time */ + + pt[i].time = get_float_time(); + + /* ----------------------------- CPU TIMING ----------------------------*/ + /* Got it from libgtop/sysdep/freebsd/proctime.c */ + +#warning initprocesstree_sysdep: waiting for fix + /* getrusage code is wrong!!! + it only measures the rusage of the current process, that means + of monit itself. + */ + /* + if ( getrusage(RUSAGE_SELF, &rup) < 0 ) { + pt[i].cputime=0 + + } else { + + stat_utime = tv2sec (rup.ru_utime); + stat_stime = tv2sec (rup.ru_stime); + + pt[i].cputime= (int)(( stat_utime + stat_stime ) / 1000); + } + */ + + /* ----------------------------- MEMORY --------------------------------*/ + /* Got it from libgtop/sysdep/freebsd/procmem.c */ + + if (kvm_read (kvm_handle, + (unsigned long) pinfo[i].kp_proc.p_limit, + (char *) &plimit, sizeof (plimit)) != sizeof (plimit)) { + + pt[i].mem_kbyte= 0; + + } else { + + rss_lim = (u_int64_t) + (plimit.pl_rlimit [RLIMIT_RSS].rlim_cur); + + vms = &pinfo [0].kp_eproc.e_vm; + + pt[i].mem_kbyte= (u_int64_t) pagetok (vms->vm_rssize); + /* <vm_rssize); - /* <pid)) { - - return FALSE; - - } - - /* If we don't have any light-weight processes (LWP) then we - are definitely a zombie */ - - if ( psinfo->pr_nlwp == 0 ) { - - p->status_flag = PROCESS_ZOMBIE; - - } - - p->ppid = pstatus->pr_ppid; - - if ( p->status_flag != PROCESS_ZOMBIE ) { - /* We can't access /proc/$pid/status of a zombie */ - /* and does it anyway matter? */ - - p->mem_percent = psinfo->pr_pctmem * 1000 / 0x8000; - p->mem_kbyte = psinfo->pr_rssize; - - if (!read_proc_file(buf,4096, "status", p->pid)) { - - return FALSE; - - } - - p->cputime_prev= p->cputime; - p->cputime= ( timestruc_to_tseconds(pstatus->pr_utime) + - timestruc_to_tseconds(pstatus->pr_stime) ); - - if( include_children ) { - - p->cputime+= ( timestruc_to_tseconds(pstatus->pr_cutime) + - timestruc_to_tseconds(pstatus->pr_cstime) ); - - } - /* first run ? */ - - if ( p->time_prev == 0.0 ) { - - p->cputime_prev= p->cputime; - - } - - } else { - - p->cputime_prev= p->cputime = 0; - p->mem_kbyte= 0; - p->mem_percent= 0.0; - - } - - return TRUE; - -} - /** * Read all processes of the proc files system to initilize @@ -176,6 +110,9 @@ */ int initprocesstree_sysdep(ProcessTree_T ** reference) { + char buf[4096]; + psinfo_t * psinfo= (psinfo_t *)&buf; + pstatus_t * pstatus= (pstatus_t *)&buf; int pid; int i; int treesize; @@ -199,19 +136,56 @@ /* Allocate the tree */ pt = xcalloc(sizeof(ProcessTree_T), treesize); + memset(pt, 0, sizeof(ProcessTree_T) * treesize); /* Insert data from /proc directory */ for ( i = 0; i < treesize; i ++ ) { pid=atoi(globbuf.gl_pathv[i]+strlen("/proc/")); - - if (! getdatafromproc(pid, &pt[i] )) { + pt[i].pid=pid; + + /* get the actual time */ + pt[i].time = get_float_time(); + if (!read_proc_file(buf,4096, "psinfo", pt[i].pid)) { + + pt[i].cputime = 0; + pt[i].mem_kbyte= 0; continue; - } + } + + pt[i].ppid = psinfo->pr_ppid; + + /* If we don't have any light-weight processes (LWP) then we + are definitely a zombie */ + + if ( psinfo->pr_nlwp == 0 ) { + pt[i].status_flag = PROCESS_ZOMBIE; + + /* We can't access /proc/$pid/status of a zombie */ + /* and does it anyway matter? */ + + pt[i].cputime = 0; + pt[i].mem_kbyte= 0; + continue; + + } + + pt[i].mem_kbyte = psinfo->pr_rssize; + + if (!read_proc_file(buf,4096, "status", pt[i].pid)) { + + pt[i].cputime=0; + + } else { + + pt[i].cputime= ( timestruc_to_tseconds(pstatus->pr_utime) + + timestruc_to_tseconds(pstatus->pr_stime) ); + } + } * reference = pt; diff -x CVS -ur monit.orig/process/sysdep_UNKNOWN.c monit/process/sysdep_UNKNOWN.c --- monit.orig/process/sysdep_UNKNOWN.c 2004-02-29 23:24:45.000000000 +0100 +++ monit/process/sysdep_UNKNOWN.c 2004-07-27 14:41:34.000000000 +0200 @@ -45,7 +45,7 @@ } -int get_process_info_sysdep(ProcInfo_T p) { +int get_process_info_sysdep(ProcessTree_T *leaf) { return FALSE; diff -x CVS -ur monit.orig/process.c monit/process.c --- monit.orig/process.c 2004-04-01 18:58:57.000000000 +0200 +++ monit/process.c 2004-07-28 12:49:46.000000000 +0200 @@ -110,7 +110,8 @@ * @param pid The process id * @return TRUE if succeeded otherwise FALSE. */ -int update_process_data(Service_T s, ProcessTree_T *pt, int treesize, pid_t pid) { +int update_process_data(Service_T s, ProcessTree_T *pt, int treesize, + pid_t pid) { ProcInfo_T pi; ProcessTree_T *leaf; @@ -120,30 +121,54 @@ pi= s->procinfo; pi->pid=pid; - if(! get_process_info(pi)) - return FALSE; if ((leaf = findprocess(pid, pt, treesize)) != NULL ) { pi->children=leaf->children_sum; + pi->mem_kbyte=leaf->mem_kbyte; + pi->status_flag=leaf->status_flag; pi->total_mem_kbyte=leaf->mem_kbyte_sum; + if ( include_children ) { + + pi->cpu_percent=leaf->cpu_percent_sum; + + } else { + + pi->cpu_percent=leaf->cpu_percent; + + } + + pi->total_cpu_percent=leaf->cpu_percent_sum; + if ( mem_kbyte_max == 0 ) { + pi->total_mem_percent=0; + pi->mem_percent = 0; + } else { + pi->total_mem_percent= - (int) ((double) leaf->mem_kbyte_sum * 1000.0 / mem_kbyte_max); + (int) ((double) leaf->mem_kbyte_sum * 1000.0 / mem_kbyte_max); + pi->mem_percent = + (int)((double) leaf->mem_kbyte * 1000.0 / mem_kbyte_max); + } } else { pi->children=0; - pi->total_mem_kbyte=pi->mem_kbyte; - pi->total_mem_percent=pi->mem_percent; + pi->total_mem_kbyte=0; + pi->total_mem_percent=0; + pi->mem_kbyte=0; + pi->mem_percent=0; + pi->cpu_percent=0; + pi->total_cpu_percent=0; } - + return TRUE; + } @@ -164,39 +189,90 @@ * Initilize the process tree * @return treesize>=0 if succeeded otherwise <0. */ -int initprocesstree(void) { +int initprocesstree(ProcessTree_T ** pt_r, int * size_r, + ProcessTree_T ** oldpt_r, int * oldsize_r) { int i; + ProcessTree_T * oldentry; + ProcessTree_T * pt; + ProcessTree_T * oldpt; - if((ptreesize = initprocesstree_sysdep(&ptree)) <= 0) + if(*pt_r!=NULL) { + + *oldpt_r=*pt_r; + *oldsize_r=*size_r; + + } + + if((*size_r = initprocesstree_sysdep(pt_r)) <= 0) return 0; - for( i = 0; i < ptreesize; i ++ ) { + pt=*pt_r; + oldpt=*oldpt_r; - if( ptree[i].ppid == 0 ) + for( i = 0; i < *size_r; i ++ ) { + + + if((oldpt != NULL) && + (NULL != (oldentry= (ProcessTree_T *)findprocess(pt[i].pid, + oldpt, + *oldsize_r)))) { + pt[i].cputime_prev= oldentry->cputime; + pt[i].time_prev= oldentry->time; + + if (pt[i].cputime_prev != 0 && + pt[i].cputime != 0 && + pt[i].cputime > pt[i].cputime_prev) { + + pt[i].cpu_percent=(int)((1000*(float)(pt[i].cputime - + pt[i].cputime_prev)/ + (pt[i].time - pt[i].time_prev)) / num_cpus); + + if ( pt[i].cpu_percent > 1000/num_cpus ) { + + /* Just for paranoia! */ + pt[i].cpu_percent = 1000/num_cpus; + + } + + } else { + + pt[i].cpu_percent= 0; + + } + + + } else { + + pt[i].cputime_prev= 0; + pt[i].time_prev= 0.0; + pt[i].cpu_percent= 0; + + } + + if( pt[i].ppid == 0 ) continue; - if(NULL == (ptree[i].parent= - (ProcessTree_T *)findprocess(ptree[i].ppid, ptree, ptreesize))) { + if(NULL == (pt[i].parent= + (ProcessTree_T *)findprocess(pt[i].ppid, pt, *size_r))) { /* inconsitency found, most probably a race condition we might lack accuracy but we remain stable! */ - ptree[i].pid=0; + pt[i].pid=0; continue; } - if(! connectchild((ProcessTree_T *) ptree[i].parent, &ptree[i])) { + if(! connectchild((ProcessTree_T *) pt[i].parent, &pt[i])) { /* connection to parent process has failed, this is usually caused in the part above */ - ptree[i].pid=0; + pt[i].pid=0; continue; } } - fillprocesstree((ProcessTree_T *) findprocess(1, ptree, ptreesize)); - - return ptreesize; + fillprocesstree((ProcessTree_T *) findprocess(1, pt, *size_r)); + return *size_r; } @@ -216,10 +292,16 @@ if(( pid == 0 ) || ( size <= 0 )) return NULL; - for( i = 0; i < size; i ++ ) - if( pid == pt[i].pid ) + for( i = 0; i < size; i ++ ) { + + if( pid == pt[i].pid ) { + return &pt[i]; + } + + } + return NULL; } @@ -227,20 +309,30 @@ /** * Delete the process tree */ -void delprocesstree(void) { +void delprocesstree(ProcessTree_T * pt, int size) { int i; - ASSERT(ptree); + if( pt == NULL ) + return; + + if( size <= 0 ) + return; + + for( i = 0; i < size; i ++ ) { + + if( pt[i].children!=NULL ) { - if( ptreesize <= 0 ) - return; + FREE(pt[i].children); + pt[i].children=NULL; - for( i = 0; i < ptreesize; i ++ ) - if( ptree[i].children!=NULL ) - FREE(ptree[i].children); + } + + } + + FREE(pt); - FREE(ptree); + pt=NULL; return; diff -x CVS -ur monit.orig/process.h monit/process.h --- monit.orig/process.h 2004-03-29 00:24:47.000000000 +0200 +++ monit/process.h 2004-07-23 15:22:48.000000000 +0200 @@ -45,9 +45,8 @@ int update_loadavg(void); ProcessTree_T *findprocess(int, ProcessTree_T *, int); -int initprocesstree(void); -void delprocesstree(void); - +int initprocesstree(ProcessTree_T **, int*, ProcessTree_T **, int*); +void delprocesstree(ProcessTree_T *, int); #endif diff -x CVS -ur monit.orig/validate.c monit/validate.c --- monit.orig/validate.c 2004-07-08 22:35:57.000000000 +0200 +++ monit/validate.c 2004-07-27 15:07:23.000000000 +0200 @@ -105,6 +105,11 @@ static int check_timeout(Service_T); static int compare_value(int, int, int); +ProcessTree_T *ptree=NULL; +int ptreesize=0; +ProcessTree_T *oldptree=NULL; +int oldptreesize=0; + /* ---------------------------------------------------------------- Public */ @@ -123,7 +128,7 @@ log("Update of loadavg has failed!\n"); if(Run.doprocess) - initprocesstree(); + initprocesstree(&ptree, &ptreesize, &oldptree, &oldptreesize); for(s= servicelist; s; s= s->next) { if(s->visited) @@ -137,7 +142,7 @@ } if(Run.doprocess) - delprocesstree(); + delprocesstree(oldptree, oldptreesize); reset_depend(); @@ -177,6 +182,7 @@ } else { log("'%s' failed to get service data\n", s->name); } + } /* Test each host:port and protocol in the service's portlist */