gc.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C), 2000-2002 by Contributors to the monit codebase. 
00003  * All Rights Reserved.
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License as
00007  * published by the Free Software Foundation; either version 2 of the
00008  * License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018  */
00019 
00020 #include <config.h>
00021 
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 
00025 #include "monitor.h"
00026 #include "protocol.h"
00027 
00028 
00029 /* Private prototypes */
00030 static void _gcpl(Process_T*);
00031 static void _gcppl(Port_T*);
00032 static void _gcpcl(Checksum_T*);
00033 static void _gcpql(Resource_T*);
00034 static void _gcppil(ProcInfo_T*);
00035 
00036 
00048 /* ------------------------------------------------------------------ Public */
00049 
00050 
00051 void gc() {
00052 
00053   gc_protocols();
00054   if(processlist) _gcpl(&processlist);
00055   if(mygroup) free(mygroup);
00056   
00057 }
00058 
00059 
00060 void gc_process(Process_T *p) {
00061 
00062   int i;
00063   
00064   if((*p)->portlist) {
00065     
00066     _gcppl(&(*p)->portlist);
00067 
00068   }
00069 
00070   if((*p)->checksumlist) {
00071     
00072     _gcpcl(&(*p)->checksumlist);
00073 
00074   }
00075 
00076   if((*p)->maillist) {
00077 
00078     gc_mail_list(&(*p)->maillist);
00079 
00080   }
00081 
00082   if((*p)->resourcelist) {
00083     
00084     _gcpql(&(*p)->resourcelist);
00085     
00086   }
00087 
00088   if((*p)->procinfo) {
00089 
00090     _gcppil(&(*p)->procinfo);
00091 
00092   }
00093   
00094   free((*p)->name);
00095   free((*p)->pidfile);
00096   free((*p)->group);
00097   if((*p)->start) {
00098     for(i= 0; (*p)->start->arg[i]; i++)
00099     free((*p)->start->arg[i]);
00100     free((*p)->start);
00101   }
00102   if((*p)->stop) {
00103     for(i= 0; (*p)->stop->arg[i]; i++)
00104     free((*p)->stop->arg[i]);
00105     free((*p)->stop);
00106   }
00107   (*p)->next= NULL;
00108   free(*p);
00109 
00110 }
00111   
00112 
00113 void gc_mail_list(Mail_T *m) {
00114   
00115   if((*m)->next)
00116       gc_mail_list(&(*m)->next);
00117   
00118   free((*m)->to);
00119   free((*m)->from);
00120   free((*m)->subject);
00121   free((*m)->message);
00122   free((*m)->opt_message);
00123   free(*m);
00124   *m= NULL;
00125   
00126 }
00127 
00128     
00129 /* ----------------------------------------------------------------- Private */
00130 
00131 
00132 static void _gcpl(Process_T *p) {
00133   
00134   if((*p)->next) {
00135     
00136     _gcpl(&(*p)->next);
00137     
00138   }
00139   
00140   gc_process(&(*p));
00141   *p= NULL;
00142     
00143 }
00144 
00145 
00146 static void _gcppl(Port_T *p) {
00147   
00148   if((*p)->next) {
00149     
00150     _gcppl(&(*p)->next);
00151     
00152   }
00153 
00154   free((*p)->hostname);
00155   free((*p)->request);
00156   free(*p);
00157   *p= NULL;
00158 
00159 }
00160 
00161 
00162 static void _gcpcl(Checksum_T *p) {
00163   
00164   if((*p)->next) {
00165     
00166     _gcpcl(&(*p)->next);
00167     
00168   }
00169 
00170   free((*p)->file); 
00171   free((*p)->md5);
00172   free(*p);
00173   *p= NULL;
00174 
00175 }
00176 
00177 
00178 static void _gcpql(Resource_T *q) {
00179 
00180   if((*q)->next) {
00181 
00182     _gcpql(&(*q)->next);
00183 
00184   }
00185 
00186   free(*q);
00187   *q= NULL;
00188   
00189 }
00190 
00191 
00192 static void _gcppil(ProcInfo_T *pi) {
00193 
00194   free(*pi);
00195   *pi= NULL;
00196 
00197 }