From 80039744844d508be78c1db6531d2a1718b5730d Mon Sep 17 00:00:00 2001 From: Clemens Fruhwirth Date: Wed, 10 Sep 2008 10:55:28 +0000 Subject: [PATCH] Thanks to Milan Broz for this patch: Fix signal handler to proper close device, otherwise if the descriptor is 0, it keeps device open and temporary-cryptsetup-$PID mapping is not removed (leaving device open and unusable). git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@30 36d66b0a-2a48-0410-832c-cd162a569da5 --- luks/keyencryption.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/luks/keyencryption.c b/luks/keyencryption.c index a10d3ae8..107b89a8 100644 --- a/luks/keyencryption.c +++ b/luks/keyencryption.c @@ -97,12 +97,13 @@ static int clear_mapping(const char *name, struct setup_backend *backend) /* I miss closures in C! */ static struct setup_backend *cleaner_backend=NULL; static const char *cleaner_name=NULL; -static int devfd=0; +static int devfd=-1; static void sigint_handler(int sig) { - if(devfd) + if(devfd >= 0) close(devfd); + devfd = -1; if(cleaner_backend && cleaner_name) clear_mapping(cleaner_name, cleaner_backend); signal(SIGINT, SIG_DFL); @@ -160,7 +161,7 @@ static int LUKS_endec_template(char *src, size_t srcLength, r = 0; out3: close(devfd); - devfd = 0; + devfd = -1; out2: clear_mapping(name,backend); out1: