Navigation Menu

Skip to content

Commit

Permalink
Add mce auto-exit feature to help debugging mce startup
Browse files Browse the repository at this point in the history
Spotting changes in verbose startup logging is difficult when mce must
be stopped manually.

Add auto-exit feature that by default makes mce exit 5 seconds after
mainloop reaches idle.
  • Loading branch information
spiiroin committed Jan 22, 2015
1 parent 104b946 commit 6d8b6f0
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions mce.c
Expand Up @@ -646,6 +646,7 @@ static struct
bool systembus;
bool show_module_info;
bool systemd_notify;
int auto_exit;
} mce_args =
{
.daemonflag = false,
Expand All @@ -654,6 +655,7 @@ static struct
.systembus = true,
.show_module_info = false,
.systemd_notify = false,
.auto_exit = -1,
};

static bool mce_do_help(const char *arg);
Expand All @@ -680,6 +682,11 @@ static bool mce_do_force_syslog(const char *arg)
return true;
}

static bool mce_do_auto_exit(const char *arg)
{
mce_args.auto_exit = arg ? strtol(arg, 0, 0) : 5;
return true;
}
static bool mce_do_log_function(const char *arg)
{
mce_log_add_pattern(arg);
Expand Down Expand Up @@ -831,6 +838,16 @@ static const mce_opt_t options[] =
.usage =
"Add function logging override"
},
{
.name = "auto-exit",
.values = "seconds",
.with_arg = mce_do_auto_exit,
.without_arg = mce_do_auto_exit,
.usage =
"Exit after mainloop gets idle\n"
"\n"
"This is usefult for mce startup debugging only.\n"
},
// sentinel
{
.name = 0
Expand Down Expand Up @@ -875,6 +892,22 @@ static bool mce_do_help(const char *arg)
exit(EXIT_SUCCESS);
}

static gboolean mce_auto_exit_cb(gpointer aptr)
{
(void)aptr;

if( mce_args.auto_exit <= 0 ) {
mce_log(LL_WARN, "exit");
mce_quit_mainloop();
}
else {
mce_log(LL_WARN, "idle");
g_timeout_add_seconds(mce_args.auto_exit, mce_auto_exit_cb, 0);
mce_args.auto_exit = 0;
}
return FALSE;
}

/* ========================================================================= *
* MAIN ENTRY POINT
* ========================================================================= */
Expand Down Expand Up @@ -1024,6 +1057,11 @@ int main(int argc, char **argv)
mce_log(LL_NOTICE, "notifying systemd");
sd_notify(0, "READY=1");
}
/* Debug feature: exit after startup is finished */
if( mce_args.auto_exit >= 0 ) {
mce_log(LL_WARN, "auto-exit scheduled");
g_idle_add(mce_auto_exit_cb, 0);
}

/* Run the main loop */
g_main_loop_run(mainloop);
Expand Down

0 comments on commit 6d8b6f0

Please sign in to comment.