/* * Call a usermode helper with a specific session keyring. */ static int call_usermodehelper_keys(char *path, char **argv, char **envp, struct key *session_keyring, enum umh_wait wait) { gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL; struct subprocess_info *info = call_usermodehelper_setup(path, argv, envp, gfp_mask); if (!info) return -ENOMEM; call_usermodehelper_setfns(info, umh_keys_init, umh_keys_cleanup, key_get(session_keyring)); return call_usermodehelper_exec(info, wait); }
/* * Call a usermode helper with a specific session keyring. */ static int call_usermodehelper_keys(char *path, char **argv, char **envp, struct key *session_keyring, int wait) { struct subprocess_info *info; info = call_usermodehelper_setup(path, argv, envp, GFP_KERNEL, umh_keys_init, umh_keys_cleanup, session_keyring); if (!info) return -ENOMEM; key_get(session_keyring); return call_usermodehelper_exec(info, wait); }
static int exec_python_script(unsigned int sys_num) { char s_num[32]; char *argv[] = {PATH_PYTHON, PATH_SCRIPT, s_num, NULL}; static char *envp[] = {"HOME=/", "TERM=linux", "PATH=/sbin:/bin:/usr/sbin:/usr/bin", NULL}; struct subprocess_info *sub_info; sprintf(s_num, "%d", sys_num); sub_info = call_usermodehelper_setup(argv[0], argv, envp, GFP_ATOMIC); if (sub_info == NULL) return -ENOMEM; call_usermodehelper_exec(sub_info, UMH_WAIT_PROC); return 0; }
/** * orderly_poweroff - Trigger an orderly system poweroff * @force: force poweroff if command execution fails * * This may be called from any context to trigger a system shutdown. * If the orderly shutdown fails, it will force an immediate shutdown. */ int orderly_poweroff(bool force) { int argc; char **argv = argv_split(GFP_ATOMIC, poweroff_cmd, &argc); static char *envp[] = { "HOME=/", "PATH=/sbin:/bin:/usr/sbin:/usr/bin", NULL }; int ret = -ENOMEM; struct subprocess_info *info; if (argv == NULL) { printk(KERN_WARNING "%s failed to allocate memory for \"%s\"\n", __func__, poweroff_cmd); goto out; } info = call_usermodehelper_setup(argv[0], argv, envp); if (info == NULL) { argv_free(argv); goto out; } call_usermodehelper_setcleanup(info, argv_cleanup); ret = call_usermodehelper_exec(info, UMH_NO_WAIT); out: if (ret && force) { printk(KERN_WARNING "Failed to start orderly shutdown: " "forcing the issue\n"); /* I guess this should try to kick off some daemon to sync and poweroff asap. Or not even bother syncing if we're doing an emergency shutdown? */ emergency_sync(); kernel_power_off(); } return ret; }
static int call_modprobe(char *module_name, int wait) { static char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL }; struct subprocess_info *info; char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL); if (!argv) goto out; module_name = kstrdup(module_name, GFP_KERNEL); if (!module_name) goto free_argv; argv[0] = modprobe_path; argv[1] = "-q"; argv[2] = "--"; argv[3] = module_name; /* check free_modprobe_argv() */ argv[4] = NULL; info = call_usermodehelper_setup(argv[0], argv, envp, GFP_ATOMIC); if (!info) goto free_module_name; call_usermodehelper_setcleanup(info, free_modprobe_argv); return call_usermodehelper_exec(info, wait | UMH_KILLABLE); free_module_name: kfree(module_name); free_argv: kfree(argv); out: return -ENOMEM; }
/** * call_usermodehelper_pipe - call a usermode helper process with a pipe stdin * @path: path to usermode executable * @argv: arg vector for process * @envp: environment for process * @filp: set to the write-end of a pipe * * This is a simple wrapper which executes a usermode-helper function * with a pipe as stdin. It is implemented entirely in terms of * lower-level call_usermodehelper_* functions. */ int call_usermodehelper_pipe(char *path, char **argv, char **envp, struct file **filp) { struct subprocess_info *sub_info; int ret; sub_info = call_usermodehelper_setup(path, argv, envp, GFP_KERNEL); if (sub_info == NULL) return -ENOMEM; ret = call_usermodehelper_stdinpipe(sub_info, filp); if (ret < 0) { call_usermodehelper_freeinfo(sub_info); return ret; } ret = call_usermodehelper_exec(sub_info, UMH_WAIT_EXEC); if (ret < 0) /* Failed to execute helper, close pipe */ filp_close(*filp, NULL); return ret; }
extern _upi_bool_ write_backup_file(char *filename, _upi_u8_ *data, _upi_u32_ size) #endif ///< end of uG31xx_OS_WINDOWS { #ifndef uG31xx_BOOT_LOADER #ifndef CONFIG_ASUS_ENGINEER_MODE #ifdef UG31XX_USE_SHELL_AP_FOR_FILE_OP struct subprocess_info *sub_info; char *argv[] = {shell_ap_name, "BACKUP_FILE", "WRITE", filename, NULL}; char *env[] = {NULL}; int rtn; sub_info = NULL; sub_info = call_usermodehelper_setup(argv[0], argv, env, GFP_ATOMIC); if(sub_info == NULL) { return (_UPI_FALSE_); } UG31_LOGN("[%s]: call_usermodehelper_setup() done (%d - %d - %d)\n", __func__, (int)sub_info, (int)data, (int)size); rtn = call_usermodehelper_exec(sub_info, UMH_WAIT_PROC); UG31_LOGN("[%s]: call_usermodehelper_exec() = %d\n", __func__, rtn); return ((rtn == 0) ? _UPI_TRUE_ : _UPI_FALSE_); #else ///< else of UG31XX_USE_SHELL_AP_FOR_FILE_OP #ifdef UG31XX_USE_DAEMON_AP_FOR_FILE_OP if(get_file_op_status() & UG31XX_KERNEL_FILE_FINISH) { clear_file_op_status_bit(UG31XX_KERNEL_FILE_EXIST); clear_file_op_status_bit(UG31XX_KERNEL_FILE_READ); set_file_op_status_bit(UG31XX_KERNEL_FILE_WRITE); return (_UPI_FALSE_); } if(get_file_op_status() & UG31XX_USER_FILE_WRITE) { clear_file_op_status_bit(UG31XX_KERNEL_FILE_EXIST); clear_file_op_status_bit(UG31XX_KERNEL_FILE_WRITE); set_file_op_status_bit(UG31XX_KERNEL_FILE_READ); set_file_op_status_bit(UG31XX_KERNEL_FILE_FINISH); return (_UPI_TRUE_); } clear_file_op_status_bit(UG31XX_KERNEL_FILE_EXIST); clear_file_op_status_bit(UG31XX_KERNEL_FILE_READ); set_file_op_status_bit(UG31XX_KERNEL_FILE_WRITE); set_file_op_status_bit(UG31XX_KERNEL_FILE_FINISH); return (_UPI_FALSE_); #else ///< else of UG31XX_USE_DAEMON_AP_FOR_FILE_OP struct file *fp; _upi_u8_ retry; retry = 3; while(retry) { fp = filp_open(filename, O_CREAT | O_RDWR, 0644); if(!is_err(fp)) { break; } retry = retry - 1; } if(retry == 0) { return (_UPI_FALSE_); } /// [AT-PM] : Write data to file ; 02/21/2013 write_file(fp, data, size); filp_close(fp, _UPI_NULL_); #endif ///< end of UG31XX_USE_DAEMON_AP_FOR_FILE_OP #endif ///< end of UG31XX_USE_SHELL_AP_FOR_FILE_OP #else int backup_tag = BACKUP_BATTERY_KEY; if (ug31xx_save_config_data("ug31xx", data, size)) { UG31_LOGE("[%s]: fail to write Intel UMIP data\n", __func__); return (_UPI_FALSE_); } return (_UPI_TRUE_); #endif #endif ///< end of uG31xx_BOOT_LOADER return (_UPI_TRUE_); }
_upi_bool_ is_file_exist(char *filename) #endif ///< end of uG31xx_OS_WINDOWS { #ifndef uG31xx_BOOT_LOADER #ifndef CONFIG_ASUS_ENGINEER_MODE #ifdef UG31XX_USE_SHELL_AP_FOR_FILE_OP struct subprocess_info *sub_info; char *argv[] = {shell_ap_name, "BACKUP_FILE", "EXIST", filename, NULL}; char *env[] = {NULL}; int rtn; sub_info = NULL; sub_info = call_usermodehelper_setup(argv[0], argv, env, GFP_ATOMIC); if(sub_info == NULL) { return (_UPI_FALSE_); } UG31_LOGN("[%s]: call_usermodehelper_setup() done (%d)\n", __func__, (int)sub_info); rtn = call_usermodehelper_exec(sub_info, UMH_WAIT_PROC); UG31_LOGN("[%s]: call_usermodehelper_exec() = %d\n", __func__, rtn); return ((rtn == 0) ? _UPI_TRUE_ : _UPI_FALSE_); #else ///< else of UG31XX_USE_SHELL_AP_FOR_FILE_OP #ifdef UG31XX_USE_DAEMON_AP_FOR_FILE_OP if(get_file_op_status() & UG31XX_KERNEL_FILE_FINISH) { set_file_op_status_bit(UG31XX_KERNEL_FILE_EXIST); return (_UPI_FALSE_); } if(get_file_op_status() & UG31XX_USER_FILE_EXIST) { clear_file_op_status_bit(UG31XX_KERNEL_FILE_EXIST); set_file_op_status_bit(UG31XX_KERNEL_FILE_READ); set_file_op_status_bit(UG31XX_KERNEL_FILE_FINISH); return (_UPI_TRUE_); } set_file_op_status_bit(UG31XX_KERNEL_FILE_EXIST); set_file_op_status_bit(UG31XX_KERNEL_FILE_FINISH); return (_UPI_FALSE_); #else ///< else of UG31XX_USE_DAEMON_AP_FOR_FILE_OP struct file *fp; _upi_u8_ retry; retry = 3; while(retry) { fp = filp_open(filename, O_RDONLY, 0644); if(!is_err(fp)) { break; } retry = retry - 1; } if(retry == 0) { return (_UPI_FALSE_); } filp_close(fp, _UPI_NULL_); #endif ///< end of UG31XX_USE_DAEMON_AP_FOR_FILE_OP #endif ///< end of UG31XX_USE_SHELL_AP_FOR_FILE_OP #else _upi_u8_ backup_tag = 0; if (ug31xx_read_backup_tag("ug31xx", &backup_tag)) return (_UPI_FALSE_); if (backup_tag != BACKUP_BATTERY_KEY) return (_UPI_FALSE_); return (_UPI_TRUE_); #endif #endif ///< end of uG31xx_BOOT_LOADER return (_UPI_TRUE_); }