[Pkg-privacy-commits] [libgsecuredelete] 41/168: Properly set and unset the busy flag.

Ulrike Uhlig u-guest at moszumanska.debian.org
Thu Jul 7 20:06:36 UTC 2016


This is an automated email from the git hooks/post-receive script.

u-guest pushed a commit to branch master
in repository libgsecuredelete.

commit 68c6eafaca7dc202158ee6df6a0dbf52cee84295
Author: Colomban Wendling <ban at herbesfolles.org>
Date:   Sat Nov 14 00:36:35 2009 +0100

    Properly set and unset the busy flag.
    
    Do not forget to release the busy flag on some error scenarios.
    Actually lock the busy flag for thread-safety.
---
 gsecuredelete/async-operation.vala | 117 ++++++++++++++++++-------------------
 gsecuredelete/fill-operation.vala  |   2 -
 gsecuredelete/swap-operation.vala  |   2 -
 3 files changed, 58 insertions(+), 63 deletions(-)

diff --git a/gsecuredelete/async-operation.vala b/gsecuredelete/async-operation.vala
index dc25df2..8a9d6be 100644
--- a/gsecuredelete/async-operation.vala
+++ b/gsecuredelete/async-operation.vala
@@ -118,6 +118,7 @@ namespace Gsd
     protected int   fd_in;
     protected int   fd_out;
     protected int   fd_err;
+    private bool    _busy = false;
     
     /* signals */
     /** AsyncOperation::finished:
@@ -142,9 +143,9 @@ namespace Gsd
      * doing a job.
      */
     public bool busy {
-      public    get;
-      protected set;
-      default = false;
+      public get {
+        return this._busy;
+      }
     }
     
     /* builds the command's arguments (argv) */
@@ -262,8 +263,8 @@ namespace Gsd
         Posix.close (this.fd_err);
         Posix.close (this.fd_out);
         Posix.close (this.fd_in);
-        /*lock (this.busy)*/ {
-          this.busy = false;
+        lock (this._busy) {
+          this._busy = false;
         }
       }
       
@@ -289,36 +290,40 @@ namespace Gsd
                      SpawnFlags spawn_flags = 0,
                      uint       watch_interval = 100)
       throws SpawnError, AsyncOperationError
-      requires (! this.busy)
     {
-      bool      success = true;
+      bool      success = false;
+      bool      busy    = false;
       string?[] args;
       
-      /*lock (this.busy)*/ {
-        this.busy = true;
+      lock (this._busy) {
+        busy = this._busy;
+        /* no need to test the value as it is either already true or we need to
+         * set it to true */
+        this._busy = true;
       }
+      return_val_if_fail (! busy, false);
       try {
         args = this.do_build_args ();
-      } catch (AsyncOperationError e) {
-        throw e;
-      }
-      this.fd_err = -1;
-      this.fd_out = -1;
-      this.n_passes = this.get_max_progress ();
-      this.passes = 0;
-      try {
-        Process.spawn_async_with_pipes (working_directory,
-                                        args, this.build_environ (),
-                                        spawn_flags | SpawnFlags.DO_NOT_REAP_CHILD,
-                                        null,
-                                        out this.pid, out this.fd_in,
-                                        out this.fd_out, out this.fd_err);
-      } catch (SpawnError e) {
-        success = false;
-        throw e;
-      }
-      if (success) {
-        Timeout.add (watch_interval, this.do_wait_child);
+        this.fd_err = -1;
+        this.fd_out = -1;
+        this.n_passes = this.get_max_progress ();
+        this.passes = 0;
+        success = Process.spawn_async_with_pipes (
+          working_directory, args, this.build_environ (),
+          spawn_flags | SpawnFlags.DO_NOT_REAP_CHILD, null,
+          out this.pid, out this.fd_in, out this.fd_out, out this.fd_err
+        );
+        if (success) {
+          Timeout.add (watch_interval, this.do_wait_child);
+        }
+      } finally {
+        /* if success is false, an error was thrown and the timeout not added,
+         * then release the busy lock here */
+        if (! success) {
+          lock (this._busy) {
+            this._busy = false;
+          }
+        }
       }
       
       return success;
@@ -344,22 +349,20 @@ namespace Gsd
                           SpawnFlags spawn_flags = 0,
                           out string standard_output)
       throws SpawnError, AsyncOperationError
-      requires (! this.busy)
     {
       bool      success = true;
+      bool      busy    = false;
       string    error_output;
       int       exit_status;
       string?[] args;
       
-      /*lock (this.busy)*/ {
-        this.busy = true;
+      lock (this._busy) {
+        busy = this._busy;
+        this._busy = true;
       }
+      return_val_if_fail (! busy, false);
       try {
         args = this.do_build_args ();
-      } catch (AsyncOperationError e) {
-        throw e;
-      }
-      try {
         /* FIXME: hack the current Vala lack of check for null-ness of out
          * parameters before using it.
          * It seems to be a planned thing (as of Vala 0.7.7), as juergbi said on
@@ -373,32 +376,28 @@ namespace Gsd
                               spawn_flags, null,
                               null, out error_output, out exit_status);
         }
-      } catch (SpawnError e) {
-        success = false;
-        throw e;
-      }
-      if (success) {
-        string? message = null;
-        
-        success = false;
-        if (! Process.if_exited (exit_status)) {
-          message = "Subprocess crashed: " + error_output;
-        } else if (Process.exit_status (exit_status) != 0) {
-          message = "Subprocess failed: " + error_output;
-        } else {
-          success = true;
+        if (success) {
+          string? message = null;
+          
+          success = false;
+          if (! Process.if_exited (exit_status)) {
+            message = "Subprocess crashed: " + error_output;
+          } else if (Process.exit_status (exit_status) != 0) {
+            message = "Subprocess failed: " + error_output;
+          } else {
+            success = true;
+          }
+          this.finished (success, message);
+          this.cleanup ();
+          if (message != null) {
+            throw new AsyncOperationError.CHILD_FAILED ("%s", message);
+          }
         }
-        this.finished (success, message);
-        this.cleanup ();
-        /* FIXME: if this prevent the rest of the function to be executed, the
-         * lock wouldn't be released */
-        if (message != null) {
-          throw new AsyncOperationError.CHILD_FAILED ("%s", message);
+      } finally {
+        lock (this._busy) {
+          this._busy = false;
         }
       }
-      /*lock (this.busy)*/ {
-        this.busy = false;
-      }
       
       return success;
     }
diff --git a/gsecuredelete/fill-operation.vala b/gsecuredelete/fill-operation.vala
index 12d23e8..d0ba21c 100644
--- a/gsecuredelete/fill-operation.vala
+++ b/gsecuredelete/fill-operation.vala
@@ -119,7 +119,6 @@ namespace Gsd
     public new bool run (string? directory = null,
                          uint watch_interval = 100)
       throws SpawnError, AsyncOperationError
-      requires (! this.busy)
     {
       if (directory != null) {
         this.directory = directory;
@@ -138,7 +137,6 @@ namespace Gsd
      */
     public new bool run_sync (string? directory = null)
       throws SpawnError, AsyncOperationError
-      requires (! this.busy)
     {
       if (directory != null) {
         this.directory = directory;
diff --git a/gsecuredelete/swap-operation.vala b/gsecuredelete/swap-operation.vala
index 40aa1bc..80f1d9a 100644
--- a/gsecuredelete/swap-operation.vala
+++ b/gsecuredelete/swap-operation.vala
@@ -121,7 +121,6 @@ namespace Gsd
     public new bool run (string? device = null,
                          uint watch_interval = 100)
       throws SpawnError, AsyncOperationError
-      requires (! this.busy)
     {
       if (device != null) {
         this.device = device;
@@ -139,7 +138,6 @@ namespace Gsd
      */
     public new bool run_sync (string? device = null)
       throws SpawnError, AsyncOperationError
-      requires (! this.busy)
     {
       if (device != null) {
         this.device = device;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/libgsecuredelete.git



More information about the Pkg-privacy-commits mailing list