@@ -572,6 +572,38 @@ int lxc_set_state(const char *name, struct lxc_handler *handler,
572572 return 0 ;
573573}
574574
575+ void * lxc_handler_mainloop_thread_fn (void * arg )
576+ {
577+ struct lxc_async_descr * descr = arg ;
578+
579+ return INT_TO_PTR (lxc_mainloop (descr , -1 ));
580+ }
581+
582+ int lxc_handler_mainloop (struct lxc_async_descr * descr , struct lxc_handler * handler )
583+ {
584+ void * exit_code ;
585+ int ret ;
586+ pthread_t thread ;
587+
588+ ret = pthread_create (& thread , NULL , lxc_handler_mainloop_thread_fn , (void * )descr );
589+ if (ret ) {
590+ return log_error_errno (-1 , ret ,
591+ "Failed to spawn a thread for lxc handler mainloop" );
592+ }
593+
594+ ret = pthread_join (thread , & exit_code );
595+ if (ret ) {
596+ return log_error_errno (-1 , ret ,
597+ "Failed to wait for lxc handler mainloop thread" );
598+ }
599+
600+ if (exit_code == PTHREAD_CANCELED ) {
601+ return log_error (-1 , "Mainloop thread was canceled" );
602+ }
603+
604+ return PTR_TO_INT (exit_code );
605+ }
606+
575607int lxc_poll (const char * name , struct lxc_handler * handler )
576608{
577609 int ret ;
@@ -626,7 +658,7 @@ int lxc_poll(const char *name, struct lxc_handler *handler)
626658
627659 TRACE ("Mainloop is ready" );
628660
629- ret = lxc_mainloop (& descr , -1 );
661+ ret = lxc_handler_mainloop (& descr , handler );
630662 if (descr .type == LXC_MAINLOOP_EPOLL )
631663 close_prot_errno_disarm (descr .epfd );
632664 if (ret < 0 || !handler -> init_died )
0 commit comments