static int unlock(const GPtrArray *distribution_array, const GPtrArray *target_array, gchar *profile) { unsigned int i, running_processes = 0; int exit_status = 0; int status; /* For each locked machine, release the lock */ for(i = 0; i < distribution_array->len; i++) { DistributionItem *item = g_ptr_array_index(distribution_array, i); Target *target = find_target(target_array, item->target); gchar *interface = find_target_client_interface(target); g_print("[target: %s]: Releasing a lock!\n", item->target); status = exec_unlock(interface, item->target, profile); if(status == -1) { g_printerr("[target: %s]: Error with forking unlock process!\n", item->target); exit_status = -1; } else running_processes++; } /* Wait until every lock is released */ for(i = 0; i < running_processes; i++) { status = wait_to_finish(0); /* If a process fails, change the exit status */ if(status != 0) { g_printerr("Failed to release the lock!\n"); exit_status = status; } } /* Return exit status, which is 0 if everything succeeds */ return exit_status; }
static pid_t unlock_distribution_item(void *data, DistributionItem *item, Target *target) { char *profile = (char*)data; g_print("[target: %s]: Releasing a lock on profile: %s\n", item->target, item->profile); return exec_unlock((char*)target->client_interface, (char*)item->target, profile); }