Don't send SIGUSR1 to not started L1 apps. Fix for #96
* ensure that kill() is called only from one place and that pid is valid * cleanup and extend app_supervisor functions related to sending signals
This commit is contained in:
parent
46bcf78914
commit
d5c7bf6a6c
|
@ -256,6 +256,17 @@ ladish_app_supervisor_add(
|
|||
return (ladish_app_handle)app_ptr;
|
||||
}
|
||||
|
||||
static void ladish_app_send_signal(struct ladish_app * app_ptr, int sig)
|
||||
{
|
||||
ASSERT(app_ptr->state = LADISH_APP_STATE_STARTED);
|
||||
if (app_ptr->pid <= 0)
|
||||
{
|
||||
ASSERT_NO_PASS;
|
||||
return;
|
||||
}
|
||||
kill(app_ptr->pid, sig);
|
||||
}
|
||||
|
||||
void ladish_app_supervisor_clear(ladish_app_supervisor_handle supervisor_handle)
|
||||
{
|
||||
struct list_head * node_ptr;
|
||||
|
@ -268,9 +279,9 @@ void ladish_app_supervisor_clear(ladish_app_supervisor_handle supervisor_handle)
|
|||
if (app_ptr->pid != 0)
|
||||
{
|
||||
log_info("terminating '%s'...", app_ptr->name);
|
||||
ladish_app_send_signal(app_ptr, SIGTERM);
|
||||
app_ptr->zombie = true;
|
||||
app_ptr->state = LADISH_APP_STATE_STOPPING;
|
||||
kill(app_ptr->pid, SIGTERM);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -366,18 +377,6 @@ bool ladish_app_supervisor_start_app(ladish_app_supervisor_handle supervisor_han
|
|||
return true;
|
||||
}
|
||||
|
||||
void ladish_app_supervisor_stop_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle)
|
||||
{
|
||||
app_ptr->state = LADISH_APP_STATE_STOPPING;
|
||||
kill(app_ptr->pid, SIGTERM);
|
||||
}
|
||||
|
||||
void ladish_app_supervisor_kill_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle)
|
||||
{
|
||||
app_ptr->state = LADISH_APP_STATE_KILL;
|
||||
kill(app_ptr->pid, SIGKILL);
|
||||
}
|
||||
|
||||
void ladish_app_supervisor_remove_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle)
|
||||
{
|
||||
remove_app_internal(supervisor_ptr, app_ptr);
|
||||
|
@ -398,6 +397,27 @@ const char * ladish_app_get_name(ladish_app_handle app_handle)
|
|||
return app_ptr->name;
|
||||
}
|
||||
|
||||
void ladish_app_stop(ladish_app_handle app_handle)
|
||||
{
|
||||
ladish_app_send_signal(app_ptr, SIGTERM);
|
||||
app_ptr->state = LADISH_APP_STATE_STOPPING;
|
||||
}
|
||||
|
||||
void ladish_app_kill(ladish_app_handle app_handle)
|
||||
{
|
||||
ladish_app_send_signal(app_ptr, SIGKILL);
|
||||
app_ptr->state = LADISH_APP_STATE_KILL;
|
||||
}
|
||||
|
||||
void ladish_app_save_L1(ladish_app_handle app_handle)
|
||||
{
|
||||
if (app_ptr->level == 1)
|
||||
{
|
||||
log_info("sending SIGUSR1 to '%s' with pid %u", app_ptr->name, (unsigned int)app_ptr->pid);
|
||||
ladish_app_send_signal(app_ptr, SIGUSR1);
|
||||
}
|
||||
}
|
||||
|
||||
#undef app_ptr
|
||||
|
||||
void ladish_app_supervisor_autorun(ladish_app_supervisor_handle supervisor_handle)
|
||||
|
@ -436,10 +456,37 @@ void ladish_app_supervisor_stop(ladish_app_supervisor_handle supervisor_handle)
|
|||
app_ptr = list_entry(node_ptr, struct ladish_app, siblings);
|
||||
if (app_ptr->pid != 0)
|
||||
{
|
||||
log_info("terminating '%s'...", app_ptr->name);
|
||||
ladish_app_send_signal(app_ptr, SIGTERM);
|
||||
app_ptr->autorun = true;
|
||||
app_ptr->state = LADISH_APP_STATE_STOPPING;
|
||||
log_info("terminating '%s'...", app_ptr->name);
|
||||
kill(app_ptr->pid, SIGTERM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ladish_app_supervisor_save_L1(ladish_app_supervisor_handle supervisor_handle)
|
||||
{
|
||||
struct list_head * node_ptr;
|
||||
struct ladish_app * app_ptr;
|
||||
|
||||
list_for_each(node_ptr, &supervisor_ptr->applist)
|
||||
{
|
||||
app_ptr = list_entry(node_ptr, struct ladish_app, siblings);
|
||||
if (app_ptr->state != LADISH_APP_STATE_STARTED)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (app_ptr->pid == 0)
|
||||
{
|
||||
ASSERT_NO_PASS;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (app_ptr->level == 1)
|
||||
{
|
||||
log_info("sending SIGUSR1 to '%s' with pid %u", app_ptr->name, (unsigned int)app_ptr->pid);
|
||||
ladish_app_send_signal(app_ptr, SIGUSR1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,7 +134,9 @@ ladish_app_supervisor_enum(
|
|||
ladish_app_supervisor_enum_callback callback);
|
||||
|
||||
/**
|
||||
* It is not clear what this function is supposed to do
|
||||
* Remove stopped apps; For running apps, initiate stop and
|
||||
* mark them as zombies thus causing app autoremove
|
||||
* once it quits.
|
||||
*
|
||||
* @param[in] supervisor_handle supervisor object handle
|
||||
*/
|
||||
|
@ -142,6 +144,15 @@ void
|
|||
ladish_app_supervisor_clear(
|
||||
ladish_app_supervisor_handle supervisor_handle);
|
||||
|
||||
/**
|
||||
* Send SIGUSR1 to all currently running L1 apps.
|
||||
*
|
||||
* @param[in] supervisor_handle supervisor object handle
|
||||
*/
|
||||
void
|
||||
ladish_app_supervisor_save_L1(
|
||||
ladish_app_supervisor_handle supervisor_handle);
|
||||
|
||||
/**
|
||||
* Add app. Apps are added in stopped state
|
||||
*
|
||||
|
@ -257,22 +268,6 @@ const char * ladish_app_supervisor_get_opath(ladish_app_supervisor_handle superv
|
|||
*/
|
||||
bool ladish_app_supervisor_start_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle);
|
||||
|
||||
/**
|
||||
* Stop an app. The app must be in started state.
|
||||
*
|
||||
* @param[in] supervisor_handle supervisor object handle
|
||||
* @param[in] app_handle Handle of app to stop
|
||||
*/
|
||||
void ladish_app_supervisor_stop_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle);
|
||||
|
||||
/**
|
||||
* Force kill an app. The app must be in started state.
|
||||
*
|
||||
* @param[in] supervisor_handle supervisor object handle
|
||||
* @param[in] app_handle Handle of app to kill
|
||||
*/
|
||||
void ladish_app_supervisor_kill_app(ladish_app_supervisor_handle supervisor_handle, ladish_app_handle app_handle);
|
||||
|
||||
/**
|
||||
* Remove an app. The app must be in stopped state.
|
||||
*
|
||||
|
@ -322,6 +317,27 @@ bool ladish_app_is_running(ladish_app_handle app_handle);
|
|||
*/
|
||||
const char * ladish_app_get_name(ladish_app_handle app_handle);
|
||||
|
||||
/**
|
||||
* Stop an app. The app must be in started state.
|
||||
*
|
||||
* @param[in] app_handle Handle of app to stop
|
||||
*/
|
||||
void ladish_app_stop(ladish_app_handle app_handle);
|
||||
|
||||
/**
|
||||
* Force kill an app. The app must be in started state.
|
||||
*
|
||||
* @param[in] app_handle Handle of app to kill
|
||||
*/
|
||||
void ladish_app_kill(ladish_app_handle app_handle);
|
||||
|
||||
/**
|
||||
* Send SIGUSR1 signal to app. The app must be in started state.
|
||||
*
|
||||
* @param[in] app_handle Handle of app to send signal to
|
||||
*/
|
||||
void ladish_app_save_L1(ladish_app_handle app_handle);
|
||||
|
||||
/**
|
||||
* D-Bus interface descriptor for the app supervisor interface. The call context must be a ::ladish_app_supervisor_handle
|
||||
*/
|
||||
|
|
|
@ -39,7 +39,7 @@ struct ladish_command_change_app_state
|
|||
unsigned int target_state;
|
||||
const char * target_state_description;
|
||||
bool (* run_target)(struct ladish_command_change_app_state *, ladish_app_supervisor_handle, ladish_app_handle);
|
||||
void (* initiate_stop)(ladish_app_supervisor_handle supervisor, ladish_app_handle app);
|
||||
void (* initiate_stop)(ladish_app_handle app);
|
||||
};
|
||||
|
||||
static bool run_target_start(struct ladish_command_change_app_state * cmd_ptr, ladish_app_supervisor_handle supervisor, ladish_app_handle app)
|
||||
|
@ -83,7 +83,7 @@ static bool run_target_stop(struct ladish_command_change_app_state * cmd_ptr, la
|
|||
{
|
||||
if (cmd_ptr->command.state == LADISH_COMMAND_STATE_PENDING)
|
||||
{
|
||||
cmd_ptr->initiate_stop(supervisor, app);
|
||||
cmd_ptr->initiate_stop(app);
|
||||
cmd_ptr->command.state = LADISH_COMMAND_STATE_WAITING;
|
||||
return true;
|
||||
}
|
||||
|
@ -182,12 +182,12 @@ bool ladish_command_change_app_state(void * call_ptr, struct ladish_cqueue * que
|
|||
case LADISH_APP_STATE_STOPPED:
|
||||
cmd_ptr->target_state_description = "stop";
|
||||
cmd_ptr->run_target = run_target_stop;
|
||||
cmd_ptr->initiate_stop = ladish_app_supervisor_stop_app;
|
||||
cmd_ptr->initiate_stop = ladish_app_stop;
|
||||
break;
|
||||
case LADISH_APP_STATE_KILL:
|
||||
cmd_ptr->target_state_description = "kill";
|
||||
cmd_ptr->run_target = run_target_stop;
|
||||
cmd_ptr->initiate_stop = ladish_app_supervisor_kill_app;
|
||||
cmd_ptr->initiate_stop = ladish_app_kill;
|
||||
break;
|
||||
default:
|
||||
ASSERT_NO_PASS;
|
||||
|
|
|
@ -665,22 +665,6 @@ struct ladish_command_save_studio
|
|||
char * studio_name;
|
||||
};
|
||||
|
||||
static bool save_app(void * context, const char * name, bool running, const char * command, bool terminal, uint8_t level, pid_t pid)
|
||||
{
|
||||
if (level == 1)
|
||||
{
|
||||
log_info("sending SIGUSR1 to '%s' with pid %u", name, (unsigned int)pid);
|
||||
kill(pid, SIGUSR1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void save_apps(void)
|
||||
{
|
||||
ladish_app_supervisor_enum(g_studio.app_supervisor, NULL, save_app);
|
||||
}
|
||||
|
||||
#define cmd_ptr ((struct ladish_command_save_studio *)command_context)
|
||||
|
||||
static bool run(void * command_context)
|
||||
|
@ -705,7 +689,7 @@ static bool run(void * command_context)
|
|||
|
||||
ret = false;
|
||||
|
||||
save_apps();
|
||||
ladish_app_supervisor_save_L1(g_studio.app_supervisor);
|
||||
|
||||
if (!ladish_studio_is_started())
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue