int lock_or_unlock(const int do_lock, const gchar *manifest_file, const gchar *coordinator_profile_path, gchar *profile) { GPtrArray *distribution_array; GPtrArray *target_array; int exit_status; if(manifest_file == NULL) { /* Get current username */ char *username = (getpwuid(geteuid()))->pw_name; /* If no manifest file has been provided, try opening the last deployed one */ gchar *old_manifest_file = determine_previous_manifest_file(coordinator_profile_path, username, profile); if(old_manifest_file == NULL) { g_printerr("[coordinator]: No previous manifest file exists, so no locking operations will be executed!\n"); return 0; } else { distribution_array = generate_distribution_array(old_manifest_file); target_array = generate_target_array(old_manifest_file); g_free(old_manifest_file); } } else { /* Open the provided manifest */ distribution_array = generate_distribution_array(manifest_file); target_array = generate_target_array(manifest_file); } if(distribution_array == NULL || target_array == NULL) { g_printerr("ERROR: Cannot open manifest file!\n"); exit_status = 1; } else { /* Override SIGINT's behaviour to allow stuff to be rollbacked in case of an interruption */ set_flag_on_interrupt(); /* Do the locking */ if(do_lock) exit_status = lock(distribution_array, target_array, profile); else exit_status = unlock(distribution_array, target_array, profile); } /* Cleanup */ delete_target_array(target_array); delete_distribution_array(distribution_array); /* Return exit status */ return exit_status; }
void delete_manifest(Manifest *manifest) { if(manifest != NULL) { delete_distribution_array(manifest->distribution_array); delete_activation_array(manifest->activation_array); delete_snapshots_array(manifest->snapshots_array); delete_target_array(manifest->target_array); g_free(manifest); } }