static int wait_to_complete_snapshot_item(GHashTable *pid_table, GPtrArray *target_array, complete_snapshot_item_mapping_function complete_snapshot_item_mapping) { int wstatus; pid_t pid = wait(&wstatus); if(pid == -1) return FALSE; else { Target *target; ProcReact_Status status; /* Find the corresponding snapshot mapping and remove it from the pids table */ SnapshotMapping *mapping = g_hash_table_lookup(pid_table, &pid); g_hash_table_remove(pid_table, &pid); /* Mark mapping as transferred to prevent it from snapshotting again */ mapping->transferred = TRUE; /* Signal the target to make the CPU core available again */ target = find_target(target_array, mapping->target); signal_available_target_core(target); /* Return the status */ int result = procreact_retrieve_boolean(pid, wstatus, &status); complete_snapshot_item_mapping(mapping, status, result); return(status == PROCREACT_STATUS_OK && result); } }
static void wait_for_activation_or_deactivation(const int activate, GHashTable *pids, GPtrArray *target_array) { int status; Target *target; /* Wait for an activation/deactivation process to finish */ pid_t pid = wait(&status); if(pid != -1) { /* Find the corresponding activation mapping and remove it from the pids table */ ActivationMapping *mapping = g_hash_table_lookup(pids, &pid); g_hash_table_remove(pids, &pid); /* Change the status of the mapping, if the process returns success */ if(WEXITSTATUS(status) == 0) { if(activate) mapping->status = ACTIVATIONMAPPING_ACTIVATED; else mapping->status = ACTIVATIONMAPPING_DEACTIVATED; } else { mapping->status = ACTIVATIONMAPPING_ERROR; if(activate) g_printerr("[target: %s]: Activation failed of service: %s\n", mapping->target, mapping->key); else g_printerr("[target: %s]: Deactivation failed of service: %s\n", mapping->target, mapping->key); } /* Signal the target to make the CPU core available again */ target = find_target(target_array, mapping->target); signal_available_target_core(target); } }