@@ -180,6 +180,43 @@ static void hup_handler(verto_ctx *vctx, verto_ev *ev UNUSED)
180
180
return ;
181
181
}
182
182
183
+ void break_loop (verto_ctx * vctx UNUSED , verto_ev * ev )
184
+ {
185
+ if (ev == gpctx -> term_ev ) {
186
+ gpctx -> term_ev = NULL ;
187
+ }
188
+ GPDEBUG ("Exiting!\n" );
189
+ gpctx -> terminate = true;
190
+ }
191
+
192
+ static void idle_handler (verto_ctx * vctx )
193
+ {
194
+ /* we've been called, this means some event just fired,
195
+ * restart the timeout handler */
196
+
197
+ if (gpctx -> term_timeout == 0 ) {
198
+ /* self termination is disabled */
199
+ return ;
200
+ }
201
+
202
+ verto_del (gpctx -> term_ev );
203
+
204
+ /* Add self-termination timeout */
205
+ gpctx -> term_ev = verto_add_timeout (vctx , VERTO_EV_FLAG_NONE ,
206
+ break_loop , gpctx -> term_timeout );
207
+ if (!gpctx -> term_ev ) {
208
+ GPDEBUG ("Failed to register timeout event!\n" );
209
+ }
210
+ }
211
+
212
+ static void do_loop (verto_ctx * vctx )
213
+ {
214
+ while (gpctx -> terminate == false) {
215
+ verto_run_once (vctx );
216
+ idle_handler (vctx );
217
+ }
218
+ }
219
+
183
220
static void init_event (verto_ctx * vctx UNUSED , verto_ev * ev UNUSED )
184
221
{
185
222
GPDEBUG ("Initialization complete.\n" );
@@ -195,6 +232,7 @@ int main(int argc, const char *argv[])
195
232
int opt_debug_level = 0 ;
196
233
int opt_syslog_status = 0 ;
197
234
int opt_userproxy = 0 ;
235
+ int opt_idle_timeout = 1000 ;
198
236
verto_ctx * vctx ;
199
237
verto_ev * ev ;
200
238
int wait_fd ;
@@ -226,6 +264,8 @@ int main(int argc, const char *argv[])
226
264
_ ("Enable GSSAPI status logging to syslog" ), NULL }, \
227
265
{"version" , '\0' , POPT_ARG_NONE , & opt_version , 0 , \
228
266
_ ("Print version number and exit" ), NULL }, \
267
+ {"idle-timeout" , '\0' , POPT_ARG_INT , & opt_idle_timeout , 0 , \
268
+ _ ("Set idle timeout for user mode (default: 1000s)" ), NULL },
229
269
{"extract-ccache" , '\0' , POPT_ARG_STRING |POPT_ARGFLAG_DOC_HIDDEN , \
230
270
& opt_extract_ccache , 0 , \
231
271
_ ("Extract a gssproxy encrypted ccache" ), NULL },
@@ -299,6 +339,8 @@ int main(int argc, const char *argv[])
299
339
write_pid ();
300
340
}
301
341
342
+ gpctx -> term_timeout = opt_idle_timeout * 1000 ;
343
+
302
344
vctx = init_event_loop ();
303
345
if (!vctx ) {
304
346
fprintf (stderr , "Failed to initialize event loop. "
@@ -308,8 +350,8 @@ int main(int argc, const char *argv[])
308
350
}
309
351
gpctx -> vctx = vctx ;
310
352
311
- /* Add SIGHUP here so that gpctx is in scope for the handler */
312
353
if (!opt_userproxy ) {
354
+ /* Add SIGHUP here so that gpctx is in scope for the handler */
313
355
ev = verto_add_signal (vctx , VERTO_EV_FLAG_PERSIST ,
314
356
hup_handler , SIGHUP );
315
357
if (!ev ) {
@@ -366,7 +408,7 @@ int main(int argc, const char *argv[])
366
408
goto cleanup ;
367
409
}
368
410
369
- verto_run (vctx );
411
+ do_loop (vctx );
370
412
verto_free (vctx );
371
413
372
414
gp_workers_free (gpctx -> workers );
0 commit comments