diff options
Diffstat (limited to 'src/main/gnunet-gtk.c')
-rw-r--r-- | src/main/gnunet-gtk.c | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/src/main/gnunet-gtk.c b/src/main/gnunet-gtk.c index 21756cd0..542edc7d 100644 --- a/src/main/gnunet-gtk.c +++ b/src/main/gnunet-gtk.c | |||
@@ -34,8 +34,14 @@ | |||
34 | struct Plug | 34 | struct Plug |
35 | { | 35 | { |
36 | 36 | ||
37 | /** | ||
38 | * Kept in a DLL. | ||
39 | */ | ||
37 | struct Plug *prev; | 40 | struct Plug *prev; |
38 | 41 | ||
42 | /** | ||
43 | * Kept in a DLL. | ||
44 | */ | ||
39 | struct Plug *next; | 45 | struct Plug *next; |
40 | 46 | ||
41 | /** | 47 | /** |
@@ -57,6 +63,17 @@ struct Plug | |||
57 | * Handle to the child process. | 63 | * Handle to the child process. |
58 | */ | 64 | */ |
59 | struct GNUNET_OS_Process *proc; | 65 | struct GNUNET_OS_Process *proc; |
66 | |||
67 | /** | ||
68 | * How long do we wait on restarts? | ||
69 | */ | ||
70 | struct GNUNET_TIME_Relative backoff; | ||
71 | |||
72 | /** | ||
73 | * Task to restart process after crash. | ||
74 | */ | ||
75 | GNUNET_SCHEDULER_TaskIdentifier restart_task; | ||
76 | |||
60 | }; | 77 | }; |
61 | 78 | ||
62 | 79 | ||
@@ -115,11 +132,19 @@ cleanup_task (void *cls, | |||
115 | 132 | ||
116 | while (NULL != (p = p_head)) | 133 | while (NULL != (p = p_head)) |
117 | { | 134 | { |
118 | (void) GNUNET_OS_process_kill (p->proc, SIGTERM); | 135 | if (NULL != p->proc) |
119 | GNUNET_break (GNUNET_OK == | 136 | { |
120 | GNUNET_OS_process_wait (p->proc)); | 137 | (void) GNUNET_OS_process_kill (p->proc, SIGTERM); |
121 | GNUNET_OS_process_destroy (p->proc); | 138 | GNUNET_break (GNUNET_OK == |
122 | p->proc = NULL; | 139 | GNUNET_OS_process_wait (p->proc)); |
140 | GNUNET_OS_process_destroy (p->proc); | ||
141 | p->proc = NULL; | ||
142 | } | ||
143 | if (GNUNET_SCHEDULER_NO_TASK != p->restart_task) | ||
144 | { | ||
145 | GNUNET_SCHEDULER_cancel (p->restart_task); | ||
146 | p->restart_task = GNUNET_SCHEDULER_NO_TASK; | ||
147 | } | ||
123 | GNUNET_CONTAINER_DLL_remove (p_head, | 148 | GNUNET_CONTAINER_DLL_remove (p_head, |
124 | p_tail, | 149 | p_tail, |
125 | p); | 150 | p); |
@@ -173,6 +198,26 @@ start_process (struct Plug *p) | |||
173 | 198 | ||
174 | 199 | ||
175 | /** | 200 | /** |
201 | * Restart crashed plugin process. | ||
202 | * | ||
203 | * @param cls the `struct Plug` of the plugin | ||
204 | * @param tc scheduler context | ||
205 | */ | ||
206 | static void | ||
207 | restart_process (void *cls, | ||
208 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
209 | { | ||
210 | struct Plug *p = cls; | ||
211 | |||
212 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
213 | _("Restarting crashed plugin `%s'\n"), | ||
214 | p->binary); | ||
215 | p->restart_task = GNUNET_SCHEDULER_NO_TASK; | ||
216 | start_process (p); | ||
217 | } | ||
218 | |||
219 | |||
220 | /** | ||
176 | * The window got detached, restart the child. | 221 | * The window got detached, restart the child. |
177 | * | 222 | * |
178 | * @param sock socket the plug got detached from | 223 | * @param sock socket the plug got detached from |
@@ -188,7 +233,10 @@ handle_remove (GtkSocket *sock, | |||
188 | (void) GNUNET_OS_process_kill (p->proc, SIGTERM); | 233 | (void) GNUNET_OS_process_kill (p->proc, SIGTERM); |
189 | GNUNET_OS_process_destroy (p->proc); | 234 | GNUNET_OS_process_destroy (p->proc); |
190 | p->proc = NULL; | 235 | p->proc = NULL; |
191 | start_process (p); | 236 | p->backoff = GNUNET_TIME_STD_BACKOFF (p->backoff); |
237 | p->restart_task = GNUNET_SCHEDULER_add_delayed (p->backoff, | ||
238 | &restart_process, | ||
239 | p); | ||
192 | return TRUE; | 240 | return TRUE; |
193 | } | 241 | } |
194 | 242 | ||