static void __ni_process_release_user_data(void *user_data) { ni_process_t *pi = user_data; if (pi) ni_process_free(pi); }
/* * Run all the netif firmware discovery scripts and return their output * as one large buffer. */ static ni_buffer_t * __ni_netconfig_firmware_discovery(const char *root, const char *type, const char *path) { ni_buffer_t *result; ni_config_t *config = ni_global.config; ni_extension_t *ex; ni_assert(config); result = ni_buffer_new_dynamic(1024); for (ex = config->fw_extensions; ex; ex = ex->next) { ni_script_action_t *script; if (ex->c_bindings) ni_warn("builtins specified in a netif-firmware-discovery element: not supported"); for (script = ex->actions; script; script = script->next) { ni_process_t *process; int rv; /* Check if requested to use specific type/name only (e.g. "ibft") */ if (type && !ni_string_eq_nocase(type, script->name)) continue; ni_debug_ifconfig("trying to discover netif config via firmware service \"%s\"", script->name); /* Create an instance of this command */ process = ni_process_new(script->process); /* Add root directory argument if given */ if (root) { ni_string_array_append(&process->argv, "-r"); ni_string_array_append(&process->argv, root); } /* Add firmware type specific path argument if given */ if (type && path) { ni_string_array_append(&process->argv, "-p"); ni_string_array_append(&process->argv, path); } rv = ni_process_run_and_capture_output(process, result); ni_process_free(process); if (rv) { ni_error("unable to discover firmware (script \"%s\")", script->name); ni_buffer_free(result); return NULL; } } } return result; }
/* * Run an extension script to update resolver, hostname etc. */ static ni_bool_t ni_system_updater_run(ni_shellcmd_t *shellcmd, ni_string_array_t *args) { ni_process_t *pi; int rv; pi = ni_process_new(shellcmd); if (args) { unsigned int i; for (i = 0; i < args->count; ++i) { const char *arg = args->data[i]; if (arg == NULL) arg = ""; ni_string_array_append(&pi->argv, arg); } } rv = ni_process_run_and_wait(pi); ni_process_free(pi); return rv >= 0; }