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 */
55 "\nVersion: " VERSION " (" DATE ")\n\n"
56 "Usage: filed [-f -s] [-c config_file] [-d debug_level] [config_file]\n"
57 " -c <file> use <file> as configuration file\n"
58 " -dnn set debug level to nn\n"
59 " -f run in foreground (for debugging)\n"
60 " -s no signals (for debugging)\n"
61 " -t test configuration file and exit\n"
62 " -? print this message.\n"
68 /*********************************************************************
70 * Main Bacula Unix Client Program
74 #define main BaculaMain
76 int main (int argc, char *argv[])
79 int no_signals = FALSE;
80 int test_config = FALSE;
81 CLIENT *me; /* my resource */
85 my_name_is(argc, argv, "filed");
86 daemon_start_time = time(NULL);
88 memset(&last_job, 0, sizeof(last_job));
90 while ((ch = getopt(argc, argv, "c:d:fst?")) != -1) {
92 case 'c': /* configuration file */
93 if (configfile != NULL) {
96 configfile = bstrdup(optarg);
99 case 'd': /* debug level */
100 debug_level = atoi(optarg);
101 if (debug_level <= 0) {
106 case 'f': /* run in foreground */
128 if (configfile != NULL)
130 configfile = bstrdup(*argv);
139 init_signals(terminate_filed);
142 if (configfile == NULL) {
143 configfile = bstrdup(CONFIG_FILE);
148 parse_config(configfile);
151 director = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
154 Emsg1(M_ABORT, 0, _("No Director resource defined in %s\n"),
159 me = (CLIENT *)GetNextRes(R_CLIENT, NULL);
162 Emsg1(M_ABORT, 0, _("No File daemon resource defined in %s\n\
163 Without that I don't know who I am :-(\n"), configfile);
165 my_name_is(0, (char **)NULL, me->hdr.name);
167 working_directory = me->working_directory;
175 init_stack_dump(); /* set new pid */
182 init_watchdog(); /* start watchdog thread */
184 /* Become server, and handle requests */
185 Dmsg1(10, "filed: listening on port %d\n", me->FDport);
186 bnet_thread_server(me->FDport, 10, &dir_workq, handle_client_request);
188 exit(0); /* should never get here */
191 void terminate_filed(int sig)
195 if (configfile != NULL) {
198 if (debug_level > 5) {
199 print_memory_pool_stats();
201 free_config_resources();
202 close_memory_pool(); /* free memory in pool */
204 sm_dump(False); /* dump orphaned buffers */