/* Upgrade support */ int md_update(void) { const char *mntdir = "/mnt2"; char bootpath[MAXPATHLEN]; struct stat sb; bool hasboot = false; /* * Check if there is a boot UFS parttion and it has the old bootloader. * We'll update bootloader only if the old one was installed. */ if (!run_program(RUN_SILENT | RUN_ERROR_OK, "mount -r /dev/%s%c %s", pm->diskdev, 'a' + PART_BOOT, mntdir)) { mnt2_mounted = 1; snprintf(bootpath, sizeof(bootpath), "%s/%s", mntdir, "boot"); if (stat(bootpath, &sb) == 0 && S_ISREG(sb.st_mode)) hasboot = true; run_program(RUN_SILENT | RUN_ERROR_OK, "umount %s", mntdir); mnt2_mounted = 0; if (hasboot) (void)copy_bootloader(); } return 1; }
/************************************************************************* * Open a read-only pipe using a given command line. *************************************************************************/ FILE* open_command_pipe (char* program, // The program to run in the pipe. char* directory, // Directory to look in. char* test_arguments, // Arguments used when searching for program. char* expected_reply, // Expected reply from search. char* real_arguments, // Arguments used when running the program. BOOLEAN_T stdout_on_error, // If command fails, return STDOUT? char* error_message) // Error or warning if command fails. { FILE* return_value; // Try to run the command with no directory specified. if (try_to_run(program, "", test_arguments, expected_reply)) { return_value = run_program(program, "", real_arguments, "w"); } // Try to run the program in the specified directory. else if (try_to_run(program, directory, test_arguments, expected_reply)) { return_value = run_program(program, directory, real_arguments, "w"); } else { // If we failed, print the error message. fprintf(stderr, "%s", error_message); if (stdout_on_error) { return_value = stdout; } else { exit(1); } } return(return_value); }
int main( int argc, char * argv[] ) { insert_natives(); if( argc == 1 ) { interactive(); return 0; } if( argc == 2 ) { if( strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 ) { std::cout << "Usage: " << argv[0] << " [-l | -p | -s | -r] <filename>\n" "\n" "This program will analyse the program specified in the last argument.\n" " -l, --lexer Do lexical analysis on the program.\n" " -p, --parser Do syntactic analysis on the program.\n" " -s, --semantic Do semantical analysis on the program.\n" " -r, --run Run the program. This is the default.\n" " -h, --help Display this help and quit.\n" "If no argument is provided, run in interactive mode.\n"; return 0; } run_program( argv[1] ); return 0; } if( argc != 3 ) { std::cout << "Usage: " << argv[0] << " [-l | -p | -s | -r] <filename>\n"; return 1; } const char * filename = argv[2]; if( strcmp(argv[1], "-l" ) == 0 || strcmp(argv[1], "--lexer") == 0 ) { lexical_analysis( filename ); return 0; } if( strcmp(argv[1], "-p" ) == 0 || strcmp(argv[1], "--parser") == 0 ) { syntactic_analysis( filename ); return 0; } if( strcmp(argv[1], "-s" ) == 0 || strcmp(argv[1], "--semantic") == 0 ) { semantic_analysis( filename ); return 0; } if( strcmp(argv[1], "-r" ) == 0 || strcmp(argv[1], "--run") == 0 ) { run_program( filename ); return 0; } std::cerr << "Unknown option " << argv[1] << '\n'; return 1; }
// Launch a project (science) graphics application // int CScreensaver::launch_screensaver(RESULT* rp, GFXAPP_ID& graphics_application) { int retval = 0; if (strlen(rp->graphics_exec_path)) { // V6 Graphics #ifdef __APPLE__ // For sandbox security, use gfx_switcher to launch gfx app // as user boinc_project and group boinc_project. // // For unknown reasons, the graphics application exits with // "RegisterProcess failed (error = -50)" unless we pass its // full path twice in the argument list to execv. char* argv[5]; argv[0] = "gfx_Switcher"; argv[1] = "-launch_gfx"; argv[2] = strrchr(rp->slot_path, '/'); if (*argv[2]) argv[2]++; // Point to the slot number in ascii argv[3] = "--fullscreen"; argv[4] = 0; retval = run_program( rp->slot_path, m_gfx_Switcher_Path, 4, argv, 0, graphics_application ); if (graphics_application) { launchedGfxApp(rp->graphics_exec_path, graphics_application, rp->slot); } #else char* argv[3]; argv[0] = rp->graphics_exec_path; argv[1] = "--fullscreen"; argv[2] = 0; retval = run_program( rp->slot_path, rp->graphics_exec_path, 2, argv, 0, graphics_application ); #endif } return retval; }
ssize_t fsl_dcm_sysfs_info(struct device *dev, struct device_attribute *attr, char *buf) { struct fsl_dcm_data *dcm = dev_get_drvdata(dev); struct om_info info; ssize_t len; if (!is_sram_available(dcm)) { dev_err(dev, "dcm is busy\n"); return 0; } if (!run_program(dcm, 0, 3, OM_INFO, DATA_ADDR, OM_END)) { dev_err(dev, "could not run 'info' program\n"); return 0; } if (!copy_from_sram(dcm, DATA_ADDR, &info, sizeof(info))) { dev_err(dev, "could not copy 'info' data\n"); return 0; } len = sprintf(buf, "DCM Version: %u\n", info.version); len += sprintf(buf + len, "Prescale: %u\n", info.prescale); len += sprintf(buf + len, "Timer: %u\n", info.timer); len += sprintf(buf + len, "Number of CRECORDs: %u\n", info.count); len += sprintf(buf + len, "CRECORD Address: %u\n", info.address); return len; }
/* * Tells the DCM to stop data collection. Collected data is copied from * SRAM into a local buffer. */ int stop_data_collection(struct fsl_dcm_data *dcm) { if (!dcm->running) { dev_dbg(dcm->dev, "dcm is already stopped\n"); return 1; } if (!is_sram_available(dcm)) { dev_err(dcm->dev, "dcm is busy\n"); return 0; } if (!run_program(dcm, 0, 4, OM_STOP, OM_GET, DATA_ADDR, OM_END)) { dev_err(dcm->dev, "could not stop monitoring\n"); return 0; } if (!copy_from_sram(dcm, DATA_ADDR, dcm->rec, dcm->board->num * sizeof(struct crecord))) { dev_err(dcm->dev, "could not copy sensor data\n"); return 0; } dcm->running = 0; return 1; }
static int merge_entry(int pos, const char *path) { int found; if (pos >= active_nr) die("git merge-index: %s not in the cache", path); arguments[0] = pgm; arguments[1] = ""; arguments[2] = ""; arguments[3] = ""; arguments[4] = path; arguments[5] = ""; arguments[6] = ""; arguments[7] = ""; arguments[8] = NULL; found = 0; do { static char hexbuf[4][60]; static char ownbuf[4][60]; struct cache_entry *ce = active_cache[pos]; int stage = ce_stage(ce); if (strcmp(ce->name, path)) break; found++; strcpy(hexbuf[stage], sha1_to_hex(ce->sha1)); sprintf(ownbuf[stage], "%o", ce->ce_mode); arguments[stage] = hexbuf[stage]; arguments[stage + 4] = ownbuf[stage]; } while (++pos < active_nr); if (!found) die("git merge-index: %s not in the cache", path); run_program(); return found; }
void md_cleanup_install(void) { #ifndef DEBUG int new_speed; enable_rc_conf(); /* * Set the console speed in /etc/ttys depending on the board. * The default speed is 115200, which is patched when needed. */ if (strcmp(prodname, "kurobox") == 0) new_speed = 57600; /* KuroBox */ else if (strcmp(prodname, "dlink") == 0 || /* D-Link DSM-G600 */ strcmp(prodname, "nhnas") == 0) /* NH23x, All6250 */ new_speed = 9600; else new_speed = 0; if (new_speed != 0) { run_program(RUN_CHROOT, "sed -an -e 's/115200/%d/;H;$!d;g;w" "/etc/ttys' /etc/ttys", new_speed); } #endif }
/* Run the program PROG with the single argument ARG */ void run1(struct netcf *ncf, const char *prog, const char *arg) { const char *const argv[] = { prog, arg, NULL }; run_program(ncf, argv, NULL); }
/* run_program_block - Run a program according to an argument vector, blocking until * return * Arguments: * char **argv - argumentvector as usual, first element is the path to the * program to be executed * Returns: * int - exit status of program run. Negative returns are errors, positive * are return values of program */ int run_program_block(char **argv) { int retval, status, pid; s_time start, end; time_t run_time; retval = gettimeofday(&start, NULL); pid = run_program(argv, 0); /* Check retval after forking as not to skew results */ if (retval == -1) fprintf(stderr, "Could not get time of day\n"); /* Wait until child has exited */ do waitpid(pid, &status, 0); while (!WIFEXITED(status) && !WIFSIGNALED(status)); retval = gettimeofday(&end, NULL); if (retval == -1) fprintf(stderr, "Could not get time of day\n"); /* Calculate elapsed time in milliseconds */ run_time = end.tv_sec*1e6+end.tv_usec - start.tv_sec*1e6 + start.tv_usec; run_time /= 1e3; printf("#[STAT]# Pid %d stopped executing after %li ms\n", pid, run_time); return 255 == WEXITSTATUS(status) ? INVALIDARGS : WEXITSTATUS(status); }
int main(int argc, char **argv) { // Check if at least a program and some final states were given if (argc < 3) { usage(argv[0]); exit(0); } char *tape = NULL; unsigned int tape_length = 4096; unsigned int position = 0; int state = 0; struct state_list final_states; struct rule_list rules; // Set to user-defined length if enough parameters given if (argc > 3) tape_length = set_tape_length(argv[3]); // Set to user-defined initial state if enough parameters given if (argc > 4) state = set_state(argv[4]); // Set to user-defined tape data if enough parameters given or initialize the tape empty if (argc > 5) init_data_tape(&tape,tape_length,argv[5]); else init_empty_tape(&tape,tape_length); load_program(argv[1],&rules); set_final_states(&final_states,argv[2]); run_program(tape,position,tape_length,state,&final_states,&rules); if (argc > 6) save_tape(tape,tape_length,argv[6]); return 0; }
int shell (int argc, char *argv[]) { char *s = malloc(INPUT_STRING_SIZE+1); /* user input string */ tok_t *t; /* tokens parsed from input */ int lineNum = 0; int fundex = -1; pid_t pid = getpid(); /* get current processes PID */ pid_t ppid = getppid(); /* get parents PID */ // pid_t cpid, tcpid, cpgid; init_shell(); printf("%s running as PID %d under %d\n",argv[0],pid,ppid); lineNum=0; char *cwd = getcwd(NULL, 0); fprintf(stdout, "%d [%s]:", lineNum, cwd); free(cwd); while ((s = freadln(stdin))){ // printf("%s\n", s); char *s_copy; asprintf(&s_copy, "%s", s); t = getToks(s); /* break the line into tokens */ fundex = lookup(t[0]); /* Is first token a shell literal */ if(fundex >= 0) cmd_table[fundex].fun(&t[1]); else { run_program(t, s_copy); } ++lineNum; cwd = getcwd(NULL, 0); fprintf(stdout, "%d [%s]:", lineNum, cwd); free(cwd); } return 0; }
static void open_shell(void) { const char *shell; struct passwd *pw; #ifdef __linux__ const char *sys = rc_sys(); /* VSERVER and OPENVZ systems cannot really drop to shells */ if (sys && (strcmp(sys, "VSERVER") == 0 || strcmp(sys, "OPENVZ") == 0)) { execl("/sbin/halt", "/sbin/halt", "-f", (char *) NULL); eerrorx("%s: unable to exec `/sbin/halt': %s", applet, strerror(errno)); } #endif shell = rc_conf_value("rc_shell"); /* No shell set, so obey env, then passwd, then default to /bin/sh */ if (shell == NULL) { shell = getenv("SHELL"); if (shell == NULL) { pw = getpwuid(getuid()); if (pw) shell = pw->pw_shell; if (shell == NULL) shell = "/bin/sh"; } } run_program(shell); }
int qmain(int argc, char* argv[]){ // char in[80]; // int answer; char *p_buf; // char *t; if(argc!=2) { printf("usage: run <filename>\n"); exit(1); } /* allocate memory for the program */ if(!(p_buf=(char *) malloc(PROG_SIZE))) { printf("allocation failure"); exit(1); } /* load the program to execute */ if(!load_program(p_buf,argv[1])) exit(1); // serror can return here and die if(setjmp(e_buf)) exit(1); /* initialize the long jump buffer */ init_namespace(); run_program(p_buf);// THIS RUNS THE PROGRAM /* run_program("print \"THIS IS END\"\n");// THIS RUNS THE PROGRAM run_program("print 1+2+3+4+5");// THIS RUNS THE PROGRAM run_program("print 1.01+2.02+3.03+4.04+5.05");// THIS RUNS THE PROGRAM run_program("print \"THIS IS END\"\n");// THIS RUNS THE PROGRAM */ return 0; }//MAIN-------------------------------
/** * Execute the current fragment program for all the fragments * in the given span. */ void _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span ) { const struct gl_fragment_program *program = ctx->FragmentProgram._Current; /* incoming colors should be floats */ if (program->Base.InputsRead & FRAG_BIT_COL0) { ASSERT(span->array->ChanType == GL_FLOAT); } ctx->_CurrentProgram = GL_FRAGMENT_PROGRAM_ARB; /* or NV, doesn't matter */ run_program(ctx, span, 0, span->end); if (program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR)) { span->interpMask &= ~SPAN_RGBA; span->arrayMask |= SPAN_RGBA; } if (program->Base.OutputsWritten & (1 << FRAG_RESULT_DEPR)) { span->interpMask &= ~SPAN_Z; span->arrayMask |= SPAN_Z; } ctx->_CurrentProgram = 0; }
int main(int argc, char** args) { FILE* instruction_file = fopen(args[1], "r"); char** instructions = NULL; int lines = get_instructions(instruction_file, &instructions); fclose(instruction_file); var** input_variables = NULL; int num_input_variables = get_input_variables(instructions, lines, &input_variables); var** temp_variables = NULL; int num_temp_variables = get_temporary_variables(instructions, lines, &temp_variables); var** output_variables = NULL; int num_output_variables = get_output_variables(instructions, lines, &output_variables); FILE* value_file = fopen(args[2], "r"); char* string = (char *) malloc(256 * sizeof(char *)); while (fscanf(value_file, "%[^\n]\n", string) == 1) { int i; for (i = 0; i < num_input_variables; i++) { input_variables[i] -> value = string[i*2] - '0'; } run_program(instructions, lines, input_variables, num_input_variables, temp_variables, num_temp_variables, output_variables, num_output_variables ); } return 0; }
int get_via_nfs(void) { struct statvfs sb; if (do_config_network() != 0) return SET_RETRY; /* If root is on NFS and we have sets, skip this step. */ if (statvfs(set_dir_bin, &sb) == 0 && strcmp(sb.f_fstypename, "nfs") == 0) { strlcpy(ext_dir_bin, set_dir_bin, sizeof ext_dir_bin); strlcpy(ext_dir_src, set_dir_src, sizeof ext_dir_src); return SET_OK; } /* Get server and filepath */ process_menu(MENU_nfssource, NULL); /* Mount it */ if (run_program(0, "/sbin/mount -r -o -2,-i,-r=1024 -t nfs %s:%s /mnt2", nfs_host, nfs_dir)) return SET_RETRY; mnt2_mounted = 1; snprintf(ext_dir_bin, sizeof ext_dir_bin, "/mnt2/%s", set_dir_bin); snprintf(ext_dir_src, sizeof ext_dir_src, "/mnt2/%s", set_dir_src); /* return location, don't clean... */ return SET_OK; }
long spoof (int argc, char* argv) { TIMEMAN res; /* Store path of the program */ bin_name = argv; program_path = argv; /* Run the program and store stats in res */ run_program (&program_path, &res); /* Generate Stats */ TIMEMAN *resp = &res; unsigned long r; /* Elapsed real milliseconds. */ unsigned long time; /* Elapsed virtual (CPU) milliseconds. */ r = resp->elapsed.tv_sec * 1000 + resp->elapsed.tv_usec / 1000; time = resp->ru.ru_utime.tv_sec * 1000 + resp->ru.ru_utime.TV_MSEC + resp->ru.ru_stime.tv_sec * 1000 + resp->ru.ru_stime.TV_MSEC; long t = resp->ru.ru_stime.tv_sec + resp->ru.ru_stime.TV_MSEC / 10 + resp->ru.ru_utime.tv_sec + resp->ru.ru_utime.TV_MSEC / 10; return r; }
/* * hook called after upgrade() or install() has finished setting * up the target disk but immediately before the user is given the * ``disks are now set up'' message. * * On pmax, we take this opportuinty to update the bootblocks. */ int md_post_newfs(void) { char *bootxx; int error; /* XXX boot blocks ... */ if (target_already_root()) { /* /usr is empty and we must already have bootblocks? */ return 0; } msg_display(MSG_dobootblks, diskdev); cp_to_target("/usr/mdec/boot.pmax", "/boot.pmax"); bootxx = bootxx_name(); if (bootxx != NULL) { error = run_program(RUN_DISPLAY | RUN_NO_CLEAR, "/usr/sbin/installboot /dev/r%sc %s", diskdev, bootxx); free(bootxx); } else error = -1; if (error != 0) process_menu(MENU_ok, deconst("Warning: disk is probably not bootable")); return 0; }
void simple_shell() { int n_args, i; //memory space for user command is always the same, freed on quit char * * sarray = malloc(max_arg_c * sizeof(*sarray)); for (i = 0; i < max_arg_c; i += 1) sarray[i] = malloc(max_arg_length + 1); print_commands(); while (1) { printf("\n---> "); for (i = 0; i < max_arg_c; i += 1) *sarray[i] = (char *)NULL; n_args = get_command_line(sarray); if (quit_command(sarray[0])) { printf("exiting shell \n"); for (i = 0; i < max_arg_c; i += 1) free(sarray[i]); free(sarray); break; } else if (!strcmp(sarray[0], "help")) print_commands(); else if (!strcmp(sarray[0], "echo")) { for (i = 1; i < n_args && sarray[i] != NULL; i += 1) printf("%s ", sarray[i]); } else if (!strcmp(sarray[0], "run")) run_program(sarray, n_args); else printf("command not found. "); } }
int main(int argc, char **argv){ bt_zero("~~~Userspace test program start!~~~\n"); print_string("TEST Command Prompt!\n"); while(true){ char input[128]={0}; print_string("[TEST]>"); get_string(input, 128); if(input[0]=='d') dir_listing(); else if(input[0]=='b') ata_test(); else if(input[0]=='l') dir_listing2(input); else if(input[0]=='f') file_contents(); else if(input[0]=='c') file_contents2(input); else if(input[0]=='m') mount_test(); else if(input[0]=='v') version(); else if(input[0]=='r') run_program(input); else if(input[0]=='p') path(input); else if(input[0]=='t') thread_test(); else if(input[0]=='x') crash_test(); else if(input[0]=='q') break; else { if(strlen(input) && input[0]!='\n') print_string("Unrecognised command.\n"); } } bt_zero("~~~Userspace test program done!~~~\n"); bt_exit(0); return 0; }
/* * auth_script - execute a script with arguments * interface-name peer-name real-user tty speed */ static void auth_script(char *script) { char strspeed[32]; struct passwd *pw; char struid[32]; char *user_name; char *argv[8]; if ((pw = getpwuid(getuid())) != NULL && pw->pw_name != NULL) user_name = pw->pw_name; else { sprintf(struid, "%d", getuid()); user_name = struid; } sprintf(strspeed, "%d", baud_rate); argv[0] = script; argv[1] = ifname; argv[2] = peer_authname; argv[3] = user_name; argv[4] = devnam; argv[5] = strspeed; argv[6] = NULL; run_program(script, argv, 0); }
int main(int argc, char *argv[]) { (void) argc; /* read intructions from argv[1], i.e. the input file */ UM_machine machine = get_new_machine_with_program(argv[1]); run_program(machine); }
static int md_newdisk(void) { msg_display(MSG_newdisk, pm->diskdev, pm->diskdev); return run_program(RUN_FATAL|RUN_DISPLAY, "/usr/mdec/newdisk -v %s", pm->diskdev); }
// Terminate any screensaver graphics application // int CScreensaver::terminate_v6_screensaver(GFXAPP_ID& graphics_application) { int retval = 0; #ifdef __APPLE__ // Under sandbox security, use gfx_switcher to kill default gfx app // as user boinc_master and group boinc_master. The man page for // kill() says the user ID of the process sending the signal must // match that of the target process, though in practice that seems // not to be true on the Mac. char current_dir[PATH_MAX]; char gfx_pid[16]; pid_t thePID; int i; sprintf(gfx_pid, "%d", graphics_application); getcwd( current_dir, sizeof(current_dir)); char* argv[4]; argv[0] = "gfx_switcher"; argv[1] = "-kill_gfx"; argv[2] = gfx_pid; argv[3] = 0; retval = run_program( current_dir, m_gfx_Switcher_Path, 3, argv, 0, thePID ); for (i=0; i<200; i++) { boinc_sleep(0.01); // Wait 2 seconds max // Prevent gfx_switcher from becoming a zombie if (waitpid(thePID, 0, WNOHANG) == thePID) { break; } } #endif #ifdef _WIN32 HWND hBOINCGraphicsWindow = FindWindow(BOINC_WINDOW_CLASS_NAME, NULL); if (hBOINCGraphicsWindow) { CloseWindow(hBOINCGraphicsWindow); Sleep(1000); hBOINCGraphicsWindow = FindWindow(BOINC_WINDOW_CLASS_NAME, NULL); if (hBOINCGraphicsWindow) { kill_program(graphics_application); } } #endif // For safety, call kill_program even under Apple sandbox security kill_program(graphics_application); return retval; }
int main(int argc, char *argv[]) { program_purpose(); run_program(); printf("End of Program."); }
static int copy_bootloader(void) { const char *mntdir = "/mnt2"; msg_display(MSG_copybootloader, pm->diskdev); if (!run_program(RUN_SILENT | RUN_ERROR_OK, "mount /dev/%s%c %s", pm->diskdev, 'a' + PART_BOOT, mntdir)) { mnt2_mounted = 1; run_program(0, "/bin/cp /usr/mdec/boot %s", mntdir); run_program(RUN_SILENT | RUN_ERROR_OK, "umount %s", mntdir); mnt2_mounted = 0; } else { /* XXX print proper error message */ return 1; } return 0; }
/* * hook called after install() has finished setting up the target disk * but immediately before the user is given the ``disks are now set up'' * message. */ int md_post_newfs(void) { if (run_program(RUN_DISPLAY | RUN_PROGRESS, "/sbin/newfs -V2 -O 0 -b %d -f %d /dev/r%s%c", PART_BOOT_BSIZE, PART_BOOT_FSIZE, pm->diskdev, 'a' + PART_BOOT)) return 1; return copy_bootloader(); }
int main(int argc, char **argv) { try { return run_program(argc, argv); } catch (std::exception &e) { std::cout << "Caught unhandled exception: " << e.what() << std::endl; return -1; } }
static int set_root_shell(struct menudesc *menu, void *arg) { configinfo **confp = arg; process_menu(MENU_rootsh, &confp[menu->cursel]->setting); run_program(RUN_PROGRESS | RUN_CHROOT, "chpass -s %s root", confp[menu->cursel]->setting); return 0; }