summaryrefslogtreecommitdiff
path: root/cleopatre/devkit
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/devkit')
-rw-r--r--cleopatre/devkit/plcd/src/plcd_main.c133
1 files changed, 70 insertions, 63 deletions
diff --git a/cleopatre/devkit/plcd/src/plcd_main.c b/cleopatre/devkit/plcd/src/plcd_main.c
index 6c448affa2..1140fae52d 100644
--- a/cleopatre/devkit/plcd/src/plcd_main.c
+++ b/cleopatre/devkit/plcd/src/plcd_main.c
@@ -203,6 +203,74 @@ plcd_init (plcd_ctx_t *ctx)
return 0;
}
+static void
+plcd_daemon_main (plcd_ctx_t *ctx)
+{
+ PLCD_ASSERT (ctx);
+
+ int init_nb, init_ret = -1;
+
+ if (0 <= plcd_init (ctx))
+ {
+ /* Show PLCD version. */
+ syslog (LOG_NOTICE, "PLC Daemon (%s) Running\n",
+ VERSION);
+
+ /* initialize the AV / EoC stack
+ * and loop (PLCD_INIT_RETRIES maximum) until successful init */
+ for (init_nb = 0; init_nb < PLCD_INIT_RETRIES; init_nb++)
+ {
+ if (0 == (init_ret = plcd_stack_init (ctx)))
+ {
+ break;
+ }
+ }
+ if (0 != init_ret)
+ {
+ syslog (LOG_WARNING, "stack init failed\n");
+ exit (EXIT_FAILURE);
+ }
+
+ pid_t pid = getpid ();
+
+ /* register to hpav.conf and hpav.info files update */
+ if ((LIBSPID_SUCCESS != libspid_system_file_update_register (
+ pid, LIBSPID_HPAV_CONF_PATH, plcd_signal_handler))
+ || (LIBSPID_SUCCESS != libspid_system_file_update_register (
+ pid, LIBSPID_HPAV_INFO_PATH, plcd_signal_handler)))
+ {
+ exit (EXIT_FAILURE);
+ }
+
+ /* register to mcast.info file update */
+ if (libspid_system_file_update_register (
+ pid, LIBSPID_MULTICAST_INFO_PATH, plcd_signal_handler)
+ != LIBSPID_SUCCESS)
+ {
+ exit (EXIT_FAILURE);
+ }
+
+ /* Catch SIGTERM. */
+ signal (SIGTERM, plcd_signal_handler);
+
+ /* Initialize autoswitch timer. */
+ plcd_autoswitch_timer_init ();
+
+ /* now get all events from plcdrv (i.e. DRV MME-s) */
+ while (!exit_requested)
+ {
+ if (0 > plcd_stack_event_dispatch (ctx))
+ {
+ exit (EXIT_FAILURE);
+ }
+ }
+
+ libspid_system_file_update_unregister (pid, LIBSPID_HPAV_CONF_PATH);
+ libspid_system_file_update_unregister (pid, LIBSPID_HPAV_INFO_PATH);
+ libspid_system_file_update_unregister (pid, LIBSPID_MULTICAST_INFO_PATH);
+ }
+}
+
/**
* Initialize default variables in context.
*
@@ -247,7 +315,7 @@ main (int argc, char **argv)
{
/* Main context. */
static plcd_ctx_t plcd_ctx;
- int c = 0, opt_index = 0, init_nb = 0, init_ret = -1;
+ int c = 0, opt_index = 0;
/* Open log process. */
openlog (argv[0], 0, LOG_DAEMON);
@@ -259,16 +327,6 @@ main (int argc, char **argv)
{"info_file", required_argument, NULL, 'i'},
{"version", no_argument, NULL, 'v'}};
- /* init context */
- if (0 > plcd_init (&plcd_ctx))
- {
- exit (EXIT_FAILURE);
- }
-
- /* show PLCD version */
- syslog (LOG_NOTICE, "PLC Daemon (%s) Running\n", VERSION);
-
-
/* process options */
while (-1 != (c = getopt_long_only (argc, argv, "c:i:v:", long_opts,
&opt_index)))
@@ -293,59 +351,8 @@ main (int argc, char **argv)
}
}
- /* initialize the AV / EoC stack
- * and loop (PLCD_INIT_RETRIES maximum) until successful init */
- for (init_nb = 0; init_nb < PLCD_INIT_RETRIES; init_nb++)
- {
- if (0 == (init_ret = plcd_stack_init (&plcd_ctx)))
- {
- break;
- }
- }
- if (0 != init_ret)
- {
- syslog (LOG_WARNING, "stack init failed\n");
- exit (EXIT_FAILURE);
- }
-
- pid_t pid = getpid ();
-
- /* register to hpav.conf and hpav.info files update */
- if ((LIBSPID_SUCCESS != libspid_system_file_update_register (pid,
- LIBSPID_HPAV_CONF_PATH, plcd_signal_handler))
- || (LIBSPID_SUCCESS != libspid_system_file_update_register (pid,
- LIBSPID_HPAV_INFO_PATH, plcd_signal_handler)))
- {
- exit (EXIT_FAILURE);
- }
-
- /* register to mcast.info file update */
- if (libspid_system_file_update_register (pid,
- LIBSPID_MULTICAST_INFO_PATH,
- plcd_signal_handler)
- != LIBSPID_SUCCESS)
- {
- exit (EXIT_FAILURE);
- }
-
- /* Catch SIGTERM. */
- signal (SIGTERM, plcd_signal_handler);
-
- /* Initialize autoswitch timer. */
- plcd_autoswitch_timer_init ();
-
- /* now get all events from plcdrv (i.e. DRV MME-s) */
- while (!exit_requested)
- {
- if (0 > plcd_stack_event_dispatch (&plcd_ctx))
- {
- exit (EXIT_FAILURE);
- }
- }
+ plcd_daemon_main (&plcd_ctx);
- libspid_system_file_update_unregister (pid, LIBSPID_HPAV_CONF_PATH);
- libspid_system_file_update_unregister (pid, LIBSPID_HPAV_INFO_PATH);
- libspid_system_file_update_unregister (pid, LIBSPID_MULTICAST_INFO_PATH);
plcd_main_uninit (&plcd_ctx);
closelog ();
exit (EXIT_SUCCESS);