Correzioni varie al codice ed alle relative citazioni
[gapil.git] / sources / FortuneServer.c
index e767c1c849e8252650c5e91f0fce1c73227f05f4..5f10062960b8dfddfa5daee88c06add0f5fa7d7d 100644 (file)
@@ -26,7 +26,7 @@
  *
  * Usage: fortuned -h give all info
  *
- * $Id: FortuneServer.c,v 1.2 2002/08/18 14:38:04 piccardi Exp $
+ * $Id: FortuneServer.c,v 1.3 2002/08/18 23:24:44 piccardi Exp $
  *
  ****************************************************************/
 /* 
 void usage(void);
 int FortuneParse(char *file, char **fortune, int n);
 
+/* name of well known fifo */
+char *fifoname = "/tmp/fortune.fifo";
 int main(int argc, char *argv[])
 {
 /* Variables definition */
     int i, n = 0;
     char *fortunefilename = "/usr/share/games/fortunes/kids";
-    char *fifoname = "/tmp/fortune.fifo";
     char **fortune;
     char line[80];
     int fifo_server, fifo_client;
@@ -93,6 +94,9 @@ int main(int argc, char *argv[])
      *               Main code beginning
      * 
      * ***********************************************************/
+    Signal(SIGTERM, HandSIGTERM);
+    Signal(SIGINT, HandSIGTERM);
+    Signal(SIGQUIT, HandSIGTERM);
     if (n==0) usage();          /* if no pool depth exit printing usage info */
     i = FortuneParse(fortunefilename, fortune, n);          /* parse phrases */
     for (n=0; n<i; n++) debug("%s\n\n", fortune[n]);
@@ -136,3 +140,10 @@ void usage(void) {
     printf("  -n XXX        set pool depth\n");
     exit(1);
 }
+/*
+ * Signal Handler to manage termination
+ */
+void HandSIGTERM(int signo) {
+    unlink(fifoname);
+    exit(0);
+}