summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cleopatre/devkit/plcd/src/plcd_main.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/cleopatre/devkit/plcd/src/plcd_main.c b/cleopatre/devkit/plcd/src/plcd_main.c
index d1f71fb238..d0bc0d0f8c 100644
--- a/cleopatre/devkit/plcd/src/plcd_main.c
+++ b/cleopatre/devkit/plcd/src/plcd_main.c
@@ -114,11 +114,6 @@ plcd_init (plcd_ctx_t *ctx)
is_process_signal_needed = 0;
memset (&user_data, 0, sizeof (struct plcdrv_setpid));
memset (&ifr, 0, sizeof (struct ifreq));
- memset (ctx, 0, sizeof (plcd_ctx_t));
- ctx->hpav_info_path = LIBSPID_HPAV_INFO_PATH;
- ctx->hpav_conf_path = LIBSPID_HPAV_CONF_PATH;
- ctx->phy_conf_path = LIBSPID_PHY_CONF_PATH;
- ctx->internal_conf_path = LIBSPID_INTERNAL_CONF_PATH;
/* create an empty hpav.info file for writing default values */
if ((LIBSPID_SUCCESS != libspid_config_write_item (ctx->hpav_info_path,
@@ -209,14 +204,35 @@ plcd_init (plcd_ctx_t *ctx)
}
/**
+ * Initialize default variables in context.
+ *
+ * \param ctx plcd context
+ */
+static void
+plcd_main_init (plcd_ctx_t *ctx)
+{
+ PLCD_ASSERT (ctx);
+
+ memset (ctx, 0, sizeof (plcd_ctx_t));
+
+ ctx->hpav_info_path = LIBSPID_HPAV_INFO_PATH;
+ ctx->hpav_conf_path = LIBSPID_HPAV_CONF_PATH;
+ ctx->phy_conf_path = LIBSPID_PHY_CONF_PATH;
+ ctx->internal_conf_path = LIBSPID_INTERNAL_CONF_PATH;
+}
+
+/**
* Un-initialize PLC daemon.
*
* \param ctx plcd context
*/
static void
-plcd_uninit (plcd_ctx_t *ctx)
+plcd_main_uninit (plcd_ctx_t *ctx)
{
- close (ctx->plc_sock);
+ PLCD_ASSERT (ctx);
+
+ if (0 < ctx->plc_sock)
+ close (ctx->plc_sock);
}
/**
@@ -229,10 +245,11 @@ plcd_uninit (plcd_ctx_t *ctx)
int
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;
- /* main context */
- plcd_ctx_t ctx;
+ plcd_main_init (&plcd_ctx);
/* input program arguments */
struct option long_opts[] = {{"conf_file", required_argument, NULL, 'c'},
@@ -240,7 +257,7 @@ main (int argc, char **argv)
{"version", no_argument, NULL, 'v'}};
/* init context */
- if (0 > plcd_init (&ctx))
+ if (0 > plcd_init (&plcd_ctx))
{
exit (EXIT_FAILURE);
}
@@ -251,6 +268,7 @@ main (int argc, char **argv)
/* open log process */
openlog (argv[0], 0, LOG_DAEMON);
+
/* process options */
while (-1 != (c = getopt_long_only (argc, argv, "c:i:v:", long_opts,
&opt_index)))
@@ -259,11 +277,11 @@ main (int argc, char **argv)
{
case 'c':
/* HPAV config file */
- ctx.hpav_conf_path = optarg;
+ plcd_ctx.hpav_conf_path = optarg;
break;
case 'i':
/* HPAV info file */
- ctx.hpav_info_path = optarg;
+ plcd_ctx.hpav_info_path = optarg;
break;
case 'v':
/* version number */
@@ -279,7 +297,7 @@ main (int argc, char **argv)
* 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)))
+ if (0 == (init_ret = plcd_stack_init (&plcd_ctx)))
{
break;
}
@@ -319,7 +337,7 @@ main (int argc, char **argv)
/* now get all events from plcdrv (i.e. DRV MME-s) */
while (!exit_requested)
{
- if (0 > plcd_stack_event_dispatch (&ctx))
+ if (0 > plcd_stack_event_dispatch (&plcd_ctx))
{
exit (EXIT_FAILURE);
}
@@ -328,6 +346,6 @@ main (int argc, char **argv)
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_uninit (&ctx);
+ plcd_main_uninit (&plcd_ctx);
exit (EXIT_SUCCESS);
}