]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/filed.c
Fix: clock diff, Dan's patch, Nic's patch, segfault
[bacula/bacula] / bacula / src / filed / filed.c
index a9d805cb4bd210103fd18f167717203792bb0827..1c321e7d7bab7181d98d6cf621485db91a2e8831 100644 (file)
 #include "filed.h"
 
 /* Imported Functions */
-extern void handle_client_request(void *dir_sock);
+extern void *handle_client_request(void *dir_sock);
 
 /* Forward referenced functions */
 void terminate_filed(int sig);
 
 /* Exported variables */
+CLIENT *me;                          /* my resource */
+char OK_msg[]   = "2000 OK\n";
+char TERM_msg[] = "2999 Terminate\n";
 
 
 #ifdef HAVE_CYGWIN
@@ -52,19 +55,21 @@ static int foreground = 0;
 static int inetd_request = 0;
 static workq_t dir_workq;            /* queue of work from Director */
 
-CLIENT *me;                          /* my resource */
 
 static void usage()
 {
    fprintf(stderr, _(
-"\nVersion: " VERSION " (" DATE ")\n\n"
-"Usage: filed [-f -s] [-c config_file] [-d debug_level] [config_file]\n"  
+"\nVersion: " VERSION " (" BDATE ")\n\n"
+"Usage: bacula-fd [-f -s] [-c config_file] [-d debug_level]\n"  
 "        -c <file>   use <file> as configuration file\n"
 "        -dnn        set debug level to nn\n"
 "        -f          run in foreground (for debugging)\n"
+"        -g          groupid\n"
 "        -i          inetd request\n"
 "        -s          no signals (for debugging)\n"
 "        -t          test configuration file and exit\n"
+"        -u          userid\n"
+"        -v          verbose user messages\n"
 "        -?          print this message.\n"
 "\n"));         
    exit(1);
@@ -85,48 +90,63 @@ int main (int argc, char *argv[])
    int no_signals = FALSE;
    int test_config = FALSE;
    DIRRES *director;
+   char *uid = NULL;
+   char *gid = NULL;
 
    init_stack_dump();
-   my_name_is(argc, argv, "filed");
+   my_name_is(argc, argv, "bacula-fd");
+   textdomain("bacula-fd");
    init_msg(NULL, NULL);
    daemon_start_time = time(NULL);
 
    memset(&last_job, 0, sizeof(last_job));
 
-   while ((ch = getopt(argc, argv, "c:d:fist?")) != -1) {
+   while ((ch = getopt(argc, argv, "c:d:fg:istu:v?")) != -1) {
       switch (ch) {
-         case 'c':                    /* configuration file */
-           if (configfile != NULL) {
-              free(configfile);
-           }
-           configfile = bstrdup(optarg);
-           break;
-
-         case 'd':                    /* debug level */
-           debug_level = atoi(optarg);
-           if (debug_level <= 0) {
-              debug_level = 1; 
-           }
-           break;
-
-         case 'f':                    /* run in foreground */
-           foreground = TRUE;
-           break;
-
-         case 'i':
-           inetd_request = TRUE;
-           break;
-         case 's':
-           no_signals = TRUE;
-           break;
-
-         case 't':
-           test_config = TRUE;
-           break;
-
-         case '?':
-        default:
-           usage();
+      case 'c':                    /* configuration file */
+        if (configfile != NULL) {
+           free(configfile);
+        }
+        configfile = bstrdup(optarg);
+        break;
+
+      case 'd':                    /* debug level */
+        debug_level = atoi(optarg);
+        if (debug_level <= 0) {
+           debug_level = 1; 
+        }
+        break;
+
+      case 'f':                    /* run in foreground */
+        foreground = TRUE;
+        break;
+
+      case 'g':                    /* set group */
+        gid = optarg;
+        break;
+
+      case 'i':
+        inetd_request = TRUE;
+        break;
+      case 's':
+        no_signals = TRUE;
+        break;
+
+      case 't':
+        test_config = TRUE;
+        break;
+
+      case 'u':                    /* set userid */
+        uid = optarg;
+        break;
+
+      case 'v':                    /* verbose */
+        verbose++;
+        break;
+
+      case '?':
+      default:
+        usage();
 
       }  
    }
@@ -181,7 +201,8 @@ Without that I don't know who I am :-(\n"), configfile);
       close_msg(NULL);               /* close temp message handler */
       init_msg(NULL, me->messages);   /* open user specified message handler */
    }
-   working_directory = me->working_directory;
+
+   set_working_directory(me->working_directory);
 
    if (test_config) {
       terminate_filed(0);
@@ -192,9 +213,10 @@ Without that I don't know who I am :-(\n"), configfile);
       init_stack_dump();             /* set new pid */
    }
 
-   if (!inetd_request) {
-      create_pid_file(me->pid_directory, "bacula-fd", me->FDport);
-   }
+   drop(uid, gid);
+
+   /* Maximum 1 daemon at a time */
+   create_pid_file(me->pid_directory, "bacula-fd", me->FDport);
 
 #ifdef BOMB
    me += 1000000;
@@ -205,6 +227,7 @@ Without that I don't know who I am :-(\n"), configfile);
    start_watchdog();                 /* start watchdog thread */
 
    if (inetd_request) {
+      /* Socket is on fd 0 */         
       BSOCK *bs = init_bsock(NULL, 0, "client", "unknown client", me->FDport);
       handle_client_request((void *)bs);
    } else {