From f8b8b6aac2ca1cb34d7a346aee1d874e7650557b Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 8 Mar 2018 16:51:51 +0900 Subject: scd: Fix status check when using PC/SC. * scd/apdu.c (struct reader_table_s): Add field of current_state. (new_reader_slot): Initialize current_state. (pcsc_get_status): Keep the status in READER_TABLE array. Return SW_HOST_NO_READER when PCSC_STATE_CHANGED. * scd/scdaemon.c (handle_connections): Silence a warning. -- To detect some change of card status, including suspend/resume possibly, SCardGetStatusChange should be used keeping the dwCurrentState field. This change could improve situation for suspend/resume with Yubikey on Windows. Even not, this is doing the Right Thing. Signed-off-by: NIIBE Yutaka --- scd/scdaemon.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'scd/scdaemon.c') diff --git a/scd/scdaemon.c b/scd/scdaemon.c index cebeea9d3..91b559925 100644 --- a/scd/scdaemon.c +++ b/scd/scdaemon.c @@ -1348,6 +1348,8 @@ handle_connections (int listen_fd) FD_SET (pipe_fd[0], &read_fdset); if (max_fd < pipe_fd[0]) max_fd = pipe_fd[0]; +#else + (void)max_fd; #endif #ifndef HAVE_W32_SYSTEM -- cgit From 71e5282c25ba812c7091e587edd721839bc4c2ac Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Tue, 13 Mar 2018 12:05:57 +0900 Subject: scd: Fix for GNU/Linux suspend/resume. * configure.ac (require_pipe_to_unblock_pselect): Default is "yes". * scd/scdaemon.c (scd_kick_the_loop): Minor clean up. -- Normally SIGCONT or SIGUSR2 works for unblocking pselect. But on my machine with GNU/Linux, when a machine is suspend/resume-ed, pselect keeps blocked, while signal itself is delivered. It's better to use pipe. Signed-off-by: NIIBE Yutaka --- configure.ac | 3 ++- scd/scdaemon.c | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'scd/scdaemon.c') diff --git a/configure.ac b/configure.ac index 8252db9a1..086af12ec 100644 --- a/configure.ac +++ b/configure.ac @@ -639,7 +639,7 @@ have_android_system=no use_simple_gettext=no use_ldapwrapper=yes mmap_needed=yes -require_pipe_to_unblock_pselect=no +require_pipe_to_unblock_pselect=yes case "${host}" in *-mingw32*) # special stuff for Windoze NT @@ -654,6 +654,7 @@ case "${host}" in have_w32_system=yes require_iconv=no use_ldapwrapper=no # Fixme: Do this only for CE. + require_pipe_to_unblock_pselect=no case "${host}" in *-mingw32ce*) have_w32ce_system=yes diff --git a/scd/scdaemon.c b/scd/scdaemon.c index 91b559925..e63aca72f 100644 --- a/scd/scdaemon.c +++ b/scd/scdaemon.c @@ -1206,18 +1206,16 @@ start_connection_thread (void *arg) void scd_kick_the_loop (void) { - int ret; - /* Kick the select loop. */ #ifdef HAVE_W32_SYSTEM - ret = SetEvent (the_event); + int ret = SetEvent (the_event); if (ret == 0) log_error ("SetEvent for scd_kick_the_loop failed: %s\n", w32_strerror (-1)); #elif defined(HAVE_PSELECT_NO_EINTR) write (notify_fd, "", 1); #else - ret = kill (main_thread_pid, SIGCONT); + int ret = kill (main_thread_pid, SIGCONT); if (ret < 0) log_error ("SetEvent for scd_kick_the_loop failed: %s\n", gpg_strerror (gpg_error_from_syserror ())); -- cgit From 11bbd99477ef5ba5b7db0c17607b10af03c68afb Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Mon, 19 Mar 2018 16:36:30 +0900 Subject: scd: signal mask should be set just after npth_init. * scd/scdaemon.c (setup_signal_mask): New. (main): Call setup_signal_mask. (handle_connections): Remove signal mask setup. -- For new thread, signal mask is inherited by thread creation. Thus, it is best to setup signal mask just after npth_init. Signed-off-by: NIIBE Yutaka --- scd/scdaemon.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'scd/scdaemon.c') diff --git a/scd/scdaemon.c b/scd/scdaemon.c index e63aca72f..8f8a02619 100644 --- a/scd/scdaemon.c +++ b/scd/scdaemon.c @@ -393,7 +393,21 @@ cleanup (void) } } - +static void +setup_signal_mask (void) +{ +#ifndef HAVE_W32_SYSTEM + npth_sigev_init (); + npth_sigev_add (SIGHUP); + npth_sigev_add (SIGUSR1); + npth_sigev_add (SIGUSR2); + npth_sigev_add (SIGINT); + npth_sigev_add (SIGCONT); + npth_sigev_add (SIGTERM); + npth_sigev_fini (); + main_thread_pid = getpid (); +#endif +} int main (int argc, char **argv ) @@ -744,6 +758,7 @@ main (int argc, char **argv ) #endif npth_init (); + setup_signal_mask (); gpgrt_set_syscall_clamp (npth_unprotect, npth_protect); /* If --debug-allow-core-dump has been given we also need to @@ -884,6 +899,7 @@ main (int argc, char **argv ) /* This is the child. */ npth_init (); + setup_signal_mask (); gpgrt_set_syscall_clamp (npth_unprotect, npth_protect); /* Detach from tty and put process into a new session. */ @@ -1290,16 +1306,6 @@ handle_connections (int listen_fd) events[0] = the_event = h2; } } -#else - npth_sigev_init (); - npth_sigev_add (SIGHUP); - npth_sigev_add (SIGUSR1); - npth_sigev_add (SIGUSR2); - npth_sigev_add (SIGINT); - npth_sigev_add (SIGCONT); - npth_sigev_add (SIGTERM); - npth_sigev_fini (); - main_thread_pid = getpid (); #endif FD_ZERO (&fdset); -- cgit