1 #define WITH_C99 /* For ul_gsa.h iterators */
10 #include <forb/forb-internal.h>
13 static struct option long_opts[] = {
14 { "daemon", optional_argument, NULL, 'd' },
15 { "id", required_argument, NULL, 'i' },
16 /* { "loglevel", required_argument, NULL, 'l' }, */
17 { "port", required_argument, NULL, 'p' },
24 printf("usage: forbrun [ options ] <forb-server>.so ... [-- <options for forb_main()>] \n");
25 printf(" -d, --daemon [pid-file] go to background after initialization of servers\n");
26 printf(" -i, --id <orb id> \n");
27 /* printf(" -l, --loglevel <number>|<domain>=<number>,...\n"); */
28 printf(" -p, --port <number> listen on a fixed port number\n");
31 int print_log_domain(ul_log_domain_t *domain, void *context)
33 printf("%s = %d\n", domain->name, domain->level);
37 struct forb_main_data {
40 int (*forb_main)(forb_orb orb, int argc, char *argv[]);
45 void *forb_main_thread(void *arg)
47 struct forb_main_data *data = arg;
49 ret = data->forb_main(data->orb, data->argc, data->argv);
54 int main(int argc, char *argv[])
57 bool opt_daemon = false;
58 char *opt_pidfile = NULL;
60 forb_init_attr_t attr = {
61 .orb_id = "org.frescor.fcb",
62 .peer_discovery_callback = NULL, /* TODO */
63 .peer_dead_callback = NULL, /* TODO */
65 #ifdef CONFIG_FORB_PROTO_INET_DEFAULT
66 .fixed_server_id = 0, /* TODO */
67 .redistribute_hellos = false , /* TODO */
72 while ((opt = getopt_long(argc, argv, "d::hil:p:", &long_opts[0], NULL)) != EOF) {
77 ul_logreg_for_each_domain(print_log_domain, NULL);
82 ret = ul_log_domain_arg2levels(optarg);
84 error(1, EINVAL, "Error parsing -l argument at char %d\n", ret);
98 exit(opt == 'h' ? 0 : 1);
101 attr.fixed_tcp_port = atol(optarg);
107 forb_daemon_prepare(opt_pidfile); /* == fork() */
109 orb = forb_init(&argc, &argv, &attr);
110 if (!orb) error(1, errno, "FORB initialization failed");
112 #if CONFIG_FCB_INET && !CONFIG_FORB_PROTO_INET_DEFAULT
113 ret = register_inet_port(orb);
114 if (ret) error(0, errno, "INET port registration failed");
117 for (i = optind; i < argc; i++) {
119 fosa_thread_id_t tid;
120 struct forb_main_data data;
122 data.filename = argv[i];
123 handle = dlopen(data.filename, RTLD_LOCAL|RTLD_LAZY);
125 error(1, errno, "dlopen(\"%s\") failed", data.filename);
126 data.forb_main = dlsym(handle, "forb_main");
128 error(1, errno, "Cannot find forb_main() in %s", data.filename);
131 data.argc = 0; /* TODO argc and argv after "--" */
132 data.argv = NULL; /* TODO argc and argv after "--" */
133 fosa_thread_create(&tid, NULL, forb_main_thread, &data);
135 forb_wait_for_server_ready(orb);
141 /* Allow other threads to continue execution, but exit
142 * ourselves (without exit()ing the whole process. */