Author: sandervanderburg
Date: Sun Oct 17 22:11:08 2010
New Revision: 24335
URL: https://svn.nixos.org/websvn/nix/?rev=24335&sc=1

Log:
All the functions now return an integer return status, instead of boolean. This 
makes the functions consistent with the other library functions

Modified:
   disnix/disnix/trunk/src/activate/activate.c
   disnix/disnix/trunk/src/activate/locking.c
   disnix/disnix/trunk/src/activate/locking.h
   disnix/disnix/trunk/src/activate/profiles.c
   disnix/disnix/trunk/src/activate/profiles.h
   disnix/disnix/trunk/src/activate/transition.c
   disnix/disnix/trunk/src/activate/transition.h

Modified: disnix/disnix/trunk/src/activate/activate.c
==============================================================================
--- disnix/disnix/trunk/src/activate/activate.c Sun Oct 17 19:30:59 2010        
(r24334)
+++ disnix/disnix/trunk/src/activate/activate.c Sun Oct 17 22:11:08 2010        
(r24335)
@@ -34,6 +34,7 @@
 {
     gchar *old_manifest_file;
     GArray *old_activation_mappings;
+    int status;
     int exit_status = 0;
     
     /* Get all the distribution items of the new configuration */
@@ -72,7 +73,7 @@
     /* If we have an old configuration -> open it */
     if(old_manifest_file != NULL)
     {              
-        printf("Using previous manifest: %s\n", old_manifest_file);
+        g_print("Using previous manifest: %s\n", old_manifest_file);
         old_activation_mappings = create_activation_array(old_manifest_file);
         
        /* Free the variable because it's not needed anymore */
@@ -81,40 +82,44 @@
     else
         old_activation_mappings = NULL;
 
-
     /* Try to acquire a lock */
-    if(lock(interface, distribution_array, profile))
+    
+    status = lock(interface, distribution_array, profile);
+    
+    if(status == 0)
     {
        /* Execute transition */
-       if(transition(interface, new_activation_mappings, 
old_activation_mappings))
-       {
-           int status;
-           
+       status = transition(interface, new_activation_mappings, 
old_activation_mappings);
+       
+       if(status == 0)
+       {                   
            /* Set the new profiles on the target machines */
-           printf("Setting the new profiles on the target machines:\n");
+           g_print("Setting the new profiles on the target machines:\n");
            status = set_target_profiles(distribution_array, interface, 
profile);
            
            /* Try to release the lock */
            unlock(interface, distribution_array, profile);
            
            /* If setting the profiles succeeds -> set the coordinator profile 
*/
-           if(status)
+           if(status == 0)
            {
-               if(!set_coordinator_profile(coordinator_profile_path, 
new_manifest, profile, username))
-                   exit_status = 1; /* if settings the coordinator profile 
fails -> change exit status */
+               status = set_coordinator_profile(coordinator_profile_path, 
new_manifest, profile, username);
+               
+               if(status != 0)
+                   exit_status = status; /* if settings the coordinator 
profile fails -> change exit status */
            }
            else
-               exit_status = 1; /* else change exit status */
+               exit_status = status; /* else change exit status */
        }
        else
        {
            /* Try to release the lock */
            unlock(interface, distribution_array, profile); 
-           exit_status = 1;
+           exit_status = status;
        }
     }
     else
-       exit_status = 1;
+       exit_status = status;
 
     /* Cleanup */
     delete_distribution_array(distribution_array);

Modified: disnix/disnix/trunk/src/activate/locking.c
==============================================================================
--- disnix/disnix/trunk/src/activate/locking.c  Sun Oct 17 19:30:59 2010        
(r24334)
+++ disnix/disnix/trunk/src/activate/locking.c  Sun Oct 17 22:11:08 2010        
(r24335)
@@ -21,10 +21,10 @@
 #include <distributionmapping.h>
 #include <client-interface.h>
 
-gboolean unlock(gchar *interface, GArray *distribution_array, gchar *profile)
+int unlock(gchar *interface, GArray *distribution_array, gchar *profile)
 {
     unsigned int i, running_processes = 0;
-    int exit_status = TRUE;
+    int exit_status = 0;
     int status;
     
     /* For each locked machine, release the lock */
@@ -37,7 +37,7 @@
        if(status == -1)
        {
            g_printerr("Error with forking unlock process!\n");
-           exit_status = FALSE;
+           exit_status = -1;
        }
        else
            running_processes++;
@@ -52,20 +52,20 @@
        if(status != 0)
        {
            g_printerr("Failed to release the lock!\n");
-           exit_status = FALSE;
+           exit_status = status;
        }
     }
     
-    /* Return exit status */
+    /* Return exit status, which is 0 if everything succeeds */
     return exit_status;
 }
 
-gboolean lock(gchar *interface, GArray *distribution_array, gchar *profile)
+int lock(gchar *interface, GArray *distribution_array, gchar *profile)
 {
     unsigned int i;
     GArray *try_array = g_array_new(FALSE, FALSE, sizeof(DistributionItem*));
     GArray *lock_array = g_array_new(FALSE, FALSE, sizeof(DistributionItem*));
-    int exit_status = TRUE;
+    int exit_status = 0;
     int status;
     
     /* For each machine acquire a lock */
@@ -79,8 +79,8 @@
        if(status == -1)
        {
            g_printerr("Error with forking lock process!\n");
-           exit_status = FALSE;
-       }       
+           exit_status = -1;
+       }
        else
            g_array_append_val(try_array, item);
     }    
@@ -94,7 +94,7 @@
        if(status != 0)
        {
            g_printerr("Failed to acquire a lock!\n");
-           exit_status = FALSE;
+           exit_status = status;
        }
     }
     
@@ -106,6 +106,6 @@
     g_array_free(try_array, TRUE);
     g_array_free(lock_array, TRUE);
     
-    /* Return exit status */
+    /* Return exit status, which is 0 if everything succeeds */
     return exit_status;
 }

Modified: disnix/disnix/trunk/src/activate/locking.h
==============================================================================
--- disnix/disnix/trunk/src/activate/locking.h  Sun Oct 17 19:30:59 2010        
(r24334)
+++ disnix/disnix/trunk/src/activate/locking.h  Sun Oct 17 22:11:08 2010        
(r24335)
@@ -27,9 +27,9 @@
  * @param interface Path to the client interface executable
  * @param distribution_array Array with profiles distributed to the target 
machines
  * @param profile Identifier of the distributed profile
- * @return TRUE if the unlocking phase succeeds, else FALSE
+ * @return 0 if the unlocking phase succeeds, else a non-zero exit status
  */
-gboolean unlock(gchar *interface, GArray *distribution_array, gchar *profile);
+int unlock(gchar *interface, GArray *distribution_array, gchar *profile);
 
 /**
  * Locks the given profile on each machine defined in the distribution array.
@@ -38,8 +38,8 @@
  * @param interface Path to the client interface executable
  * @param distribution_array Array with profiles distributed to the target 
machines
  * @param profile Identifier of the distributed profile
- * @return TRUE if the locking phase succeeds, else FALSE
+ * @return 0 if the unlocking phase succeeds, else a non-zero exit status
  */
-gboolean lock(gchar *interface, GArray *distribution_array, gchar *profile);
+int lock(gchar *interface, GArray *distribution_array, gchar *profile);
 
 #endif

Modified: disnix/disnix/trunk/src/activate/profiles.c
==============================================================================
--- disnix/disnix/trunk/src/activate/profiles.c Sun Oct 17 19:30:59 2010        
(r24334)
+++ disnix/disnix/trunk/src/activate/profiles.c Sun Oct 17 22:11:08 2010        
(r24335)
@@ -26,10 +26,11 @@
 #include <sys/stat.h>
 #include <string.h>
 
-gboolean set_target_profiles(GArray *distribution_array, gchar *interface, 
gchar *profile)
+int set_target_profiles(GArray *distribution_array, gchar *interface, gchar 
*profile)
 {
     unsigned int i;
-        
+    int exit_status = 0;
+    
     for(i = 0; i < distribution_array->len; i++)
     {
        int status;
@@ -42,14 +43,14 @@
        if(status != 0)
        {
            g_printerr("Cannot set profile!\n");
-           return FALSE;
+           exit_status = status;
        }
     }
 
-    return TRUE;
+    return exit_status;
 }
 
-gboolean set_coordinator_profile(gchar *coordinator_profile_path, gchar 
*manifest_file, gchar *profile, gchar *username)
+int set_coordinator_profile(gchar *coordinator_profile_path, gchar 
*manifest_file, gchar *profile, gchar *username)
 {
     gchar *profile_path, *manifest_file_path;
     int status;
@@ -104,14 +105,14 @@
     
     /* If the process suceeds the the operation succeeded */
     if(status == -1)
-       return FALSE;
+       return -1;
     else
     {
        wait(&status);
     
        if(WEXITSTATUS(status) == 0)
-           return TRUE;
+           return 0;
        else
-           return FALSE;
+           return WEXITSTATUS(status);
     }
 }

Modified: disnix/disnix/trunk/src/activate/profiles.h
==============================================================================
--- disnix/disnix/trunk/src/activate/profiles.h Sun Oct 17 19:30:59 2010        
(r24334)
+++ disnix/disnix/trunk/src/activate/profiles.h Sun Oct 17 22:11:08 2010        
(r24335)
@@ -28,9 +28,9 @@
  * @param distribution_array Array with Nix profiles containing installed 
services for each machine
  * @param interface Path to the client interface executable
  * @param profile Name of the distributed profile
- * @return TRUE if everything succeeds, else FALSE
+ * @return 0 if everything succeeds, else a non-zero exit status
  */
-gboolean set_target_profiles(GArray *distribution_array, gchar *interface, 
gchar *profile);
+int set_target_profiles(GArray *distribution_array, gchar *interface, gchar 
*profile);
 
 /**
  * Sets the Disnix coordinator profile, so that the current configuration is 
@@ -40,8 +40,8 @@
  * @param manifest_file Path to the manifest file representing the deployment 
state
  * @param profile Name of the distributed profile
  * @param username Username of the current user invoking the activation
- * @return TRUE if everything succeeds, else FALSE
+ * @return 0 if everything succeeds, else a non-zero exit status
  */
-gboolean set_coordinator_profile(gchar *coordinator_profile_path, gchar 
*manifest_file, gchar *profile, gchar *username);
+int set_coordinator_profile(gchar *coordinator_profile_path, gchar 
*manifest_file, gchar *profile, gchar *username);
 
 #endif

Modified: disnix/disnix/trunk/src/activate/transition.c
==============================================================================
--- disnix/disnix/trunk/src/activate/transition.c       Sun Oct 17 19:30:59 
2010        (r24334)
+++ disnix/disnix/trunk/src/activate/transition.c       Sun Oct 17 22:11:08 
2010        (r24335)
@@ -21,7 +21,7 @@
 #include <activationmapping.h>
 #include <client-interface.h>
 
-static gboolean activate(gchar *interface, GArray *union_array, 
ActivationMapping *mapping)
+static int activate(gchar *interface, GArray *union_array, ActivationMapping 
*mapping)
 {
     /* Search for the location of the mapping in the union array */
     gint actual_mapping_index = activation_mapping_index(union_array, mapping);
@@ -33,6 +33,7 @@
     if(actual_mapping->depends_on != NULL)
     {
        unsigned int i;
+       int status;
        
        for(i = 0; i < actual_mapping->depends_on->len; i++)
        {
@@ -41,9 +42,11 @@
            ActivationMapping lookup;
            lookup.service = dependency->service;
            lookup.target = dependency->target;
-                   
-           if(!activate(interface, union_array, &lookup))
-               return FALSE; /* If the activation of an inter-dependency 
fails, abort */
+           
+           status = activate(interface, union_array, &lookup);
+           
+           if(status != 0)
+               return status; /* If the activation of an inter-dependency 
fails, abort */
        }
     }
     
@@ -78,15 +81,15 @@
        g_strfreev(arguments);
        
        if(status != 0)
-           return FALSE; /* If the activation fails, abort */
+           return status; /* If the activation fails, abort */
        else            
            actual_mapping->activated = TRUE; /* Mark activation mapping as 
activated */
     }
     
-    return TRUE; /* The activation of the closure succeeded */
+    return 0; /* The activation of the closure succeeded */
 }
 
-static gboolean deactivate(gchar *interface, GArray *union_array, 
ActivationMapping *mapping)
+static int deactivate(gchar *interface, GArray *union_array, ActivationMapping 
*mapping)
 {
     /* Search for the location of the mapping in the union array */
     gint actual_mapping_index = activation_mapping_index(union_array, mapping);
@@ -104,10 +107,12 @@
     for(i = 0; i < interdependent_mappings->len; i++)
     {
         ActivationMapping *dependency_mapping = 
g_array_index(interdependent_mappings, ActivationMapping*, i);
-        if(!deactivate(interface, union_array, dependency_mapping))
+       int status = deactivate(interface, union_array, dependency_mapping);
+       
+        if(status != 0)
        {
            g_array_free(interdependent_mappings, TRUE);
-           return FALSE; /* If the deactivation of an inter-dependency fails, 
abort */
+           return status; /* If the deactivation of an inter-dependency fails, 
abort */
        }
     }
     
@@ -143,21 +148,21 @@
        g_free(arguments);
 
        if(status != 0)
-           return FALSE; /* If the deactivation fails, abort */
+           return status; /* If the deactivation fails, abort */
        else
            actual_mapping->activated = FALSE; /* Mark activation mapping as 
deactivated */
     }
     
-    return TRUE; /* The deactivation of the closure succeeded */
+    return 0; /* The deactivation of the closure succeeded */
 }
 
-gboolean transition(gchar *interface, GArray *new_activation_mappings, GArray 
*old_activation_mappings)
+int transition(gchar *interface, GArray *new_activation_mappings, GArray 
*old_activation_mappings)
 {
     GArray *union_array;
     GArray *deactivation_array;
     GArray *activation_array;
-    gboolean exit_status = TRUE;
     unsigned int i;
+    int exit_status = 0;
     
     /* Print configurations */
     
@@ -215,11 +220,12 @@
         for(i = 0; i < deactivation_array->len; i++)
         {
            ActivationMapping *mapping = g_array_index(deactivation_array, 
ActivationMapping*, i);
-                               
-           if(!deactivate(interface, union_array, mapping))
+           int status = deactivate(interface, union_array, mapping);
+                       
+           if(status != 0)
            {
                /* If the deactivation fails, perform a rollback */
-               
+                               
                unsigned int j;
                g_print("Deactivation failed! Doing a rollback...\n");
                
@@ -227,11 +233,11 @@
                {
                    ActivationMapping *mapping = g_array_index(union_array, 
ActivationMapping*, j);
                    
-                   if(!activate(interface, union_array, mapping))
+                   if(activate(interface, union_array, mapping) != 0)
                        g_print("Rollback failed!\n");                          
    
                }               
                
-               exit_status = FALSE;
+               exit_status = status;
                break;
            }
        }
@@ -239,7 +245,7 @@
 
     /* Execute activation process (if deactivation process did not fail) */
     
-    if(exit_status)
+    if(exit_status == 0)
     {
        g_print("Executing activation:\n");
 
@@ -248,8 +254,9 @@
        for(i = 0; i < activation_array->len; i++)
        {
            ActivationMapping *mapping = g_array_index(activation_array, 
ActivationMapping*, i);
+           int status = activate(interface, union_array, mapping);
            
-           if(!activate(interface, union_array, mapping))
+           if(status != 0)
            {
                /* If the activation fails, perform a rollback */
            
@@ -261,7 +268,7 @@
                {
                    ActivationMapping *mapping = 
g_array_index(activation_array, ActivationMapping*, j);
            
-                   if(!deactivate(interface, union_array, mapping))
+                   if(deactivate(interface, union_array, mapping) != 0)
                        g_print("Rollback failed!\n");
                }
            
@@ -272,12 +279,12 @@
                    {
                        ActivationMapping *mapping = 
g_array_index(old_activation_mappings, ActivationMapping*, j);
                
-                       if(!activate(interface, union_array, mapping))
+                       if(activate(interface, union_array, mapping) != 0)
                            g_print("Rollback failed!\n");
                    }
                }
            
-               exit_status = FALSE;
+               exit_status = status;
                break;
            }
        }
@@ -292,6 +299,6 @@
        g_array_free(union_array, TRUE);
     }
     
-    /* Transition process succeeded */
+    /* Returns the exit status, which is 0 if everything succeeded */
     return exit_status;
 }

Modified: disnix/disnix/trunk/src/activate/transition.h
==============================================================================
--- disnix/disnix/trunk/src/activate/transition.h       Sun Oct 17 19:30:59 
2010        (r24334)
+++ disnix/disnix/trunk/src/activate/transition.h       Sun Oct 17 22:11:08 
2010        (r24335)
@@ -28,8 +28,8 @@
  * @param interface Path to the client interface executable
  * @param new_activation_mappings Array containing the activation mappings of 
the new configuration
  * @param old_activation_mappings Array containing the activation mappings of 
the old configuration
- * @return TRUE if the phase succeeds, else FALSE
+ * @return 0 if the phase succeeds, else a non-zero exit status
  */
-gboolean transition(gchar *interface, GArray *new_activation_mappings, GArray 
*old_activation_mappings);
+int transition(gchar *interface, GArray *new_activation_mappings, GArray 
*old_activation_mappings);
 
 #endif
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits

Reply via email to