aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Kibbey <[email protected]>2012-04-10 00:52:22 +0000
committerWerner Koch <[email protected]>2012-04-10 07:02:18 +0000
commitbee0ac28c9c8027540ae56900b9f85e0bd555f1d (patch)
treef6856be7b209567f623c44b866c0f2ab951c28bc
parentDo not mix test result with progress lines. (diff)
downloadgnupg-bee0ac28c9c8027540ae56900b9f85e0bd555f1d.tar.gz
gnupg-bee0ac28c9c8027540ae56900b9f85e0bd555f1d.zip
Fix killing PID -1.
When the KILLSCD command had been sent a race condition would occur causing PID -1 getting killed, which on Linux seems to terminate all applications for the current user.
-rw-r--r--scd/apdu.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/scd/apdu.c b/scd/apdu.c
index 064f0d636..8467b034c 100644
--- a/scd/apdu.c
+++ b/scd/apdu.c
@@ -1016,7 +1016,8 @@ pcsc_get_status_wrapped (int slot, unsigned int *status)
close (slotp->pcsc.rsp_fd);
slotp->pcsc.req_fd = -1;
slotp->pcsc.rsp_fd = -1;
- kill (slotp->pcsc.pid, SIGTERM);
+ if (slotp->pcsc.pid != -1)
+ kill (slotp->pcsc.pid, SIGTERM);
slotp->pcsc.pid = (pid_t)(-1);
slotp->used = 0;
return sw;
@@ -1180,7 +1181,8 @@ pcsc_send_apdu_wrapped (int slot, unsigned char *apdu, size_t apdulen,
close (slotp->pcsc.rsp_fd);
slotp->pcsc.req_fd = -1;
slotp->pcsc.rsp_fd = -1;
- kill (slotp->pcsc.pid, SIGTERM);
+ if (slotp->pcsc.pid != -1)
+ kill (slotp->pcsc.pid, SIGTERM);
slotp->pcsc.pid = (pid_t)(-1);
slotp->used = 0;
return sw;
@@ -1321,7 +1323,8 @@ control_pcsc_wrapped (int slot, unsigned long ioctl_code,
close (slotp->pcsc.rsp_fd);
slotp->pcsc.req_fd = -1;
slotp->pcsc.rsp_fd = -1;
- kill (slotp->pcsc.pid, SIGTERM);
+ if (slotp->pcsc.pid != -1)
+ kill (slotp->pcsc.pid, SIGTERM);
slotp->pcsc.pid = (pid_t)(-1);
slotp->used = 0;
return pcsc_error_to_sw (err);
@@ -1422,7 +1425,8 @@ close_pcsc_reader_wrapped (int slot)
close (slotp->pcsc.rsp_fd);
slotp->pcsc.req_fd = -1;
slotp->pcsc.rsp_fd = -1;
- kill (slotp->pcsc.pid, SIGTERM);
+ if (slotp->pcsc.pid != -1)
+ kill (slotp->pcsc.pid, SIGTERM);
slotp->pcsc.pid = (pid_t)(-1);
slotp->used = 0;
return 0;
@@ -1640,7 +1644,8 @@ reset_pcsc_reader_wrapped (int slot)
close (slotp->pcsc.rsp_fd);
slotp->pcsc.req_fd = -1;
slotp->pcsc.rsp_fd = -1;
- kill (slotp->pcsc.pid, SIGTERM);
+ if (slotp->pcsc.pid != -1)
+ kill (slotp->pcsc.pid, SIGTERM);
slotp->pcsc.pid = (pid_t)(-1);
slotp->used = 0;
return sw;
@@ -1965,7 +1970,8 @@ open_pcsc_reader_wrapped (const char *portstr)
close (slotp->pcsc.rsp_fd);
slotp->pcsc.req_fd = -1;
slotp->pcsc.rsp_fd = -1;
- kill (slotp->pcsc.pid, SIGTERM);
+ if (slotp->pcsc.pid != -1)
+ kill (slotp->pcsc.pid, SIGTERM);
slotp->pcsc.pid = (pid_t)(-1);
slotp->used = 0;
/* There is no way to return SW. */