cleaner shutdown (*g* .. still segfaulting) if SIGTERM
authorhackbard <hackbard>
Tue, 1 Feb 2005 18:51:23 +0000 (18:51 +0000)
committerhackbard <hackbard>
Tue, 1 Feb 2005 18:51:23 +0000 (18:51 +0000)
nlsop_client.c

index f7938ed..0d52f94 100644 (file)
@@ -64,6 +64,7 @@ d3_lattice *gd3_l;
 info *gmy_info;
 int *gi;
 unsigned char dc;
+unsigned char shut_down;
 
 int get_data_and_calc(t_event *event,void *allineed);
 int nop(t_event *event,void *allineed);
@@ -319,6 +320,8 @@ void send_data(int signum) {
   network_send_chan(gnet,0,gd3_l->status,c*sizeof(unsigned char));
   network_send_chan(gnet,0,(unsigned char *)gd3_l->extra,c*sizeof(int));
   network_send_chan(gnet,0,(unsigned char *)gi,sizeof(int));
+
+  if(dc==DC_QUIT) shut_down=1;
 }
 
 
@@ -400,6 +403,8 @@ int main(int argc,char **argv)
   printf("idle, waiting for jobs ...\n");
   event_start(&event,NULL,get_data_and_calc,nop);
 
+  network_shutdown(&net);
+
   return 1;
 }
 
@@ -434,6 +439,7 @@ int get_data_and_calc(t_event *event,void *allineed) {
   gmy_info=&my_info;
   gi=&i;
   dc=0;
+  shut_down=0;
 
   printf("got a new job ...\n");
   
@@ -541,6 +547,14 @@ int get_data_and_calc(t_event *event,void *allineed) {
       dc=DC_QUIT;
     }
     if(i%my_info.s_rate==0) sputter(&d3_l);
+    if(shut_down) {
+      free(d3_l.status);
+      free(d3_l.extra);
+      free(c_profile);
+      free(n_e_loss);
+      free(nel_z);
+      event_stop(event); 
+    }
   }
 
   /* finished */