summaryrefslogtreecommitdiff
path: root/cleopatre
diff options
context:
space:
mode:
authorBelkadi & Buret2011-06-27 18:47:24 +0200
committerBelkadi & Buret2011-06-30 15:16:40 +0200
commit48d3c34eb9786d6fd870ab7f39031fe3c5c92db0 (patch)
treed578f47f29cf6a865dfe43b2ef79a5c9ae43d502 /cleopatre
parent657c32e0500e2e45760b4374137319dfdd9b2182 (diff)
cleo/app/managerd: fix possible incoherent read of hpav.info, refs #2449
managerd reads the contents of hpav.info when it receives a signal from plcd. Reading hpav.info one value at a time may result in an incoherent end result if the file is updated by plcd between the reads. This commit: - modifies managerd to read all the values at once by using the new libspid_hpav_info_read_file(). - updates managerd to use the new structure libspid_hpav_info_t.
Diffstat (limited to 'cleopatre')
-rw-r--r--cleopatre/application/managerd/src/managerd.c51
1 files changed, 14 insertions, 37 deletions
diff --git a/cleopatre/application/managerd/src/managerd.c b/cleopatre/application/managerd/src/managerd.c
index 7feedcb4c7..c93f6d85bf 100644
--- a/cleopatre/application/managerd/src/managerd.c
+++ b/cleopatre/application/managerd/src/managerd.c
@@ -36,7 +36,6 @@
* and has now to be processed. */
volatile sig_atomic_t is_process_signal_needed;
-
/**
* Handle SIGHUP reception.
*
@@ -64,72 +63,55 @@ int
managerd_process_signal (struct managerd_ctx *ctx)
{
/* hpav.info */
- char status[LIBSPID_HPAV_INFO_STATUS_MAX_LEN];
- char cco[LIBSPID_HPAV_INFO_CCO_MAX_LEN];
- char is_backup_cco_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
- char is_sc_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
- char is_sc_button_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
+ libspid_hpav_info_t hpav_info;
+ memset (&hpav_info, 0, sizeof (libspid_hpav_info_t));
assert (NULL != ctx);
/* read hpav.info file contents */
- if ((LIBSPID_SUCCESS != libspid_config_read_item (LIBSPID_HPAV_INFO_PATH,
- LIBSPID_HPAV_INFO_LABEL_STATUS, status,
- LIBSPID_HPAV_INFO_STATUS_MAX_LEN))
- || (LIBSPID_SUCCESS != libspid_config_read_item (LIBSPID_HPAV_INFO_PATH,
- LIBSPID_HPAV_INFO_LABEL_CCO, cco,
- LIBSPID_HPAV_INFO_CCO_MAX_LEN))
- || (LIBSPID_SUCCESS != libspid_config_read_item (LIBSPID_HPAV_INFO_PATH,
- LIBSPID_HPAV_INFO_LABEL_BACKUP_CCO, is_backup_cco_str,
- LIBSPID_BOOLEAN_STR_MAX_LEN))
- || (LIBSPID_SUCCESS != libspid_config_read_item (LIBSPID_HPAV_INFO_PATH,
- LIBSPID_HPAV_INFO_LABEL_SC, is_sc_str, LIBSPID_BOOLEAN_STR_MAX_LEN))
- || (LIBSPID_SUCCESS != libspid_config_read_item (LIBSPID_HPAV_INFO_PATH,
- LIBSPID_HPAV_INFO_LABEL_SC_BUTTON, is_sc_button_str,
- LIBSPID_BOOLEAN_STR_MAX_LEN)))
+ if (libspid_hpav_info_read_file (&hpav_info) != LIBSPID_SUCCESS)
{
syslog (LOG_WARNING, "libspid config read item failed");
return -1;
}
- if (strcmp (status, ctx->hpav_info.status)
- || (LIBSPID_GET_BOOLEAN (is_sc_str) != ctx->hpav_info.is_sc))
+ if (strcmp (hpav_info.status, ctx->hpav_info.status)
+ || (hpav_info.is_sc != ctx->hpav_info.is_sc))
{
/* attachment */
- if (0 > led_attachment_event (ctx, status,
- LIBSPID_GET_BOOLEAN (is_sc_str)))
+ if (0 > led_attachment_event (ctx, hpav_info.status, hpav_info.is_sc))
{
syslog (LOG_WARNING, "led attachment event failed");
return -1;
}
/* save values in managerd context */
- strcpy (ctx->hpav_info.status, status);
- ctx->hpav_info.is_sc = LIBSPID_GET_BOOLEAN (is_sc_str);
+ strcpy (ctx->hpav_info.status, hpav_info.status);
+ ctx->hpav_info.is_sc = hpav_info.is_sc;
}
- if (strcmp (cco, ctx->hpav_info.cco))
+ if (strcmp (hpav_info.cco, ctx->hpav_info.cco))
{
/* LED1 */
- if (0 > led1_event (ctx, cco))
+ if (0 > led1_event (ctx, hpav_info.cco))
{
syslog (LOG_WARNING, "led1 event failed");
return -1;
}
/* save value in managerd context */
- strcpy (ctx->hpav_info.cco, cco);
+ strcpy (ctx->hpav_info.cco, hpav_info.cco);
}
- if (LIBSPID_GET_BOOLEAN (is_backup_cco_str) != ctx->hpav_info.is_backup_cco)
+ if (hpav_info.is_backup_cco != ctx->hpav_info.is_backup_cco)
{
/* LED2 */
- if (0 > led2_event (ctx, LIBSPID_GET_BOOLEAN (is_backup_cco_str)))
+ if (0 > led2_event (ctx, hpav_info.is_backup_cco))
{
syslog (LOG_WARNING, "led2 event failed");
return -1;
}
/* save value in managerd context */
- ctx->hpav_info.is_backup_cco = LIBSPID_GET_BOOLEAN (is_backup_cco_str);
+ ctx->hpav_info.is_backup_cco = hpav_info.is_backup_cco;
}
return 0;
@@ -270,11 +252,6 @@ static int managerd_process(struct managerd_ctx *ctx)
*/
static int managerd_init(struct managerd_ctx *ctx)
{
- /* hpav.info */
- char is_backup_cco_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
- char is_sc_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
- char is_sc_button_str[LIBSPID_BOOLEAN_STR_MAX_LEN] = {0};
-
//Check arguments
assert(ctx != NULL);