4 * Kern Sibbald, March MM
8 Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2 of
13 the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public
21 License along with this program; if not, write to the Free
22 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /* Imported Functions */
31 extern void handle_client_request(void *dir_sock);
33 /* Forward referenced functions */
34 void terminate_filed(int sig);
36 /* Exported variables */
46 #define CONFIG_FILE "./bacula-fd.conf" /* default config file */
48 static char *configfile = NULL;
49 static int foreground = 0;
50 static workq_t dir_workq; /* queue of work from Director */
51 static CLIENT *me; /* my resource */
56 "\nVersion: " VERSION " (" DATE ")\n\n"
57 "Usage: filed [-f -s] [-c config_file] [-d debug_level] [config_file]\n"
58 " -c <file> use <file> as configuration file\n"
59 " -dnn set debug level to nn\n"
60 " -f run in foreground (for debugging)\n"
61 " -s no signals (for debugging)\n"
62 " -t test configuration file and exit\n"
63 " -? print this message.\n"
69 /*********************************************************************
71 * Main Bacula Unix Client Program
75 #define main BaculaMain
77 int main (int argc, char *argv[])
80 int no_signals = FALSE;
81 int test_config = FALSE;
85 my_name_is(argc, argv, "filed");
87 daemon_start_time = time(NULL);
89 memset(&last_job, 0, sizeof(last_job));
91 while ((ch = getopt(argc, argv, "c:d:fst?")) != -1) {
93 case 'c': /* configuration file */
94 if (configfile != NULL) {
97 configfile = bstrdup(optarg);
100 case 'd': /* debug level */
101 debug_level = atoi(optarg);
102 if (debug_level <= 0) {
107 case 'f': /* run in foreground */
129 if (configfile != NULL)
131 configfile = bstrdup(*argv);
140 init_signals(terminate_filed);
143 if (configfile == NULL) {
144 configfile = bstrdup(CONFIG_FILE);
147 parse_config(configfile);
150 director = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
153 Emsg1(M_ABORT, 0, _("No Director resource defined in %s\n"),
158 me = (CLIENT *)GetNextRes(R_CLIENT, NULL);
161 Emsg1(M_ABORT, 0, _("No File daemon resource defined in %s\n\
162 Without that I don't know who I am :-(\n"), configfile);
164 my_name_is(0, NULL, me->hdr.name);
167 me->messages = (MSGS *)GetNextRes(R_MSGS, NULL);
170 Emsg1(M_ABORT, 0, _("No Messages resource defined in %s\n"), configfile);
173 close_msg(NULL); /* close temp message handler */
174 init_msg(NULL, me->messages); /* open user specified message handler */
176 working_directory = me->working_directory;
184 init_stack_dump(); /* set new pid */
187 create_pid_file(me->pid_directory, "bacula-fd", me->FDport);
193 start_watchdog(); /* start watchdog thread */
195 /* Become server, and handle requests */
196 Dmsg1(10, "filed: listening on port %d\n", me->FDport);
197 bnet_thread_server(me->FDport, 10, &dir_workq, handle_client_request);
199 exit(0); /* should never get here */
202 void terminate_filed(int sig)
206 if (configfile != NULL) {
209 if (debug_level > 5) {
210 print_memory_pool_stats();
212 delete_pid_file(me->pid_directory, "bacula-fd", me->FDport);
213 free_config_resources();
215 close_memory_pool(); /* release free memory in pool */
216 sm_dump(False); /* dump orphaned buffers */