+ /***** initialize the monitoring interface instance *****/
+ if (NULL == (tr->mons = mons_new(tr))) {
+ tr_crit("Error initializing monitoring interface instance.");
+ return 1;
+ }
+ /* Monitor our tids/trps instances */
+ tr->mons->tids = tr->tids;
+ tr->mons->trps = tr->trps;
+
+ /* Register monitoring handlers */
+ mons_register_handler(tr->mons, MON_CMD_SHOW, OPT_TYPE_SHOW_VERSION, tr_handle_version, NULL);
+ mons_register_handler(tr->mons, MON_CMD_SHOW, OPT_TYPE_SHOW_CONFIG_FILES, tr_handle_show_cfg_serial, tr->cfg_mgr);
+ mons_register_handler(tr->mons, MON_CMD_SHOW, OPT_TYPE_SHOW_UPTIME, tr_handle_uptime, &start_time);
+ mons_register_handler(tr->mons, MON_CMD_SHOW, OPT_TYPE_SHOW_RP_CLIENTS, tr_handle_show_rp_clients, tr->cfg_mgr);
+ tr_tid_register_mons_handlers(tr->tids, tr->mons);
+ tr_trp_register_mons_handlers(tr->trps, tr->mons);
+
+ /***** process configuration *****/
+ tr->cfgwatch=tr_cfgwatch_create(tr);
+ if (tr->cfgwatch == NULL) {
+ tr_crit("Unable to create configuration watcher object, exiting.");
+ return 1;
+ }
+ tr->cfgwatch->config_dir=opts.config_dir;
+ tr->cfgwatch->cfg_mgr=tr->cfg_mgr;
+ tr->cfgwatch->update_cb=tr_config_changed; /* handle configuration changes */
+ tr->cfgwatch->update_cookie=(void *)tr;
+ if (0 != tr_read_and_apply_config(tr->cfgwatch)) {
+ tr_crit("Error reading configuration, exiting.");
+ return 1;
+ }
+
+ /***** Exit here if we are just validating our configuration *****/
+ if (opts.validate_config_and_exit) {
+ printf("Valid configuration found in %s.\n", opts.config_dir);
+ return 0;
+ }
+ /***** Set up the event loop *****/
+ ev_base=tr_event_loop_init(); /* Set up the event loop */
+ if (ev_base==NULL) {
+ tr_crit("Error initializing event loop.");
+ return 1;
+ }
+
+ /* already set config_dir, fstat_list and n_files earlier */
+ if (0 != tr_cfgwatch_event_init(ev_base, tr->cfgwatch, &cfgwatch_ev)) {
+ tr_crit("Error initializing configuration file watcher.");
+ return 1;