Browse code

- FIFO DB interface - first steps

Bogdan-Andrei Iancu authored on 26/10/2003 19:21:08
Showing 1 changed files
... ...
@@ -87,11 +87,13 @@
87 87
 #include "mem/mem.h"
88 88
 #include "sr_module.h"
89 89
 #include "pt.h"
90
+#include "db/db_fifo.h"
90 91
 
91 92
 /* FIFO server vars */
92 93
 char *fifo=0; /* FIFO name */
93 94
 char* fifo_dir=DEFAULT_FIFO_DIR; /* dir where reply fifos are allowed */
94 95
 int fifo_mode=S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP ;
96
+char *fifo_db_url = 0;
95 97
 pid_t fifo_pid;
96 98
 /* file descriptors */
97 99
 static int fifo_read=0;
... ...
@@ -463,6 +465,9 @@ static void fifo_server(FILE *fifo_stream)
463 465
 
464 466
 	file_sep=command=file=0;
465 467
 
468
+	/* register a diagnostic FIFO command */
469
+	register_core_fifo();
470
+
466 471
 	while(1) {
467 472
 
468 473
 		/* commands must look this way ':<command>:[filename]' */
... ...
@@ -524,6 +529,7 @@ static void fifo_server(FILE *fifo_stream)
524 529
 consume:
525 530
 		if (file) { pkg_free(file); file=0;}
526 531
 		consume_request(fifo_stream);
532
+		DBG("**** done consume\n");
527 533
 	}
528 534
 }
529 535
 
... ...
@@ -551,9 +557,9 @@ int open_fifo_server()
551 557
 			LOG(L_ERR, "ERROR: open_fifo_server: cannot delete old fifo (%s):"
552 558
 					" %s\n", fifo, strerror(errno));
553 559
 			return -1;
560
+			}
554 561
 		}
555
-	}
556
-	 /* create FIFO ... */
562
+		/* create FIFO ... */
557 563
 		LOG(L_DBG, "DEBUG: open_fifo_server: FIFO stat failed: %s\n",
558 564
 			strerror(errno));
559 565
 		if ((mkfifo(fifo, fifo_mode)<0)) {
... ...
@@ -813,36 +819,50 @@ static int ps_fifo_cmd(FILE *stream, char *response_file )
813 819
 int register_core_fifo()
814 820
 {
815 821
 	if (register_fifo_cmd(print_fifo_cmd, FIFO_PRINT, 0)<0) {
816
-		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_PRINT);
822
+		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_PRINT);
817 823
 		return -1;
818 824
 	}
819 825
 	if (register_fifo_cmd(uptime_fifo_cmd, FIFO_UPTIME, 0)<0) {
820
-		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_UPTIME);
826
+		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_UPTIME);
821 827
 		return -1;
822 828
 	}
823 829
 	if (register_fifo_cmd(print_version_cmd, FIFO_VERSION, 0)<0) {
824
-		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_VERSION);
830
+		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n",FIFO_VERSION);
825 831
 		return -1;
826 832
 	}
827 833
 	if (register_fifo_cmd(pwd_cmd, FIFO_PWD, 0)<0) {
828
-		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_PWD);
834
+		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_PWD);
829 835
 		return -1;
830 836
 	}
831 837
 	if (register_fifo_cmd(arg_cmd, FIFO_ARG, 0)<0) {
832
-		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_ARG);
838
+		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_ARG);
833 839
 		return -1;
834 840
 	}
835 841
 	if (register_fifo_cmd(which_fifo_cmd, FIFO_WHICH, 0)<0) {
836
-		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_WHICH);
842
+		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_WHICH);
837 843
 		return -1;
838 844
 	}
839 845
 	if (register_fifo_cmd(ps_fifo_cmd, FIFO_PS, 0)<0) {
840
-		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_PS);
846
+		LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_PS);
841 847
 		return -1;
842 848
 	}
843 849
 	if (register_fifo_cmd(kill_fifo_cmd, FIFO_KILL, 0)<0) {
844
-		LOG(L_CRIT, "unable to register '%s' FIFO cmd\n", FIFO_KILL);
850
+		LOG(L_CRIT, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_KILL);
845 851
 		return -1;
846 852
 	}
853
+	if (fifo_db_url==0) {
854
+		LOG(L_WARN,"WARNING: no fifo_db_url given - "
855
+			"fifo DB commands disabled!\n");
856
+	} else if ( bind_dbmod(fifo_db_url)==0 ) {
857
+		if (register_fifo_cmd(db_fifo_cmd, FIFO_DB, 0)<0) {
858
+			LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_DB);
859
+			return -1;
860
+		} else {
861
+			/* call db_init() */
862
+		}
863
+	} else {
864
+		LOG(L_WARN,"WARNING: unable to find any db module - "
865
+			"fifo DB commands disabled!\n");
866
+	}
847 867
 	return 1;
848 868
 }