Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[usb-moded] Improve exit handling
Seems dbus_shutdown does not behave in the slightest as it is documented,
as it causes an exit(1). Also handle SIGTERM as that gets sent first by
init, before SIGKILL.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Mar 11, 2014
1 parent fd75451 commit 29bdeee
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/usb_moded.c
Expand Up @@ -587,7 +587,8 @@ static void handle_exit(void)
usb_moded_appsync_cleanup();
#endif /* APP_SYNC_DBUS */
#endif /* APP_SYNC */
dbus_shutdown();
/* dbus_shutdown(); This causes exit(1) and don't seem
to behave as documented */

/* If the mainloop is initialised, unreference it */
if (mainloop != NULL)
Expand All @@ -598,14 +599,16 @@ static void handle_exit(void)
free((void *)current_mode.mode);
free((void *)current_mode.module);

log_debug("All resources freed. Exiting!\n");

exit(0);
}

static void sigint_handler(int signum)
{
struct mode_list_elem *data;

if(signum == SIGINT)
if(signum == SIGINT || signum == SIGTERM)
handle_exit();
if(signum == SIGHUP)
{
Expand Down Expand Up @@ -747,6 +750,7 @@ int main(int argc, char* argv[])

/* signal handling */
signal(SIGINT, sigint_handler);
signal(SIGTERM, sigint_handler);
signal(SIGHUP, sigint_handler);

#ifdef SYSTEMD
Expand Down

0 comments on commit 29bdeee

Please sign in to comment.