4 * Kern Sibbald, March MM
10 Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of
15 the License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public
23 License along with this program; if not, write to the Free
24 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
32 /* Imported Functions */
33 extern void *handle_client_request(void *dir_sock);
35 /* Forward referenced functions */
36 void terminate_filed(int sig);
38 /* Exported variables */
48 #define CONFIG_FILE "./bacula-fd.conf" /* default config file */
50 static char *configfile = NULL;
51 static int foreground = 0;
52 static int inetd_request = 0;
53 static workq_t dir_workq; /* queue of work from Director */
55 CLIENT *me; /* my resource */
60 "\nVersion: " VERSION " (" BDATE ")\n\n"
61 "Usage: filed [-f -s] [-c config_file] [-d debug_level] [config_file]\n"
62 " -c <file> use <file> as configuration file\n"
63 " -dnn set debug level to nn\n"
64 " -f run in foreground (for debugging)\n"
67 " -s no signals (for debugging)\n"
68 " -t test configuration file and exit\n"
70 " -v verbose user messages\n"
71 " -? print this message.\n"
77 /*********************************************************************
79 * Main Bacula Unix Client Program
83 #define main BaculaMain
85 int main (int argc, char *argv[])
88 int no_signals = FALSE;
89 int test_config = FALSE;
95 my_name_is(argc, argv, "filed");
97 daemon_start_time = time(NULL);
99 memset(&last_job, 0, sizeof(last_job));
101 while ((ch = getopt(argc, argv, "c:d:fg:istu:v?")) != -1) {
103 case 'c': /* configuration file */
104 if (configfile != NULL) {
107 configfile = bstrdup(optarg);
110 case 'd': /* debug level */
111 debug_level = atoi(optarg);
112 if (debug_level <= 0) {
117 case 'f': /* run in foreground */
121 case 'g': /* set group */
126 inetd_request = TRUE;
136 case 'u': /* set userid */
140 case 'v': /* verbose */
154 if (configfile != NULL)
156 configfile = bstrdup(*argv);
165 init_signals(terminate_filed);
168 if (configfile == NULL) {
169 configfile = bstrdup(CONFIG_FILE);
172 parse_config(configfile);
175 director = (DIRRES *)GetNextRes(R_DIRECTOR, NULL);
178 Emsg1(M_ABORT, 0, _("No Director resource defined in %s\n"),
183 me = (CLIENT *)GetNextRes(R_CLIENT, NULL);
186 Emsg1(M_ABORT, 0, _("No File daemon resource defined in %s\n\
187 Without that I don't know who I am :-(\n"), configfile);
189 my_name_is(0, NULL, me->hdr.name);
192 me->messages = (MSGS *)GetNextRes(R_MSGS, NULL);
195 Emsg1(M_ABORT, 0, _("No Messages resource defined in %s\n"), configfile);
198 close_msg(NULL); /* close temp message handler */
199 init_msg(NULL, me->messages); /* open user specified message handler */
201 working_directory = me->working_directory;
207 if (!foreground &&!inetd_request) {
209 init_stack_dump(); /* set new pid */
214 /* Maximum 1 daemon at a time */
215 create_pid_file(me->pid_directory, "bacula-fd", me->FDport);
221 set_thread_concurrency(10);
223 start_watchdog(); /* start watchdog thread */
226 /* Socket is on fd 0 */
227 BSOCK *bs = init_bsock(NULL, 0, "client", "unknown client", me->FDport);
228 handle_client_request((void *)bs);
230 /* Become server, and handle requests */
231 Dmsg1(10, "filed: listening on port %d\n", me->FDport);
232 bnet_thread_server(me->FDaddr, me->FDport, me->MaxConcurrentJobs,
233 &dir_workq, handle_client_request);
237 exit(0); /* should never get here */
240 void terminate_filed(int sig)
244 if (configfile != NULL) {
247 if (debug_level > 5) {
248 print_memory_pool_stats();
250 delete_pid_file(me->pid_directory, "bacula-fd", me->FDport);
251 free_config_resources();
253 close_memory_pool(); /* release free memory in pool */
254 sm_dump(False); /* dump orphaned buffers */