Commit eb7cb06e authored by Lucas Russo's avatar Lucas Russo

libs/libhutils/*: add hutils_wait_clhd_timed () function

This functions performs the same as hutils_wait_clhd (),
apart from that it employs a busy loop timeout, calling
hutils_wait_chld () each time and exiting if the timeout
is over.
parent 278201e3
......@@ -94,6 +94,11 @@ int hutils_spawn_chld (const char *program, char *const argv[]);
* in the global LOG. Returns 0 in case of success and -1 in case of error */
int hutils_wait_chld (void);
/* Wait for a child process with a looped timeout, printing the exit status
* and possible errors in the global LOG. Returns 0 in case of success and
* -1 in case of error */
int hutils_wait_chld_timed (int timeout);
/* Clones a str NULL terminated string and return it to the called. Returns NULL
* in case of error */
char *hutils_clone_str (const char *str);
......
......@@ -30,6 +30,9 @@
CHECK_HAL_ERR(err, HAL_UTILS, "[hutils:utils]", \
hutils_err_str (err_type))
#define MIN_WAIT_TIME 1 /* in ms */
#define MSECS 1000 /* in seconds */
static char *_hutils_concat_strings_raw (const char *str1, const char* str2,
const char *str3, bool with_sep, char sep);
static void _hutils_hints_free_item (void **data);
......@@ -245,6 +248,32 @@ int hutils_wait_chld (void)
return 0;
}
int hutils_wait_chld_timed (int timeout)
{
int err = 0;
time_t start = time (NULL);
while ((time(NULL) - start)*1000 < timeout) {
if (zsys_interrupted) {
err = -1;
goto bpm_zsys_interrupted;
}
err = hutils_wait_chld ();
if (err == 0) {
DBE_DEBUG (DBG_HAL_UTILS | DBG_LVL_WARN, "[hutils:utils] "
"hutils_wait_chld_timed: finished waiting\n");
goto exit;
}
usleep (MSECS*MIN_WAIT_TIME);
}
exit:
bpm_zsys_interrupted:
return err;
}
/*******************************************************************/
/************************ Revision functions ***********************/
/*******************************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment