1515#include <assuan.h>
1616#include <createrepo_c/createrepo_c.h>
1717#include <errno.h>
18+ #include <signal.h>
1819#include <string.h>
1920
2021#include "createrepo-agent/command.h"
@@ -33,7 +34,7 @@ struct command_context
3334 gboolean invalidate_dependants ;
3435 gboolean missing_ok ;
3536 GError * err ;
36- gint * sentinel ;
37+ volatile sig_atomic_t * sentinel ;
3738};
3839
3940static const char * const greeting = "Greetings from creatrepo-agent " CRA_VERSION ;
@@ -309,7 +310,7 @@ cmd_shutdown(assuan_context_t ctx, char * line)
309310 return cmd_error (ctx , GPG_ERR_ASSUAN_SERVER_FAULT , NULL );
310311 }
311312
312- g_atomic_int_set ( cmd_ctx -> sentinel , 1 ) ;
313+ * cmd_ctx -> sentinel = 1 ;
313314 shutdown (cmd_ctx -> listen_fd , SHUT_RD );
314315 assuan_set_flag (ctx , ASSUAN_FORCE_CLOSE , 1 );
315316
@@ -791,7 +792,7 @@ client_worker(assuan_context_t ctx, gpointer unused)
791792
792793 cmd_ctx = (struct command_context * )assuan_get_pointer (ctx );
793794 if (cmd_ctx ) {
794- while (!done && !g_atomic_int_get ( cmd_ctx -> sentinel ) ) {
795+ while (!done && !* cmd_ctx -> sentinel ) {
795796 rc = assuan_process_next (ctx , & done );
796797 if (rc ) {
797798 break ;
@@ -803,14 +804,18 @@ client_worker(assuan_context_t ctx, gpointer unused)
803804}
804805
805806void
806- command_handler (int fd , const char * path )
807+ command_handler (int fd , const char * path , volatile sig_atomic_t * sentinel )
807808{
808809 gpg_error_t rc ;
809810 assuan_context_t ctx ;
810811 struct command_context * cmd_ctx ;
811812 cra_Coordinator * coordinator ;
812813 GThreadPool * pool ;
813- gint sentinel = 0 ;
814+ volatile sig_atomic_t local_sentinel = 0 ;
815+
816+ if (NULL == sentinel ) {
817+ sentinel = & local_sentinel ;
818+ }
814819
815820 coordinator = cra_coordinator_new (path );
816821 if (!coordinator ) {
@@ -826,7 +831,7 @@ command_handler(int fd, const char * path)
826831 return ;
827832 }
828833
829- do {
834+ while (! * sentinel ) {
830835 rc = assuan_new (& ctx );
831836 if (rc ) {
832837 fprintf (stderr , "server context creation failed: %s\n" , gpg_strerror (rc ));
@@ -841,7 +846,7 @@ command_handler(int fd, const char * path)
841846 }
842847
843848 cmd_ctx -> listen_fd = fd ;
844- cmd_ctx -> sentinel = & sentinel ;
849+ cmd_ctx -> sentinel = sentinel ;
845850 cmd_ctx -> stage = cra_stage_new (coordinator );
846851 if (!cmd_ctx -> stage ) {
847852 fprintf (stderr , "stage init failed\n" );
@@ -881,9 +886,10 @@ command_handler(int fd, const char * path)
881886
882887 rc = assuan_accept (ctx );
883888 if (rc ) {
884- if (!g_atomic_int_get (cmd_ctx -> sentinel ) ||
885- gpg_err_code (rc ) != gpg_err_code_from_errno (EINVAL ))
886- {
889+ if (gpg_err_code (rc ) == gpg_err_code_from_errno (EINTR )) {
890+ client_worker_free (ctx );
891+ continue ;
892+ } else if (!* sentinel || gpg_err_code (rc ) != gpg_err_code_from_errno (EINVAL )) {
887893 fprintf (stderr , "accept failed: %s\n" , gpg_strerror (rc ));
888894 }
889895 client_worker_free (ctx );
@@ -895,7 +901,7 @@ command_handler(int fd, const char * path)
895901 client_worker_free (ctx );
896902 break ;
897903 }
898- } while (! g_atomic_int_get ( & sentinel ));
904+ }
899905
900906 assuan_sock_close (fd );
901907 g_thread_pool_free (pool , FALSE, TRUE);
0 commit comments