int exec_command (const std::vector<std::string>& command) { HANDLE child_handle = spawn_command(command, NULL, NULL, NULL); int exit_code = wait_for_child(child_handle); CloseHandle(child_handle); return exit_code; }
static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out) { char * ex_cmd = NULL; size_t ex_cmdlen; int ret; /* File descriptor "-j &3" */ if (*cli_opts.proxycmd == '&') { char *p = cli_opts.proxycmd + 1; int sock = strtoul(p, &p, 10); /* must be a single number, and not stdin/stdout/stderr */ if (sock > 2 && sock < 1024 && *p == '\0') { *sock_in = sock; *sock_out = sock; return; } } /* Normal proxycommand */ /* So that spawn_command knows which shell to run */ fill_passwd(cli_opts.own_user); ex_cmdlen = strlen(cli_opts.proxycmd) + 6; /* "exec " + command + '\0' */ ex_cmd = m_malloc(ex_cmdlen); snprintf(ex_cmd, ex_cmdlen, "exec %s", cli_opts.proxycmd); ret = spawn_command(exec_proxy_cmd, ex_cmd, sock_out, sock_in, NULL, pid_out); m_free(ex_cmd); if (ret == DROPBEAR_FAILURE) { dropbear_exit("Failed running proxy command"); *sock_in = *sock_out = -1; } }
static void cli_proxy_cmd(int *sock_in, int *sock_out) { int ret; fill_passwd(cli_opts.own_user); ret = spawn_command(exec_proxy_cmd, cli_opts.proxycmd, sock_out, sock_in, NULL, NULL); if (ret == DROPBEAR_FAILURE) { dropbear_exit("Failed running proxy command"); *sock_in = *sock_out = -1; } }
void Coprocess::spawn (const std::vector<std::string>& args) { proc_handle = spawn_command(args, stdin_pipe_reader, stdout_pipe_writer, nullptr); if (stdin_pipe_reader) { CloseHandle(stdin_pipe_reader); stdin_pipe_reader = nullptr; } if (stdout_pipe_writer) { CloseHandle(stdout_pipe_writer); stdout_pipe_writer = nullptr; } }
static void spawn_service(VSTREAM *client_stream, char *service, char **argv) { const char *myname = "spawn_service"; static SPAWN_ATTR attr; WAIT_STATUS_T status; ARGV *export_env; /* * This routine runs whenever a client connects to the UNIX-domain socket * dedicated to running an external command. */ if (msg_verbose) msg_info("%s: service=%s, command=%s...", myname, service, argv[0]); /* * Look up service attributes and config information only once. This is * safe since the information comes from a trusted source. */ if (attr.argv == 0) { get_service_attr(&attr, service, argv); } /* * Execute the command. */ export_env = mail_parm_split(VAR_EXPORT_ENVIRON, var_export_environ); status = spawn_command(CA_SPAWN_CMD_STDIN(vstream_fileno(client_stream)), CA_SPAWN_CMD_STDOUT(vstream_fileno(client_stream)), CA_SPAWN_CMD_STDERR(vstream_fileno(client_stream)), CA_SPAWN_CMD_UID(attr.uid), CA_SPAWN_CMD_GID(attr.gid), CA_SPAWN_CMD_ARGV(attr.argv), CA_SPAWN_CMD_TIME_LIMIT(attr.time_limit), CA_SPAWN_CMD_EXPORT(export_env->argv), CA_SPAWN_CMD_END); argv_free(export_env); /* * Warn about unsuccessful completion. */ if (!NORMAL_EXIT_STATUS(status)) { if (WIFEXITED(status)) msg_warn("command %s exit status %d", attr.argv[0], WEXITSTATUS(status)); if (WIFSIGNALED(status)) msg_warn("command %s killed by signal %d", attr.argv[0], WTERMSIG(status)); } }
void play_wav_file(const std::string& filename) { #ifdef _WIN32 //TODO: more good solution? #if !defined(_MSC_VER) PlaySound(filename.c_str(), 0, SND_ASYNC | SND_FILENAME); #endif #elif defined(CONFIG_GNOME) gnome_sound_play(filename.c_str()); #else const std::string &playcmd= conf->get_string_at("dictionary/play_command"); spawn_command(playcmd.c_str(), filename.c_str()); #endif }
void show_url(const char *url) { if (!url) return; #ifdef _WIN32 ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->window->window)), "OPEN", url, NULL, NULL, SW_SHOWNORMAL); #elif defined(CONFIG_GNOME) gnome_url_show(url, NULL); #elif defined(CONFIG_GPE) gchar *command = g_strdup_printf("gpe-mini-browser %s", url); system(command); g_free(command); #else spawn_command("firefox", url); #endif }
int exec_command (const std::vector<std::string>& command, std::ostream& output) { HANDLE stdout_pipe_reader = NULL; HANDLE stdout_pipe_writer = NULL; SECURITY_ATTRIBUTES sec_attr; // Set the bInheritHandle flag so pipe handles are inherited. sec_attr.nLength = sizeof(SECURITY_ATTRIBUTES); sec_attr.bInheritHandle = TRUE; sec_attr.lpSecurityDescriptor = NULL; // Create a pipe for the child process's STDOUT. if (!CreatePipe(&stdout_pipe_reader, &stdout_pipe_writer, &sec_attr, 0)) { throw System_error("CreatePipe", "", GetLastError()); } // Ensure the read handle to the pipe for STDOUT is not inherited. if (!SetHandleInformation(stdout_pipe_reader, HANDLE_FLAG_INHERIT, 0)) { throw System_error("SetHandleInformation", "", GetLastError()); } HANDLE child_handle = spawn_command(command, NULL, stdout_pipe_writer, NULL); CloseHandle(stdout_pipe_writer); // Read from stdout_pipe_reader. // Note that ReadFile on a pipe may return with bytes_read==0 if the other // end of the pipe writes zero bytes, so don't break out of the read loop // when this happens. When the other end of the pipe closes, ReadFile // fails with ERROR_BROKEN_PIPE. char buffer[1024]; DWORD bytes_read; while (ReadFile(stdout_pipe_reader, buffer, sizeof(buffer), &bytes_read, NULL)) { output.write(buffer, bytes_read); } const DWORD read_error = GetLastError(); if (read_error != ERROR_BROKEN_PIPE) { throw System_error("ReadFile", "", read_error); } CloseHandle(stdout_pipe_reader); int exit_code = wait_for_child(child_handle); CloseHandle(child_handle); return exit_code; }
static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out) { char * ex_cmd = NULL; size_t ex_cmdlen; int ret; fill_passwd(cli_opts.own_user); ex_cmdlen = strlen(cli_opts.proxycmd) + 6; /* "exec " + command + '\0' */ ex_cmd = m_malloc(ex_cmdlen); snprintf(ex_cmd, ex_cmdlen, "exec %s", cli_opts.proxycmd); ret = spawn_command(exec_proxy_cmd, ex_cmd, sock_out, sock_in, NULL, pid_out); m_free(ex_cmd); if (ret == DROPBEAR_FAILURE) { dropbear_exit("Failed running proxy command"); *sock_in = *sock_out = -1; } }
static void spawn_clicked( GtkButton *button, GtkDialog *spawn_dialog ) { GtkWidget *command, *arguments; const char *cmd, *arg; int response; response = gtk_dialog_run( spawn_dialog ); gtk_widget_hide( GTK_WIDGET( spawn_dialog ) ); if( response != GTK_RESPONSE_OK ) return; command = glade_xml_get_widget( xml, "command-entry" ); arguments = glade_xml_get_widget( xml, "arguments-entry" ); cmd = gtk_entry_get_text( GTK_ENTRY( command ) ); arg = gtk_entry_get_text( GTK_ENTRY( arguments ) ); spawn_command( cmd, arg ); }
int exec_command_with_input (const std::vector<std::string>& command, const char* p, size_t len) { HANDLE stdin_pipe_reader = NULL; HANDLE stdin_pipe_writer = NULL; SECURITY_ATTRIBUTES sec_attr; // Set the bInheritHandle flag so pipe handles are inherited. sec_attr.nLength = sizeof(SECURITY_ATTRIBUTES); sec_attr.bInheritHandle = TRUE; sec_attr.lpSecurityDescriptor = NULL; // Create a pipe for the child process's STDIN. if (!CreatePipe(&stdin_pipe_reader, &stdin_pipe_writer, &sec_attr, 0)) { throw System_error("CreatePipe", "", GetLastError()); } // Ensure the write handle to the pipe for STDIN is not inherited. if (!SetHandleInformation(stdin_pipe_writer, HANDLE_FLAG_INHERIT, 0)) { throw System_error("SetHandleInformation", "", GetLastError()); } HANDLE child_handle = spawn_command(command, stdin_pipe_reader, NULL, NULL); CloseHandle(stdin_pipe_reader); // Write to stdin_pipe_writer. while (len > 0) { DWORD bytes_written; if (!WriteFile(stdin_pipe_writer, p, len, &bytes_written, NULL)) { throw System_error("WriteFile", "", GetLastError()); } p += bytes_written; len -= bytes_written; } CloseHandle(stdin_pipe_writer); int exit_code = wait_for_child(child_handle); CloseHandle(child_handle); return exit_code; }
void w_assess_trigger(w_root_t *root, struct watchman_trigger_command *cmd) { w_query_res res; struct w_clockspec *since_spec = cmd->query->since_spec; if (since_spec && since_spec->tag == w_cs_clock) { w_log(W_LOG_DBG, "running trigger rules! since %" PRIu32 "\n", since_spec->clock.ticks); } else { w_log(W_LOG_DBG, "running trigger rules!\n"); } // Triggers never need to sync explicitly; we are only dispatched // at settle points which are by definition sync'd to the present time cmd->query->sync_timeout = 0; if (!w_query_execute(cmd->query, root, &res, trigger_generator, cmd)) { w_log(W_LOG_ERR, "error running trigger query: %s", res.errmsg); w_query_result_free(&res); return; } w_log(W_LOG_DBG, "trigger generated %" PRIu32 " results\n", res.num_results); // create a new spec that will be used the next time cmd->query->since_spec = w_clockspec_new_clock(res.root_number, res.ticks); if (res.num_results) { spawn_command(root, cmd, &res, since_spec); } if (since_spec) { w_clockspec_free(since_spec); since_spec = NULL; } w_query_result_free(&res); }
int main(int argc, char *argv[]) { char *wmiirc; WMScreen *s; WinAttr wa; int i; fmtinstall('r', errfmt); fmtinstall('C', Cfmt); wmiirc = "wmiistartrc"; ARGBEGIN{ case 'v': print("%s", version); exit(0); case 'V': verbose = True; break; case 'a': address = EARGF(usage()); break; case 'r': wmiirc = EARGF(usage()); break; default: usage(); break; }ARGEND; if(argc) usage(); setlocale(LC_CTYPE, ""); starting = True; initdisplay(); xlib_errorhandler = XSetErrorHandler(errorhandler); check_other_wm = True; XSelectInput(display, scr.root.w, SubstructureRedirectMask | EnterWindowMask); XSync(display, False); check_other_wm = False; passwd = getpwuid(getuid()); user = estrdup(passwd->pw_name); init_environment(); sock = ixp_announce(address); if(sock < 0) fatal("Can't create socket '%s': %r", address); if(wmiirc) spawn_command(wmiirc); init_traps(); init_atoms(); init_cursors(); init_lock_keys(); srv.preselect = check_preselect; ixp_listen(&srv, sock, &p9srv, serve_9pcon, nil); ixp_listen(&srv, ConnectionNumber(display), nil, check_x_event, closedisplay); def.font = loadfont(FONT); def.border = 1; def.colmode = Coldefault; def.mod = Mod1Mask; strcpy(def.grabmod, "Mod1"); loadcolor(&def.focuscolor, FOCUSCOLORS); loadcolor(&def.normcolor, NORMCOLORS); num_screens = 1; screens = emallocz(num_screens * sizeof(*screens)); screen = &screens[0]; for(i = 0; i < num_screens; i++) { s = &screens[i]; init_screen(s); s->ibuf = allocimage(Dx(s->r), Dy(s->r), scr.depth); wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask; wa.cursor = cursor[CurNormal]; setwinattr(&scr.root, &wa, CWEventMask | CWCursor); initbar(s); } screen->focus = nil; setfocus(screen->barwin, RevertToParent); scan_wins(); starting = False; select_view("nil"); update_views(); write_event("FocusTag %s\n", screen->sel->name); check_x_event(nil); i = ixp_serverloop(&srv); if(i) fprint(2, "%s: error: %r\n", argv0); cleanup(); if(exitsignal) raise(exitsignal); if(execstr) execl("/bin/sh", "sh", "-c", execstr, nil); return i; }
static int os_spawn(lua_State * L) { int allow = 0; const char *maincmd = NULL; char *runcmd = NULL; char *safecmd = NULL, *cmdname = NULL; char **cmdline = NULL; char **envblock = NULL; int i; if (lua_gettop(L) != 1) { lua_pushnil(L); lua_pushliteral(L, "invalid arguments passed"); return 2; } if (shellenabledp <= 0) { lua_pushnil(L); lua_pushliteral(L, "All command execution disabled."); return 2; } if (lua_type(L, 1) == LUA_TSTRING) { maincmd = lua_tostring(L, 1); cmdline = do_split_command(maincmd, &runcmd); } else if (lua_type(L, 1) == LUA_TTABLE) { cmdline = do_flatten_command(L, &runcmd); } /* If restrictedshell == 0, any command is allowed. */ /* this is a little different from \write18/ os.execute processing * because it does not test for commands with fixed arguments, * but I am not so eager to attempt to fix that. Just document * that os.exec() checks only the command name. */ if (restrictedshell == 0) { allow = 1; } else { const char *theruncmd = runcmd; allow = shell_cmd_is_allowed(theruncmd, &safecmd, &cmdname); } if (allow > 0 && cmdline != NULL && runcmd != NULL) { if (allow == 2) i = spawn_command(safecmd, cmdline, envblock); else i = spawn_command(runcmd, cmdline, envblock); if (safecmd) free(safecmd); if (cmdname) free(cmdname); if (i == 0) { lua_pushinteger(L, i); return 1; } else if (i == -1) { /* this branch covers WIN32 as well as fork() and waitpid() errors */ do_error_return(strerror(errno), errno); #ifndef _WIN32 } else if (i == INVALID_RET_E2BIG) { do_error_return(strerror(E2BIG), i); } else if (i == INVALID_RET_ENOENT) { do_error_return(strerror(ENOENT), i); } else if (i == INVALID_RET_ENOEXEC) { do_error_return(strerror(ENOEXEC), i); } else if (i == INVALID_RET_ENOMEM) { do_error_return(strerror(ENOMEM), i); } else if (i == INVALID_RET_ETXTBSY) { do_error_return(strerror(ETXTBSY), i); } else if (i == INVALID_RET_UNKNOWN) { do_error_return("execution failed", i); } else if (i == INVALID_RET_INTR) { do_error_return("execution interrupted", i); #endif } else { lua_pushinteger(L, i); return 1; } } if (safecmd) free(safecmd); if (cmdname) free(cmdname); if (allow == 0) { lua_pushnil(L); lua_pushliteral(L, "Command execution disabled via shell_escape='p'"); return 2; } lua_pushnil(L); lua_pushliteral(L, "invalid command line passed"); return 2; }
bool watchman_trigger_command::maybeSpawn( const std::shared_ptr<w_root_t>& root) { bool didRun = false; // If it looks like we're in a repo undergoing a rebase or // other similar operation, we want to defer triggers until // things settle down if (root->inner.view->isVCSOperationInProgress()) { w_log(W_LOG_DBG, "deferring triggers until VCS operations complete\n"); return false; } w_query_res res; auto since_spec = query->since_spec.get(); if (since_spec && since_spec->tag == w_cs_clock) { w_log( W_LOG_DBG, "running trigger \"%s\" rules! since %" PRIu32 "\n", triggername.c_str(), since_spec->clock.position.ticks); } else { w_log(W_LOG_DBG, "running trigger \"%s\" rules!\n", triggername.c_str()); } // Triggers never need to sync explicitly; we are only dispatched // at settle points which are by definition sync'd to the present time query->sync_timeout = std::chrono::milliseconds(0); watchman::log(watchman::DBG, "assessing trigger ", triggername, "\n"); if (!w_query_execute_locked(query.get(), root, &res, time_generator)) { watchman::log( watchman::ERR, "error running trigger \"", triggername, "\" query: ", res.errmsg, "\n"); return false; } watchman::log( watchman::DBG, "trigger \"", triggername, "\" generated ", res.resultsArray.array().size(), " results\n"); // create a new spec that will be used the next time auto saved_spec = std::move(query->since_spec); query->since_spec = watchman::make_unique<w_clockspec>(res.clockAtStartOfQuery); watchman::log( watchman::DBG, "updating trigger \"", triggername, "\" use ", res.clockAtStartOfQuery.ticks, " ticks next time\n"); if (!res.resultsArray.array().empty()) { didRun = true; spawn_command(root, this, &res, saved_spec.get()); } return didRun; }
main(int argc, char *argv[]) /* MAIN Purpose : 1 Get privilege mask 2 Setup SMG environment unless no VT or DFU$NOSMG is set 3 Get and Parse command (syntax only) 4 Dispatch to correct subroutine Inputs : Command line (if specified through foreign command) Outputs : returns last status code to DCL in case of single command processing. In interactive mode always returns SS$_NORMAL. */ { const rms_eof=98938,smg$_eof=1213442; struct { short status, count; int extra ; } iosb; static char command_line[255], *e; unsigned int out_len,ret_len,prvmask; void reset_ctrl(), clean_ctrlc(), prev_screen(), next_screen(), dump_screen(), toggle_width() ; int smg_flag, x, y, i, ttype; int cursor_on = SMG$M_CURSOR_ON; $DESCRIPTOR(input_line , command_line); $DESCRIPTOR(prompt,"DFU> "); $DESCRIPTOR(terminal,"SYS$COMMAND"); $DESCRIPTOR(top_txt,"< DFU V2.2 (Freeware) >"); $DESCRIPTOR(status_txt,"Statistics"); $DESCRIPTOR(do_key,"DO"); $DESCRIPTOR(pf2,"PF2"); $DESCRIPTOR(pf4,"PF4"); $DESCRIPTOR(prev,"PREV_SCREEN"); $DESCRIPTOR(next,"NEXT_SCREEN"); $DESCRIPTOR(select,"SELECT"); $DESCRIPTOR(help,"HELP"); /* First find out how we got called ( by RUN, or a foreign command */ ret_len = 0; #if 0 status = lib$get_foreign(&input_line,0,&ret_len,0); #else status = 1; #if 0 strcpy(command_line,argv[1]); #endif #endif out_len = ret_len; smg$enable = TRUE; key_tab = 0; disp2_id = 0; cip = 0; setvbuf(stdout, NULL, _IONBF, 0); // need this to see i/o at all #if 0 smg$enable = FALSE; vms_mm = check_vms_mm(); #else /* Now create the SMG environment */ colls=80; rows=24; SMG$CREATE_PASTEBOARD(&paste_id, 0, &rows, &colls,&SMG$M_KEEP_CONTENTS,&ttype,0); if ((e = (char *) getenv("DFU$NOSMG")) && *e) smg$enable = FALSE; else { if (ttype != SMG$K_VTTERMTABLE) smg$enable = FALSE; if (ttype != SMG$K_VTTERMTABLE) SMG$DELETE_PASTEBOARD(&paste_id,&i0); } SMG$CREATE_VIRTUAL_KEYBOARD(&keyb_id,0,0,0,0); if (smg$enable) /* Setup key table */ { SMG$ERASE_PASTEBOARD(&paste_id, 0, 0, 0, 0, 0, 0); SMG$CREATE_KEY_TABLE(&key_tab); colls -=2; orig_colls = colls; smg_flag = SMG$M_KEY_NOECHO + SMG$M_KEY_TERMINATE; SMG$ADD_KEY_DEF(&key_tab,&do_key,0, &smg_flag, &do_key,0); SMG$ADD_KEY_DEF(&key_tab,&pf4,0, &smg_flag,&pf4,0); SMG$ADD_KEY_DEF(&key_tab,&prev,0, &smg_flag, &prev,0); SMG$ADD_KEY_DEF(&key_tab,&next,0, &smg_flag, &next,0); SMG$ADD_KEY_DEF(&key_tab,&pf2,0, &smg_flag, &help,0); SMG$ADD_KEY_DEF(&key_tab,&help,0, &smg_flag, &help,0); SMG$ADD_KEY_DEF(&key_tab,&select,0, &smg_flag, &select,0); SMG$CREATE_VIRTUAL_DISPLAY(&i500, &colls , &disp1_id, &SMG$M_BORDER, 0, 0); x = 508 - rows; y = rows - 7; SMG$CREATE_VIEWPORT(&disp1_id,&x,&i1,&y,&colls); SMG$CREATE_VIRTUAL_DISPLAY(&i2, &colls, &status_id, 0 , 0, 0); SMG$CREATE_VIRTUAL_DISPLAY(&i2, &colls, &disp2_id, 0 , 0, 0); SMG$SET_BROADCAST_TRAPPING(&paste_id,brdcst_ast,0); SMG$LABEL_BORDER(&disp1_id, &top_txt, 0, 0,&SMG$M_BOLD, 0, 0); SMG$LABEL_BORDER(&status_id, &status_txt, 0, 0,&SMG$M_BOLD, 0, 0); SMG$PASTE_VIRTUAL_DISPLAY(&disp1_id, &paste_id, &i2,&i2,0); x = rows - 4; SMG$PASTE_VIRTUAL_DISPLAY(&status_id, &paste_id, &x,&i2,0); x = rows - 1; SMG$PASTE_VIRTUAL_DISPLAY(&disp2_id, &paste_id, &x,&i2,0); x = 508 - rows; SMG$SET_CURSOR_ABS(&disp1_id,&x,&i1); SMG$SET_CURSOR_ABS(&disp2_id,&i1,&i1); SMG$BEGIN_PASTEBOARD_UPDATE(&paste_id); } #endif sprintf(outbuf,"\n Disk and File Utilities for OpenVMS DFU V2.2"); put_disp(); sprintf(outbuf," Freeware version"); put_disp(); sprintf(outbuf," Copyright © 1995 Digital Equipment Corporation\n"); put_disp(); if (smg$enable) { /* Enter additional info */ sprintf(outbuf," DFU functions are : \n"); put_disp(); sprintf(outbuf," DEFRAGMENT : Defragment files"); put_disp(); sprintf(outbuf," DELETE : Delete files by File-ID; delete directory (trees)"); put_disp(); sprintf(outbuf," DIRECTORY : Manipulate directories"); put_disp(); sprintf(outbuf," REPORT : Generate a complete disk report"); put_disp(); sprintf(outbuf," SEARCH : Fast file search"); put_disp(); sprintf(outbuf," SET : Modify file attributes"); put_disp(); sprintf(outbuf," UNDELETE : Recover deleted files"); put_disp(); sprintf(outbuf," VERIFY : Check and repair disk structure"); put_disp(); SMG$END_PASTEBOARD_UPDATE(&paste_id); } prvmask = 0; status = dfu_check_access(&prvmask); /*Get the privilege mask */ /* Setup terminal channel for control purposes; get the terminal chars */ status = SYS$ASSIGN(&terminal, &tchan, 0,0); status = SYS$QIOW(0,tchan, IO$_SENSEMODE,0,0,0,&orgttchar,12,0,0,0,0); for (i = 0; i < 3; i++) ttchar[i] = orgttchar[i]; ttchar[2] &= ~TT2$M_EDITING; /* Clear line edit bit */ clean_ctrlc(); /* Enable CTRL/W if needed */ if (ret_len==0) { if (smg$enable) status = SMG$READ_COMPOSED_LINE(&keyb_id,&key_tab,&input_line,&prompt, &out_len,&disp2_id,0,0,0,0,0); else status = SMG$READ_COMPOSED_LINE(&keyb_id,0,&input_line,&prompt, &out_len,0,0,0,0,0,0); } memcpy (command_line, input_line.dsc$a_pointer, input_line.dsc$w_length); cip = 1; /* Main loop starts here. Get a command and pasre it*/ for (;;) { /* loop forever until EXIT is entered */ if(status==smg$_eof) status = exit_command(prvmask); if ((status&1) != 1) goto endfor; if (out_len == 0) goto endfor; /* First catch special screen commands */ if (smg$enable) { status = strncmp(command_line, "PREV_SCREEN", 11); if (status == 0) { prev_screen(); goto endfor; } status = strncmp(command_line, "DO",2); if (status == 0) { status = spawn_command(prvmask); goto endfor; } status = strncmp(command_line, "PF4",3); if (status == 0) { dump_screen(); goto endfor; } status = strncmp(command_line, "NEXT_SCREEN", 11); if (status == 0) { next_screen(); goto endfor; } status = strncmp(command_line, "SELECT", 6); if (status == 0) { toggle_width(); goto endfor; } SMG$ERASE_DISPLAY(&disp1_id, 0, 0, 0, 0); SMG$ERASE_DISPLAY(&status_id, 0, 0, 0, 0); SMG$CHANGE_VIEWPORT(&disp1_id,&x,&i1,&y,&colls); SMG$SET_CURSOR_ABS(&disp1_id,&x,&i1); } /* Catch the CLI errors do avoid disrupting the SMG screen... */ #if 0 VAXC$ESTABLISH(prim_hand); #endif status = CLI$DCL_PARSE(&input_line,&dfu_tables,0 /* not yet lib$get_input*/,0,&prompt); // check added & before dfu_tables #if 0 VAXC$ESTABLISH(NULL); #endif if (status == CLI$_NOCOMD) singlemsg(0,status); if ((status & 1 ) != 1) goto endfor; else /* Now dispatch if no errors */ { reset_ctrl(); CLI$DISPATCH(prvmask); clean_ctrlc(); cip = 0; status = brdcst_ast(); if (smg$enable) SMG$SET_CURSOR_MODE(&paste_id, &cursor_on); } endfor: if (ret_len !=0) { /* Single command processing , so exit here */ status += 0x10000000; /* Do not echo the error on DCL level */ if (smg$enable) { if (colls != orig_colls) toggle_width(); SMG$SET_CURSOR_ABS(&disp2_id,&i2,&i1); } exit(status); } /* Get next line */ cip = 0; #if 1 if (smg$enable) { SMG$ERASE_LINE(&disp2_id, &i1, &i1); SMG$SET_CURSOR_ABS(&disp2_id,&i1,&i1); status = SMG$READ_COMPOSED_LINE(&keyb_id,&key_tab,&input_line, &prompt,&out_len,&disp2_id,0,0,0,0,0); /*Get next command */ cip = 1; } else status = SMG$READ_COMPOSED_LINE(&keyb_id,0,&input_line, &prompt,&out_len,0,0,0,0,0,0); /*Get next command */ #else printf("%s",prompt.dsc$a_pointer); out_len = read(0,command_line,254); out_len--; command_line[out_len]=0; if (strncmp(command_line,"exit",4)==0) return 0; #endif } } /* END of MAIN */
int main(int argc, char *argv[]) { IxpMsg m; char **oargv; char *wmiirc, *s; int i; quotefmtinstall(); fmtinstall('r', errfmt); fmtinstall('a', afmt); fmtinstall('C', Cfmt); extern int fmtevent(Fmt*); fmtinstall('E', fmtevent); wmiirc = "wmiirc"; oargv = argv; ARGBEGIN{ case 'a': address = EARGF(usage()); break; case 'r': wmiirc = EARGF(usage()); break; case 'v': print("%s", version); exit(0); case 'D': s = EARGF(usage()); m = ixp_message(s, strlen(s), 0); msg_debug(&m); break; default: usage(); break; }ARGEND; if(argc) usage(); setlocale(LC_CTYPE, ""); starting = true; initdisplay(); traperrors(true); selectinput(&scr.root, EnterWindowMask | SubstructureRedirectMask); if(traperrors(false)) fatal("another window manager is already running"); passwd = getpwuid(getuid()); user = estrdup(passwd->pw_name); init_environment(); fmtinstall('F', Ffmt); ixp_printfcall = printfcall; sock = ixp_announce(address); if(sock < 0) fatal("Can't create socket '%s': %r", address); closeexec(ConnectionNumber(display)); closeexec(sock); if(wmiirc[0]) spawn_command(wmiirc); init_traps(); init_cursors(); init_lock_keys(); ewmh_init(); xext_init(); srv.preselect = check_preselect; ixp_listen(&srv, sock, &p9srv, serve_9pcon, nil); ixp_listen(&srv, ConnectionNumber(display), nil, check_x_event, closedisplay); def.border = 1; def.colmode = Colstack; def.font = loadfont(FONT); def.incmode = ISqueeze; def.mod = Mod1Mask; strcpy(def.grabmod, "Mod1"); loadcolor(&def.focuscolor, FOCUSCOLORS); loadcolor(&def.normcolor, NORMCOLORS); disp.sel = pointerscreen(); init_screens(); root_init(); disp.focus = nil; setfocus(screen->barwin, RevertToParent); view_select("1"); scan_wins(); starting = false; view_update_all(); ewmh_updateviews(); event("FocusTag %s\n", selview->name); i = ixp_serverloop(&srv); if(i) fprint(2, "%s: error: %r\n", argv0); else event("Quit"); cleanup(); if(exitsignal) raise(exitsignal); if(execstr) { char *toks[32]; int n; n = unquote(strdup(execstr), toks, nelem(toks)-1); toks[n] = nil; execvp(toks[0], toks); fprint(2, "%s: failed to exec %q: %r\n", argv0, execstr); execvp(argv0, oargv); fatal("failed to exec myself"); } return i; }