]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/filed.c
Fix reporting jobs from state file + misc
[bacula/bacula] / bacula / src / filed / filed.c
index 1c321e7d7bab7181d98d6cf621485db91a2e8831..bd8fd3570449776cec7b62a8a5531f82d1b37be2 100644 (file)
@@ -7,7 +7,7 @@
  *
  */
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2000-2004 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -41,10 +41,10 @@ char OK_msg[]   = "2000 OK\n";
 char TERM_msg[] = "2999 Terminate\n";
 
 
-#ifdef HAVE_CYGWIN
-int win32_client = 1;
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
+const int win32_client = 1;
 #else
-int win32_client = 0;
+const int win32_client = 0;
 #endif
 
 
@@ -81,9 +81,10 @@ static void usage()
  *  Main Bacula Unix Client Program                       
  *
  */
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
 #define main BaculaMain
 #endif
+
 int main (int argc, char *argv[])
 {
    int ch;
@@ -99,8 +100,6 @@ int main (int argc, char *argv[])
    init_msg(NULL, NULL);
    daemon_start_time = time(NULL);
 
-   memset(&last_job, 0, sizeof(last_job));
-
    while ((ch = getopt(argc, argv, "c:d:fg:istu:v?")) != -1) {
       switch (ch) {
       case 'c':                    /* configuration file */
@@ -213,10 +212,11 @@ Without that I don't know who I am :-(\n"), configfile);
       init_stack_dump();             /* set new pid */
    }
 
-   drop(uid, gid);
-
    /* Maximum 1 daemon at a time */
    create_pid_file(me->pid_directory, "bacula-fd", me->FDport);
+   read_state_file(me->working_directory, "bacula-fd", me->FDport);
+
+   drop(uid, gid);
 
 #ifdef BOMB
    me += 1000000;
@@ -226,9 +226,14 @@ Without that I don't know who I am :-(\n"), configfile);
 
    start_watchdog();                 /* start watchdog thread */
 
+   init_jcr_subsystem();             /* start JCR watchdogs etc. */
+
    if (inetd_request) {
       /* Socket is on fd 0 */         
-      BSOCK *bs = init_bsock(NULL, 0, "client", "unknown client", me->FDport);
+      struct sockaddr_in client_addr;
+      memset(&client_addr, 0, sizeof(client_addr));
+      BSOCK *bs = init_bsock(NULL, 0, "client", "unknown client", me->FDport, 
+                            &client_addr);
       handle_client_request((void *)bs);
    } else {
       /* Become server, and handle requests */
@@ -237,23 +242,23 @@ Without that I don't know who I am :-(\n"), configfile);
                      &dir_workq, handle_client_request);
    }
 
-   term_msg();
+   terminate_filed(0);
    exit(0);                          /* should never get here */
 }
 
 void terminate_filed(int sig)
 {
-   stop_watchdog();
-
    if (configfile != NULL) {
       free(configfile);
    }
    if (debug_level > 5) {
       print_memory_pool_stats(); 
    }
+   write_state_file(me->working_directory, "bacula-fd", me->FDport);
    delete_pid_file(me->pid_directory, "bacula-fd", me->FDport);
    free_config_resources();
    term_msg();
+   stop_watchdog();
    close_memory_pool();              /* release free memory in pool */
    sm_dump(False);                   /* dump orphaned buffers */
    exit(1);