Skip to content

Commit a64ea90

Browse files
jfsmigfvennetier
authored andcommitted
Add a configurable KILL delay, at child registration
1 parent f1c6f21 commit a64ea90

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

lib/children.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3535
#include "./gridinit-utils.h"
3636
#include "./gridinit-internals.h"
3737

38+
time_t supervisor_default_delay_KILL = SUPERVISOR_DEFAULT_TIMEOUT_KILL;
39+
3840
static time_t _monotonic_seconds(void) {
3941
return g_get_monotonic_time() / G_TIME_SPAN_SECOND;
4042
}
@@ -94,6 +96,7 @@ struct my_rlimits_s {
9496

9597
struct child_s {
9698
struct child_s *next;
99+
time_t delay_before_KILL;
97100
gchar *command;
98101
pid_t pid;
99102
uid_t uid;
@@ -103,9 +106,6 @@ struct child_s {
103106
guint32 user_flags;
104107
GSList *env;
105108

106-
gchar key[SUPERVISOR_LIMIT_CHILDKEYSIZE];
107-
gchar group[2048];
108-
109109
/* Useful stats */
110110
guint counter_started;
111111
guint counter_died;
@@ -122,17 +122,13 @@ struct child_s {
122122

123123
/* Child's startup properties */
124124
struct my_rlimits_s rlimits;
125-
};
126125

127-
static struct child_s SRV_BEACON = {
128-
NULL, NULL, 0, 0, 0,
129-
NULL, 0, 0, NULL,
130-
"", "", /* keys */
131-
0, 0, 0, 0, 0, /* birth/death stats */
132-
{0,0,0,0,0} /* deaths */,
133-
{0,0,0} /* limits */
126+
gchar key[SUPERVISOR_LIMIT_CHILDKEYSIZE];
127+
gchar group[2048];
134128
};
135129

130+
static struct child_s SRV_BEACON = {};
131+
136132
static supervisor_postfork_f *supervisor_cb_postfork = NULL;
137133
static void *supervisor_cb_postfork_udata = NULL;
138134

@@ -465,11 +461,12 @@ _child_stop(struct child_s *sd)
465461
time_t now = _monotonic_seconds();
466462
if (sd->first_kill_attempt == 0)
467463
sd->first_kill_attempt = now;
468-
if (sd->first_kill_attempt > 0 && (now - sd->first_kill_attempt > SUPERVISOR_DEFAULT_TIMEOUT_KILL)) {
464+
if (sd->delay_before_KILL > 0
465+
&& sd->first_kill_attempt > 0
466+
&& (now - sd->first_kill_attempt) > sd->delay_before_KILL) {
469467
DEBUG("Service [%s] did not exit after 60s, sending SIGKILL", sd->key);
470468
kill(sd->pid, SIGKILL);
471-
}
472-
else {
469+
} else {
473470
DEBUG("Sending SIGTERM to service [%s] pid %i", sd->key, sd->pid);
474471
kill(sd->pid, SIGTERM);
475472
}
@@ -770,13 +767,11 @@ supervisor_children_fini(void)
770767

771768

772769
gboolean
773-
supervisor_children_register(const gchar *key, const gchar *cmd, GError **error)
770+
supervisor_children_register(const gchar *key, const gchar *cmd)
774771
{
775772
struct child_s *sd = NULL;
776773

777-
(void) error;
778-
779-
/*check if the service is present*/
774+
/* check if the service is present */
780775
FOREACH_CHILD(sd) {
781776
if (0 == g_ascii_strcasecmp(sd->key, key)) {
782777

@@ -790,14 +785,15 @@ supervisor_children_register(const gchar *key, const gchar *cmd, GError **error)
790785
}
791786
}
792787

793-
/*Child not found, it will be created*/
788+
/* Child not found, it will be created */
794789
sd = g_try_malloc0(sizeof(struct child_s));
795790
if (NULL == sd) {
796791
errno = ENOMEM;
797792
return FALSE;
798793
}
799794

800795
g_strlcpy(sd->key, key, sizeof(sd->key)-1);
796+
sd->delay_before_KILL = supervisor_default_delay_KILL;
801797
sd->flags = MASK_STARTED|MASK_RESPAWN|MASK_DELAYED;
802798
sd->working_directory = g_get_current_dir();
803799
sd->command = g_strdup(cmd);
@@ -813,7 +809,7 @@ supervisor_children_register(const gchar *key, const gchar *cmd, GError **error)
813809
(void) supervisor_limit_get(SUPERV_LIMIT_MAX_FILES, &(sd->rlimits.nb_files));
814810
(void) supervisor_limit_get(SUPERV_LIMIT_CORE_SIZE, &(sd->rlimits.core_size));
815811

816-
/*ring insertion*/
812+
/* ring insertion */
817813
sd->next = SRV_BEACON.next;
818814
SRV_BEACON.next = sd;
819815

lib/gridinit-utils.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3232
# include <sys/types.h>
3333
# include <unistd.h>
3434

35+
extern time_t supervisor_default_delay_KILL;
36+
3537
/* Children monitoring ----------------------------------------------------- */
3638

3739
enum supervisor_limit_e {
@@ -93,8 +95,7 @@ guint supervisor_children_killall(int sig);
9395

9496
guint supervisor_children_catharsis(void *udata, supervisor_cb_f cb);
9597

96-
gboolean supervisor_children_register(const gchar *key, const gchar *cmd,
97-
GError **error);
98+
gboolean supervisor_children_register(const gchar *key, const gchar *cmd);
9899

99100
/**
100101
* Marks the services still obsolete as DISABLED and to be stopped.

main/gridinit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
5454
#include "./gridinit_alerts.h"
5555
#include "../lib/gridinit-internals.h"
5656

57-
#define USERFLAG_ONDIE_EXIT 0x00000001
58-
#define USERFLAG_PROCESS_DIED 0x00000002
59-
#define USERFLAG_PROCESS_RESTARTED 0x00000004
57+
#define USERFLAG_ONDIE_EXIT 0x00000001
58+
#define USERFLAG_PROCESS_DIED 0x00000002
59+
#define USERFLAG_PROCESS_RESTARTED 0x00000004
6060

6161
#define BOOL(i) ((i)!=0)
6262

@@ -1227,7 +1227,7 @@ _cfg_section_service(GKeyFile *kf, const gchar *section, GError **err)
12271227
* being reloaded. */
12281228
already_exists = _service_exists(str_key);
12291229

1230-
if (!supervisor_children_register(str_key, str_command, err))
1230+
if (!supervisor_children_register(str_key, str_command))
12311231
goto label_exit;
12321232

12331233
/* Enables or not. This is a lock controlled by the configuration

0 commit comments

Comments
 (0)