Exec_stat MCAsk::exec(class MCExecPoint& ep) { Exec_errors t_error = EE_UNDEFINED; Meta::cstring_value t_title; MCresult -> clear(False); t_error = Meta::evaluate(ep, title, t_title, EE_ANSWER_BADTITLE); if (!t_error) switch(mode) { case AT_PASSWORD: case AT_CLEAR: t_error = exec_password(ep, t_title); break; case AT_FILE: t_error = exec_file(ep, t_title); break; default: t_error = exec_question(ep, t_title); break; } if (!t_error) it -> set(ep); else MCeerror -> add(t_error, line, pos); return t_error ? ES_ERROR : ES_NORMAL; }
int main(int argc, char* argv[]) { /* Check we're running in Pyrebox */ if (!check_for_pyrebox()) { fprintf(stderr, "This program doesn't seem to be run under Pyrebox.\n"); return 1; } /* Wait for Pyrebox to signal some command. Several commands can be executed * one after the other. This is also useful to stall execution to take a snapshot while the execution is here, and then resume from the snapshot and run some command when asked for. */ int cmd = CMD_WAIT; while ((cmd = host_get_command()) != CMD_EXIT) { switch(cmd) { case CMD_WAIT: sleep(1); break; case CMD_COPY: copy_file(); break; case CMD_EXEC: exec_file(); break; case CMD_EXIT: return 0; default: printf("Invalid command requested: %d\n",cmd); break; } } }
int parse_file(char *ptr) { char *p; char *str; size_t i = 0; file_instruction *command; p = strchr(ptr, '\n'); /* Si on est en fin de config */ if(p == NULL) return 0; /* Si c'est un commentaire */ if (ptr[0] == '#') return parse_file(p+1); /* On grille les espaces eventuels */ while (ptr[i] == ' ') i++; /* Si c'est une ligne d'espaces */ if (ptr[i] == '\n') return parse_file(p+1); /* On alloue la ligne de config */ str = malloc(sizeof(char) * (1+p-ptr)); memcpy(str, ptr, p-ptr); str[p-ptr] = '\0'; /* On execute la ligne de config */ command = creat_liste_instruction(str); exec_file(command); free_file_instruction(command); free(str); return parse_file(p+1); }
PAM_EXTERN int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc, const char **argv) { int retval = PAM_IGNORE; gray_slist_t slist; cntl_flags = 0; debug_level = 0; gray_log_init(0, MODULE_NAME, LOG_AUTHPRIV); gray_parseopt(pam_opt, argc, argv); if (la_str) { double max_la, la; if (fpread(la_str, &max_la)) return PAM_SERVICE_ERR; if (get_la(&la) == 0 && la >= max_la) { _pam_log(LOG_ERR, "load average too high: %.2g >= %.2g", la, max_la); return PAM_IGNORE; } } if (motd_file_name) { char *file; slist = gray_slist_create(); gray_expand_string(pamh, motd_file_name, slist); gray_slist_append_char(slist, 0); file = gray_slist_finish(slist); retval = read_file(pamh, file); gray_slist_free(&slist); } else if (optindex >= 0) { int i; char **xargv; argc -= optindex; argv += optindex; if (!argc) { _pam_log(LOG_INFO, "empty command line"); return retval; } xargv = gray_malloc((argc + 1) * sizeof (xargv[0])); slist = gray_slist_create(); for (i = 0; i < argc; i++) { gray_expand_string(pamh, argv[i], slist); gray_slist_append_char(slist, 0); xargv[i] = gray_slist_finish(slist); } xargv[i] = NULL; retval = exec_file(pamh, xargv, logfile_name); free(xargv); gray_slist_free(&slist); } else _pam_log(LOG_ERR, "invalid usage: either file or exec must be specified"); return retval; }
bool configureHook() { os::MutexLock lock(m); if(!lua_string.empty()) exec_str(lua_string); if(!lua_file.empty()) exec_file(lua_file); return call_func(L, "configureHook", this); }
Exec_stat MCAnswer::exec(MCExecPoint& ep) { Exec_errors t_error = EE_UNDEFINED; Meta::cstring_value t_title; t_error = Meta::evaluate(ep, title, t_title, EE_ANSWER_BADTITLE); if (!t_error) switch(mode) { case AT_PAGESETUP: t_error = exec_pagesetup(ep, t_title); break; case AT_PRINTER: t_error = exec_printer(ep, t_title); break; case AT_EFFECT: t_error = exec_effect(ep, t_title); break; case AT_RECORD: t_error = exec_record(ep, t_title); break; case AT_COLOR: t_error = exec_colour(ep, t_title); break; case AT_FILE: case AT_FILES: t_error = exec_file(ep, t_title); break; case AT_FOLDER: case AT_FOLDERS: t_error = exec_folder(ep, t_title); break; default: t_error = exec_notify(ep, t_title); break; } if (!t_error) it -> set(ep); else MCeerror -> add(t_error, line, pos); return t_error ? ES_ERROR : ES_NORMAL; }
tm_server_rep::tm_server_rep (): def_zoomf (1.0) { the_server= tm_new<server> (this); initialize_scheme (); gui_interpose (texmacs_interpose_handler); set_wait_handler (texmacs_wait_handler); if (is_none (tm_init_file)) tm_init_file= "$TEXMACS_PATH/progs/init-texmacs.scm"; if (is_none (my_init_file)) my_init_file= "$TEXMACS_HOME_PATH/progs/my-init-texmacs.scm"; bench_start ("initialize scheme"); if (exists (tm_init_file)) exec_file (tm_init_file); if (exists (my_init_file)) exec_file (my_init_file); bench_cumul ("initialize scheme"); if (my_init_cmds != "") { my_init_cmds= "(begin" * my_init_cmds * ")"; exec_delayed (scheme_cmd (my_init_cmds)); } #ifdef OS_GNU_LINUX return; // in order to avoid segmentation faults #elif defined OS_POWERPC_GNU_LINUX return; // in order to avoid segmentation faults #endif }
void PythonConfig::loadConfig(const std::string &filename) { try { exec_file(boost::python::str(filename), main_namespace); } catch(boost::python::error_already_set const &) { std::cerr << "Error while parsing config file: " << filename << std::endl; PyErr_Print(); exit(1); } config = getattr(main_module, "config", true); }
void exec_cmd(char *str) { char **cmd; str = ft_strdup(parse_vars(str)); if (!(cmd = split_cmd(str)) || !cmd[0]) { free_tab(cmd); return ; } if (!exec_file(cmd) && !exec_builtin(cmd)) exec_path(cmd); free(str); free_tab(cmd); }
interpreter_t::interpreter_t() { PyImport_AppendInittab(( char *) "_ramen", &init_ramen); Py_Initialize(); bpy::object main_module( bpy::handle<>( bpy::borrowed( PyImport_AddModule( "__main__")))); main_namespace_ = main_module.attr( "__dict__"); setup_python_paths( main_namespace_); init_pyside(); // default import our module. bpy::object module(( bpy::handle<>( PyImport_ImportModule( "ramen")))); main_namespace_[ "ramen"] = module; exec( "from ramen import *"); // execute startup files bfs::path exec_path = app().system().executable_path(); bfs::path py_path = exec_path.parent_path() / "../python"; exec_file( py_path / "app/init.py"); exec_file( app().system().home_path() / "ramen/python/init.py"); }
void exec_env(char **str, int *i, int isnew_env, char **env) { pid_t pid; if ((pid = fork()) < 0) { ft_putendl_fd("Fork fail", 2); return ; } if (!pid) { if (ft_strchr(*str, '/')) exec_file(str, isnew_env, env); else exec_bin(str, isnew_env, env); } else waitpid(pid, i, 0); }
void exec(t_pars_cmd *cmd, int type) { char **str; int i; str = NULL; i = -1; if (type && (i = builtin(cmd)) > -1) exit(i); if (!(str = ft_strsplit(cmd->cmd, ' '))) { ft_putendl_fd("42sh: an error occured code : 012", 2); exit(3); } if (ft_strchr(*str, '/')) exec_file(str, 0, NULL); else exec_bin(str, 0, NULL); ft_p_free(&str); exit(4); }
int read_pseudo_def(struct pseudo **pseudo, char *def) { int n, bytes; unsigned int major = 0, minor = 0, mode; char filename[2048], type, suid[100], sgid[100], *ptr; long long uid, gid; struct pseudo_dev *dev; n = sscanf(def, "%s %c %o %s %s %n", filename, &type, &mode, suid, sgid, &bytes); if(n < 5) { ERROR("Not enough or invalid arguments in pseudo file " "definition\n"); goto error; } switch(type) { case 'b': case 'c': n = sscanf(def + bytes, "%u %u", &major, &minor); if(n < 2) { ERROR("Not enough or invalid arguments in pseudo file " "definition\n"); goto error; } if(major > 0xfff) { ERROR("Major %d out of range\n", major); goto error; } if(minor > 0xfffff) { ERROR("Minor %d out of range\n", minor); goto error; } case 'f': if(def[bytes] == '\0') { ERROR("Not enough arguments in pseudo file " "definition\n"); goto error; } break; case 'd': case 'm': break; default: ERROR("Unsupported type %c\n", type); goto error; } if(mode > 07777) { ERROR("Mode %o out of range\n", mode); goto error; } uid = strtoll(suid, &ptr, 10); if(*ptr == '\0') { if(uid < 0 || uid > ((1LL << 32) - 1)) { ERROR("Uid %s out of range\n", suid); goto error; } } else { struct passwd *pwuid = getpwnam(suid); if(pwuid) uid = pwuid->pw_uid; else { ERROR("Uid %s invalid uid or unknown user\n", suid); goto error; } } gid = strtoll(sgid, &ptr, 10); if(*ptr == '\0') { if(gid < 0 || gid > ((1LL << 32) - 1)) { ERROR("Gid %s out of range\n", sgid); goto error; } } else { struct group *grgid = getgrnam(sgid); if(grgid) gid = grgid->gr_gid; else { ERROR("Gid %s invalid uid or unknown user\n", sgid); goto error; } } switch(type) { case 'b': mode |= S_IFBLK; break; case 'c': mode |= S_IFCHR; break; case 'd': mode |= S_IFDIR; break; case 'f': mode |= S_IFREG; break; } dev = malloc(sizeof(struct pseudo_dev)); if(dev == NULL) BAD_ERROR("Failed to create pseudo_dev\n"); dev->type = type; dev->mode = mode; dev->uid = uid; dev->gid = gid; dev->major = major; dev->minor = minor; if(type == 'f') { int res; printf("Executing dynamic pseudo file\n"); printf("\t\"%s\"\n", def); res = exec_file(def + bytes, dev); if(res == -1) { ERROR("Failed to execute dynamic pseudo file definition" " \"%s\"\n", def); return FALSE; } add_pseudo_file(dev); } *pseudo = add_pseudo(*pseudo, dev, filename, filename); return TRUE; error: ERROR("Bad pseudo file definition \"%s\"\n", def); return FALSE; }
PROCESS_THREAD(tftpd_process, ev, data) { static struct etimer t; static tftp_header *h; static int len, block, ack; static int tries; static int fd = -1; #if WITH_EXEC static char *elf_err; #endif PROCESS_BEGIN(); etimer_set(&t, CLOCK_CONF_SECOND*3); PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); setup_server(); #if WITH_EXEC elfloader_init(); #endif print_local_addresses(); while(1) { /* connection from client */ RECV_PACKET(h); len = 0; init_config(); if(h->op == uip_htons(TFTP_RRQ)) { connect_back(); PRINTF("< rrq for %s\n", h->filename); len += strlen(h->filename)+1; if(strcmp("octet", h->filename+len)) { send_error(EUNDEF, "only octet mode supported"); goto close_connection; } len += strlen(h->filename+len)+1; /* skip mode */ parse_opts(h->options+len, uip_datalen()-len-2); if(config.to_ack & OACK_ERROR) { send_error(EOPTNEG, ""); goto close_connection; } fd = cfs_open(h->filename, CFS_READ); if(fd<0) { send_error(ENOTFOUND, ""); goto close_connection; } block = 0; ack = 0; tries = TFTP_MAXTRIES; PRINTF("starting transfer...\n"); for(;;) { if(send_oack()) len = config.blksize; /* XXX hack to prevent loop exit*/ else len = send_data(fd, block+1); if(len<0) { send_error(EUNDEF, "read failed"); goto close_file; } RECV_PACKET_TIMEOUT(h,t); if(ev == PROCESS_EVENT_TIMER) { PRINTF("ack timed out, tries left: %d\n", tries); if(--tries<=0) goto close_file; continue; } if(h->op != uip_htons(TFTP_ACK)) { send_error(EBADOP, ""); goto close_file; } config.to_ack = 0; tries = TFTP_MAXTRIES; ack = uip_htons(h->block_nr); if(ack == block+1) block++; if(len < config.blksize && ack == block) goto done; } } else if(h->op == uip_htons(TFTP_WRQ)) { connect_back(); PRINTF("< wrq for %s\n", h->filename); len += strlen(h->filename)+1; strncpy(config.filename, h->filename, sizeof(config.filename)-1); if(strcmp("octet", h->filename+strlen(h->filename)+1)) { send_error(EUNDEF, "only octet mode supported"); goto close_connection; } len += strlen(h->filename+len)+1; /* skip mode */ parse_opts(h->options+len, uip_datalen()-len-2); if(config.to_ack & OACK_ERROR) { send_error(EOPTNEG, ""); goto close_connection; } cfs_remove(h->filename); fd = cfs_open(h->filename, CFS_WRITE); if(fd<0) { send_error(EACCESS, ""); goto close_connection; } block = 0; ack = 0; tries = TFTP_MAXTRIES; PRINTF("starting transfer...\n"); if(!send_oack()) send_ack(block); for(;;) { RECV_PACKET_TIMEOUT(h,t); if(ev == PROCESS_EVENT_TIMER) { PRINTF("data timed out, tries left: %d\n", tries); if(--tries<=0) goto close_file; len = config.blksize; /* XXX hack to prevent loop exit*/ goto resend_ack; } if(h->op != uip_htons(TFTP_DATA)) { send_error(EBADOP, ""); goto close_file; } config.to_ack = 0; tries = TFTP_MAXTRIES; ack = uip_htons(h->block_nr); if(ack != block+1) continue; /* else */ block++; len = recv_data(fd, block); if(len<0) { send_error(EUNDEF, "write failed"); goto close_file; } #if WITH_EXEC if(len < config.blksize) { if(config.exec) { if(exec_file(config.filename, &elf_err) != 0) { send_error(EUNDEF, elf_err); goto close_file; } } } #endif resend_ack: if(!send_oack()) send_ack(block); if(len < config.blksize) goto done; } } done: PRINTF("done.\n"); close_file: if(fd>=0) cfs_close(fd); fd = -1; close_connection: if(client_conn) uip_udp_remove(client_conn); client_conn = 0; PRINTF("connection closed.\n"); } PROCESS_END(); }
int exec_cmd(int under_glob, int under_until) { register int status; register char *p; int n; if((status = getrange()) <= ERROR) return( status ); status = ERROR9; switch( *lp++ ) { case 'i': laddr2 = prevln(laddr2); case 'a': status = append(laddr2, under_glob); break; case 'b': if(!under_glob && !under_until) status = branch(); break; case 'c': if((status = delete(laddr1, laddr2, SAVE)) == OK) status = append(prevln(laddr1), under_glob); break; case 'd': if((status = delete(laddr1, laddr2, SAVE)) == OK && nextln(curln) != 0) curln = nextln(curln); break; case 'e': if(lastln && dirty && *lp != 'e') { status = ERROR4; break; } if(*lp == 'e') ++lp; if(nladdrs == 0 && !under_glob && !under_until && (status = getfn()) == OK) { set_fn(curfile, lp); if(lastln != 0) delete(1, lastln, NOSAVE); num_delete_lines = 0; if((status = _read( lp, 0, 0)) == OK) { dirty = 0; if(lastln) curln = 1; } } lp = "\n"; break; case 'f': if(nladdrs == 0 && (status = getfn()) == OK) { set_fn(curfile, lp); putmsg(curfile); lp = "\n"; } change_state(CMD); break; case 'g': if(!under_glob) { if(*lp == '^') { ++lp; n = 0; } else n = 1; status = exec_glob(n, under_until); } break; case 'h': n = getint(); #ifndef __STDC__ while(n--) for(n1 = 0; n1 < 10; ++n1) time_slice(); #endif status = OK; break; case 'j': status = join(laddr2); break; case 'k': if((status = get_laddr_expr(&n)) == OK) status = kopy(n); break; case 'l': if(nladdrs == 0) status = learn(); break; case 'm': if((status = get_laddr_expr(&n)) == OK) status = move(n); break; case 'o': status = option(); break; case 'p': case 'P': status = prnt(laddr1, laddr2); break; case 'q': if(nladdrs==0 && !under_glob) { if((*lp=='\n' && !dirty) || *lp=='q' || lastln == 0) status = EOF; else status = ERROR4; } break; case 'r': if(!under_glob && !under_until && (status = getfn()) == OK) status = _read(lp, laddr2, 0); lp = "\n"; break; case 's': n = getint(); /* read occurance if present */ if((status=getpat()) == OK && (status=getsubst_str(tbuff)) == OK) status = substitute(tbuff, under_glob, n); break; case 't': case 'T': if(nladdrs == 0) status = translate(*(lp - 1) == 't'); break; case 'u': status = until(laddr1, laddr2, under_glob); break; case 'v': if(nladdrs <= 1) status = view(laddr1); break; case 'w': n = 0; if(*lp == 'w') { n |= 2; ++lp; } if(*lp == 'a') { n |= 1; ++lp; } if((status = getfn()) == OK) { if(nladdrs == 0) { if(curfile[0] == '\0') set_fn(curfile, lp); else { if((n & 2) == 0 && strcmp(curfile, lp) != 0) { for(p = lp ; *p ; ++p) if(*p == '$') goto ok; puterr(-19); lp = "\n"; break; } } ok: if((status = _write(lp, 1, lastln, n & 1, 0)) == OK) dirty = 0; } } else { status = _write(lp, laddr1, laddr2, n & 1, 0); } lp = "\n"; break; case 'x': if(!under_glob && !under_until && (status = getfn()) == OK) if(nladdrs == 0) status = exec_file(lp, under_glob, under_until); lp = "\n"; break; case 'y': status = yut(); break; case 'z': status = zap(); break; case '\n': --lp; /* put back newline for main */ if(laddr2 < 0 || laddr2 > lastln) status = lastln ? ERROR5 : OK; else { curln = laddr2; status = OK; } break; case ' ': case '\t': case CMD_CHAR: status = OK; break; case '=': dtoc(rbuff, laddr2); if(under_glob) prnt_screen(rbuff, 1); else putmsg(rbuff); status = OK; break; case '"': lp = "\n"; /* Ignore rest of line */ status = OK; break; case '!': if(escape_char == 0 || restrict_flag) { putmsg("Escape from ED inhibited"); status = NOTHING; } else status = exec_sys_cmd(under_glob, under_until); break; default: status = ERROR2; } return(status); }