Thanks to Milan Broz <mbroz@redhat.com> for this patch:
authorClemens Fruhwirth <clemens@endorphin.org>
Wed, 10 Sep 2008 10:55:28 +0000 (10:55 +0000)
committerClemens Fruhwirth <clemens@endorphin.org>
Wed, 10 Sep 2008 10:55:28 +0000 (10:55 +0000)
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

index a10d3ae..107b89a 100644 (file)
@@ -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: