[git] GnuPG - branch, master, updated. gnupg-2.1.10-114-g9b6c914

by Werner Koch cvs at cvs.gnupg.org
Wed Jan 13 14:53:54 CET 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  9b6c91469a804c60289a2ed21334dfd856c294bb (commit)
       via  8f1368d5e3f7654ad9cb100053535f728dff2344 (commit)
       via  4aceebf36f103eb380e21d12a1f08b7d6ea7cc8e (commit)
      from  160862978628b07ed5150ec2c8abad6af1656bc3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 9b6c91469a804c60289a2ed21334dfd856c294bb
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Jan 13 14:48:02 2016 +0100

    gpg: Improve error code from lock_all.
    
    * g10/keydb.c (lock_all): Do not clobber RC during failur cleanup.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/g10/keydb.c b/g10/keydb.c
index 3ee9dfd..cf7b990 100644
--- a/g10/keydb.c
+++ b/g10/keydb.c
@@ -1003,7 +1003,7 @@ lock_all (KEYDB_HANDLE hd)
               keyring_lock (hd->active[i].u.kr, 0);
               break;
             case KEYDB_RESOURCE_TYPE_KEYBOX:
-              rc = keybox_lock (hd->active[i].u.kb, 0);
+              keybox_lock (hd->active[i].u.kb, 0);
               break;
             }
         }

commit 8f1368d5e3f7654ad9cb100053535f728dff2344
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Jan 13 14:47:06 2016 +0100

    kbx: Improve and fix keybox_lock.
    
    * kbx/keybox-init.c (keybox_lock): Make sure ERR is initialized.  Get
    error codes from dotlock functions.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/kbx/keybox-init.c b/kbx/keybox-init.c
index cfee7b8..01d29f0 100644
--- a/kbx/keybox-init.c
+++ b/kbx/keybox-init.c
@@ -266,10 +266,10 @@ _keybox_close_file (KEYBOX_HANDLE hd)
 gpg_error_t
 keybox_lock (KEYBOX_HANDLE hd, int yes)
 {
-  gpg_error_t err;
+  gpg_error_t err = 0;
   KB_NAME kb = hd->kb;
 
-  if (!keybox_is_writable ((void*)kb))
+  if (!keybox_is_writable (kb))
     return 0;
 
   /* Make sure the lock handle has been created.  */
@@ -278,9 +278,9 @@ keybox_lock (KEYBOX_HANDLE hd, int yes)
       kb->lockhd = dotlock_create (kb->fname, 0);
       if (!kb->lockhd)
         {
-          /* Unfortuntaley dotlock_create does not properly set ERRNO.  */
+          err = gpg_error_from_syserror ();
           log_info ("can't allocate lock for '%s'\n", kb->fname );
-          return gpg_error (GPG_ERR_GENERAL);
+          return err;
         }
     }
 
@@ -288,28 +288,26 @@ keybox_lock (KEYBOX_HANDLE hd, int yes)
     {
       if (kb->is_locked)
         ;
-      else if (!dotlock_take (kb->lockhd, -1))
-        kb->is_locked = 1;
-      else
+      else if (dotlock_take (kb->lockhd, -1))
         {
-          /* Unfortuntaley dotlock_take does not properly set ERRNO.  */
+          err = gpg_error_from_syserror ();
           log_info ("can't lock '%s'\n", kb->fname );
-          err = gpg_error (GPG_ERR_GENERAL);
         }
+      else
+        kb->is_locked = 1;
     }
   else /* Release the lock.  */
     {
       if (!kb->is_locked)
         ;
-      else if (!dotlock_release (kb->lockhd))
-        kb->is_locked = 0;
-      else
+      else if (dotlock_release (kb->lockhd))
         {
-          /* Unfortuntaley dotlock_release does not properly set ERRNO.  */
+          err = gpg_error_from_syserror ();
           log_info ("can't unlock '%s'\n", kb->fname );
-          err = gpg_error (GPG_ERR_GENERAL);
         }
-    }
+      else
+        kb->is_locked = 0;
+   }
 
   return err;
 }

commit 4aceebf36f103eb380e21d12a1f08b7d6ea7cc8e
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Jan 13 14:42:12 2016 +0100

    common: Make sure dotlock functions set a proper ERRNO.
    
    * common/dotlock.c (map_w32_to_errno): New.
    (read_lockfile): Return a proper ERRNO.
    (dotlock_create_unix): Do not let log functions clobber ERRNO.
    (dotlock_take_unix): Ditto.
    (dotlock_release_unix): Ditto.
    (dotlock_create_w32): Set proper ERRNO.
    (dotlock_take_w32): Ditto.
    (dotlock_release_w32): Ditto.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/common/dotlock.c b/common/dotlock.c
index d880859..26005bf 100644
--- a/common/dotlock.c
+++ b/common/dotlock.c
@@ -412,7 +412,8 @@ struct dotlock_handle
 
 
 /* A list of of all lock handles.  The volatile attribute might help
-   if used in an atexit handler.  */
+   if used in an atexit handler.  Note that [UN]LOCK_all_lockfiles
+   must not change ERRNO. */
 static volatile dotlock_t all_lockfiles;
 #ifdef DOTLOCK_USE_PTHREAD
 static pthread_mutex_t all_lockfiles_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -434,6 +435,41 @@ static int never_lock;
 
 
 
+

+#ifdef HAVE_DOSISH_SYSTEM
+static int
+map_w32_to_errno (DWORD w32_err)
+{
+  switch (w32_err)
+    {
+    case 0:
+      return 0;
+
+    case ERROR_FILE_NOT_FOUND:
+      return ENOENT;
+
+    case ERROR_PATH_NOT_FOUND:
+      return ENOENT;
+
+    case ERROR_ACCESS_DENIED:
+      return EPERM;
+
+    case ERROR_INVALID_HANDLE:
+    case ERROR_INVALID_BLOCK:
+      return EINVAL;
+
+    case ERROR_NOT_ENOUGH_MEMORY:
+      return ENOMEM;
+
+    case ERROR_NO_DATA:
+    case ERROR_BROKEN_PIPE:
+      return EPIPE;
+
+    default:
+      return EIO;
+    }
+}
+#endif /*HAVE_DOSISH_SYSTEM*/
 
 

 /* Entirely disable all locking.  This function should be called
@@ -514,11 +550,12 @@ read_lockfile (dotlock_t h, int *same_node )
         continue;
       if (res < 0)
         {
+          int e = errno;
           my_info_1 ("error reading lockfile '%s'\n", h->lockname );
           close (fd);
           if (buffer != buffer_space)
             xfree (buffer);
-          my_set_errno (0); /* Do not return an inappropriate ERRNO. */
+          my_set_errno (e);
           return -1;
         }
       p += res;
@@ -532,7 +569,7 @@ read_lockfile (dotlock_t h, int *same_node )
       my_info_1 ("invalid size of lockfile '%s'\n", h->lockname);
       if (buffer != buffer_space)
         xfree (buffer);
-      my_set_errno (0); /* Better don't return an inappropriate ERRNO. */
+      my_set_errno (EINVAL);
       return -1;
     }
 
@@ -543,7 +580,7 @@ read_lockfile (dotlock_t h, int *same_node )
       my_error_2 ("invalid pid %d in lockfile '%s'\n", pid, h->lockname);
       if (buffer != buffer_space)
         xfree (buffer);
-      my_set_errno (0);
+      my_set_errno (EINVAL);
       return -1;
     }
 
@@ -664,12 +701,14 @@ dotlock_create_unix (dotlock_t h, const char *file_to_lock)
 
   if ( fd == -1 )
     {
+      int saveerrno = errno;
       all_lockfiles = h->next;
       UNLOCK_all_lockfiles ();
       my_error_2 (_("failed to create temporary file '%s': %s\n"),
-                  h->tname, strerror(errno));
+                  h->tname, strerror (errno));
       xfree (h->tname);
       xfree (h);
+      my_set_errno (saveerrno);
       return NULL;
     }
   if ( write (fd, pidstr, 11 ) != 11 )
@@ -696,19 +735,25 @@ dotlock_create_unix (dotlock_t h, const char *file_to_lock)
       h->use_o_excl = 1;
       break;
     default:
-      my_error_2 ("can't check whether hardlinks are supported for '%s': %s\n",
-                  h->tname, strerror(errno));
+      {
+        int saveerrno = errno;
+        my_error_2 ("can't check whether hardlinks are supported for '%s': %s\n"
+                    , h->tname, strerror (saveerrno));
+        my_set_errno (saveerrno);
+      }
       goto write_failed;
     }
 
   h->lockname = xtrymalloc (strlen (file_to_lock) + 6 );
   if (!h->lockname)
     {
+      int saveerrno = errno;
       all_lockfiles = h->next;
       UNLOCK_all_lockfiles ();
       unlink (h->tname);
       xfree (h->tname);
       xfree (h);
+      my_set_errno (saveerrno);
       return NULL;
     }
   strcpy (stpcpy (h->lockname, file_to_lock), EXTSEP_S "lock");
@@ -719,14 +764,18 @@ dotlock_create_unix (dotlock_t h, const char *file_to_lock)
   return h;
 
  write_failed:
-  all_lockfiles = h->next;
-  UNLOCK_all_lockfiles ();
-  my_error_2 (_("error writing to '%s': %s\n"), h->tname, strerror (errno));
-  if ( fd != -1 )
-    close (fd);
-  unlink (h->tname);
-  xfree (h->tname);
-  xfree (h);
+  {
+    int saveerrno = errno;
+    all_lockfiles = h->next;
+    UNLOCK_all_lockfiles ();
+    my_error_2 (_("error writing to '%s': %s\n"), h->tname, strerror (errno));
+    if ( fd != -1 )
+      close (fd);
+    unlink (h->tname);
+    xfree (h->tname);
+    xfree (h);
+    my_set_errno (saveerrno);
+  }
   return NULL;
 }
 #endif /*HAVE_POSIX_SYSTEM*/
@@ -784,11 +833,13 @@ dotlock_create_w32 (dotlock_t h, const char *file_to_lock)
   }
   if (h->lockhd == INVALID_HANDLE_VALUE)
     {
+      int saveerrno = map_w32_to_errno (GetLastError ());
       all_lockfiles = h->next;
       UNLOCK_all_lockfiles ();
       my_error_2 (_("can't create '%s': %s\n"), h->lockname, w32_strerror (-1));
       xfree (h->lockname);
       xfree (h);
+      my_set_errno (saveerrno);
       return NULL;
     }
   return h;
@@ -911,7 +962,7 @@ dotlock_destroy_w32 (dotlock_t h)
 #endif /*HAVE_DOSISH_SYSTEM*/
 
 
-/* Destroy the locck handle H and release the lock.  */
+/* Destroy the lock handle H and release the lock.  */
 void
 dotlock_destroy (dotlock_t h)
 {
@@ -962,6 +1013,7 @@ dotlock_take_unix (dotlock_t h, long timeout)
   int ownerchanged;
   const char *maybe_dead="";
   int same_node;
+  int saveerrno;
 
  again:
   if (h->use_o_excl)
@@ -981,8 +1033,10 @@ dotlock_take_unix (dotlock_t h, long timeout)
         ; /* Lock held by another process.  */
       else if (fd == -1)
         {
+          saveerrno = errno;
           my_error_2 ("lock not made: open(O_EXCL) of '%s' failed: %s\n",
-                      h->lockname, strerror (errno));
+                      h->lockname, strerror (saveerrno));
+          my_set_errno (saveerrno);
           return -1;
         }
       else
@@ -1000,10 +1054,12 @@ dotlock_take_unix (dotlock_t h, long timeout)
               return 0;
             }
           /* Write error.  */
+          saveerrno = errno;
           my_error_2 ("lock not made: writing to '%s' failed: %s\n",
                       h->lockname, strerror (errno));
           close (fd);
           unlink (h->lockname);
+          my_set_errno (saveerrno);
           return -1;
         }
     }
@@ -1016,11 +1072,13 @@ dotlock_take_unix (dotlock_t h, long timeout)
 
       if (stat (h->tname, &sb))
         {
+          saveerrno = errno;
           my_error_1 ("lock not made: Oops: stat of tmp file failed: %s\n",
                       strerror (errno));
           /* In theory this might be a severe error: It is possible
              that link succeeded but stat failed due to changed
              permissions.  We can't do anything about it, though.  */
+          my_set_errno (saveerrno);
           return -1;
         }
 
@@ -1036,7 +1094,9 @@ dotlock_take_unix (dotlock_t h, long timeout)
     {
       if ( errno != ENOENT )
         {
+          saveerrno = errno;
           my_info_0 ("cannot read lockfile\n");
+          my_set_errno (saveerrno);
           return -1;
         }
       my_info_0 ("lockfile disappeared\n");
@@ -1131,6 +1191,7 @@ dotlock_take_w32 (dotlock_t h, long timeout)
     {
       my_error_2 (_("lock '%s' not made: %s\n"),
                   h->lockname, w32_strerror (w32err));
+      my_set_errno (map_w32_to_errno (w32err));
       return -1;
     }
 
@@ -1161,6 +1222,7 @@ dotlock_take_w32 (dotlock_t h, long timeout)
       goto again;
     }
 
+  my_set_errno (EACCES);
   return -1;
 }
 #endif /*HAVE_DOSISH_SYSTEM*/
@@ -1200,23 +1262,29 @@ static int
 dotlock_release_unix (dotlock_t h)
 {
   int pid, same_node;
+  int saveerrno;
 
   pid = read_lockfile (h, &same_node);
   if ( pid == -1 )
     {
+      saveerrno = errno;
       my_error_0 ("release_dotlock: lockfile error\n");
+      my_set_errno (saveerrno);
       return -1;
     }
   if ( pid != getpid() || !same_node )
     {
       my_error_1 ("release_dotlock: not our lock (pid=%d)\n", pid);
+      my_set_errno (EACCES);
       return -1;
     }
 
   if ( unlink( h->lockname ) )
     {
+      saveerrno = errno;
       my_error_1 ("release_dotlock: error removing lockfile '%s'\n",
                   h->lockname);
+      my_set_errno (saveerrno);
       return -1;
     }
   /* Fixme: As an extra check we could check whether the link count is
@@ -1236,8 +1304,10 @@ dotlock_release_w32 (dotlock_t h)
   memset (&ovl, 0, sizeof ovl);
   if (!UnlockFileEx (h->lockhd, 0, 1, 0, &ovl))
     {
+      int saveerrno = map_w32_to_errno (GetLastError ());
       my_error_2 ("release_dotlock: error removing lockfile '%s': %s\n",
                   h->lockname, w32_strerror (-1));
+      my_set_errno (saveerrno);
       return -1;
     }
 

-----------------------------------------------------------------------

Summary of changes:
 common/dotlock.c  | 104 +++++++++++++++++++++++++++++++++++++++++++++---------
 g10/keydb.c       |   2 +-
 kbx/keybox-init.c |  28 +++++++--------
 3 files changed, 101 insertions(+), 33 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list