2 * $Id: main.c,v 1.1 2005/04/25 16:42:24 paul Exp $
4 * This file is part of Quagga.
6 * Quagga is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * Quagga is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Quagga; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 #include <lib/version.h>
31 extern void test_init();
33 struct thread_master
*master
;
35 struct option longopts
[] =
37 { "daemon", no_argument
, NULL
, 'd'},
38 { "config_file", required_argument
, NULL
, 'f'},
39 { "help", no_argument
, NULL
, 'h'},
40 { "vty_addr", required_argument
, NULL
, 'A'},
41 { "vty_port", required_argument
, NULL
, 'P'},
42 { "version", no_argument
, NULL
, 'v'},
49 "Make the daemon exit\n")
54 static int timer_count
;
56 test_timer (struct thread
*thread
)
58 int *count
= THREAD_ARG(thread
);
60 printf ("run %d of timer\n", (*count
)++);
61 thread_add_timer (master
, test_timer
, count
, 5);
68 thread_add_timer (master
, test_timer
, &timer_count
, 10);
74 install_element (VIEW_NODE
, &daemon_exit_cmd
);
77 /* Help information display. */
79 usage (char *progname
, int status
)
82 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
85 printf ("Usage : %s [OPTION...]\n\
86 Daemon which does 'slow' things.\n\n\
87 -d, --daemon Runs in daemon mode\n\
88 -f, --config_file Set configuration file name\n\
89 -A, --vty_addr Set vty's bind address\n\
90 -P, --vty_port Set vty's port number\n\
91 -v, --version Print program version\n\
92 -h, --help Display this help and exit\n\
94 Report bugs to %s\n", progname
, ZEBRA_BUG_ADDRESS
);
102 main (int argc
, char **argv
)
105 char *vty_addr
= NULL
;
109 struct thread thread
;
110 char *config_file
= NULL
;
112 /* Set umask before anything for security */
115 /* get program name */
116 progname
= ((p
= strrchr (argv
[0], '/')) ? ++p
: argv
[0]);
119 master
= thread_master_create ();
125 opt
= getopt_long (argc
, argv
, "dhf:A:P:v", longopts
, 0);
135 config_file
= optarg
;
144 /* Deal with atoi() returning 0 on failure */
145 if (strcmp(optarg
, "0") == 0)
150 vty_port
= atoi (optarg
);
151 vty_port
= (vty_port
? vty_port
: 4000);
154 print_version (progname
);
171 /* OSPF vty inits. */
176 /* Change to the daemon program. */
177 if (daemon_mode
&& daemon (0, 0) < 0)
179 fprintf(stderr
, "daemon failed: %s", strerror(errno
));
183 /* Create VTY socket */
184 vty_serv_sock (vty_addr
, vty_port
, "/tmp/.heavy.sock");
186 /* Configuration file read*/
189 vty_read_config (config_file
, NULL
);
195 /* Fetch next active thread. */
196 while (thread_fetch (master
, &thread
))
197 thread_call (&thread
);