void fix_java_result(const char *stdout_file, const char *stderr_file) { int comp_res = execute_cmd("/bin/grep -q 'java.lang.OutOfMemoryError' %s", stderr_file); if (!comp_res) { oj_solution.result = OJ_MLE; oj_solution.memory_usage = oj_solution.memory_limit * STD_KB; return; } comp_res = execute_cmd("/bin/grep -q 'java.lang.OutOfMemoryError' %s", stdout_file); if (!comp_res) { oj_solution.result = OJ_MLE; oj_solution.memory_usage = oj_solution.memory_limit * STD_KB; return; } comp_res = execute_cmd("/bin/grep -q 'Exception' %s", stderr_file); if (!comp_res) { oj_solution.result = OJ_RE; return; } comp_res = execute_cmd("/bin/grep -q 'Could not create' %s", stderr_file); if (!comp_res) { oj_solution.result = OJ_RE; return; } }
int fix_java_mis_judge(char *work_dir, int & ACflg, int & topmemory, int mem_lmt) { int comp_res = OJ_AC; if (DEBUG) execute_cmd("cat %s/error.out", work_dir); comp_res = execute_cmd("grep 'java.lang.OutOfMemoryError' %s/error.out", work_dir); if (!comp_res) { printf("JVM need more Memory!"); ACflg = OJ_ML; topmemory = mem_lmt * STD_MB; } comp_res = execute_cmd("grep 'java.lang.OutOfMemoryError' %s/user.out", work_dir); if (!comp_res) { printf("JVM need more Memory or Threads!"); ACflg = OJ_ML; topmemory = mem_lmt * STD_MB; } comp_res = execute_cmd("grep 'Could not create' %s/error.out", work_dir); if (!comp_res) { printf("jvm need more resource,tweak -Xmx Settings"); ACflg = OJ_RE; //topmemory=0; } return comp_res; }
void copy_python_runtime(char * work_dir) { copy_shell_runtime(work_dir); execute_cmd("mkdir %s/usr", work_dir); execute_cmd("mkdir %s/usr/lib", work_dir); execute_cmd("cp /usr/bin/python* %s/", work_dir); }
/* Build Dir to run exec */ void run_judge_clinet_mkdir(int solution_id){ execute_cmd("mkdir %d -m 777", solution_id); execute_cmd("mkdir %d/%s -m 777", solution_id, problem.my_out_path.c_str()); execute_cmd("mkdir %d/%s -m 777", solution_id, problem.my_result_path.c_str()); }
void copy_ruby_runtime(char * work_dir) { copy_shell_runtime(work_dir); execute_cmd("mkdir %s/usr", work_dir); execute_cmd("mkdir %s/usr/lib", work_dir); execute_cmd("cp /usr/lib/libruby* %s/usr/lib/", work_dir); execute_cmd("cp /usr/bin/ruby* %s/", work_dir); }
/* * __mount(): wrapper around the mount() system call which also * sets the underlying block device to read-only if the mount is read-only. * See "man 2 mount" for return values. */ static int __mount(const char *source, const char *target, const struct fstab_rec *rec, int encryptable) { unsigned long mountflags = rec->flags; int ret; int save_errno; /* We need this because sometimes we have legacy symlinks * that are lingering around and need cleaning up. */ struct stat info; if (!lstat(target, &info)) if ((info.st_mode & S_IFMT) == S_IFLNK) unlink(target); mkdir(target, 0755); NOTICE("%s: target='%s, encryptable=%d \n", __FUNCTION__, target, encryptable); if(encryptable == FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED && (!strcmp(target, PROTECT_1_MNT_POINT) || !strcmp(target, PROTECT_2_MNT_POINT)) ) { NOTICE("encryptable is FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED. Need to mount '%s' as tmpfs\n", target); if ((ret = fs_mgr_do_tmpfs_mount((char *)target))) { ERROR("Mount '%s' to tmpfs fail. \n", target); } else { NOTICE("Try to copy modem nvram from emmc to the tmpfs of '%s'\n", target); char tmp_mnt_point[256]; snprintf(tmp_mnt_point, sizeof(tmp_mnt_point), "/mnt%s", target); char *mkdir_argv[] = {"/system/bin/mkdir", tmp_mnt_point}; execute_cmd(mkdir_argv, ARRAY_SIZE(mkdir_argv)); if (!access(tmp_mnt_point, F_OK) && (ret = mount(source, tmp_mnt_point, rec->fs_type, mountflags, rec->fs_options))) { ERROR("Fail: mount '%s', errno=%d \n", tmp_mnt_point, errno); } else { char *cp_argv[] = {"/system/bin/cp", "-Rp", tmp_mnt_point, "/"}; execute_cmd(cp_argv, ARRAY_SIZE(cp_argv)); char *umount_argv[] = {"/system/bin/umount", tmp_mnt_point}; if(!execute_cmd(umount_argv, ARRAY_SIZE(umount_argv))) { char *rm_argv[] = {"/system/bin/rm", "-rf", tmp_mnt_point}; execute_cmd(rm_argv, ARRAY_SIZE(rm_argv)); } } } } else { ret = mount(source, target, rec->fs_type, mountflags, rec->fs_options); save_errno = errno; INFO("%s(source=%s,target=%s,type=%s)=%d\n", __func__, source, target, rec->fs_type, ret); if ((ret == 0) && (mountflags & MS_RDONLY) != 0) { fs_set_blk_ro(source); } errno = save_errno; } return ret; }
void copy_php_runtime(char * work_dir) { copy_shell_runtime(work_dir); execute_cmd("mkdir %s/usr", work_dir); execute_cmd("mkdir %s/usr/lib", work_dir); execute_cmd("cp /usr/lib/libedit* %s/usr/lib/", work_dir); execute_cmd("cp /usr/lib/libdb* %s/usr/lib/", work_dir); execute_cmd("cp /usr/lib/libgssapi_krb5* %s/usr/lib/", work_dir); execute_cmd("cp /usr/lib/libkrb5* %s/usr/lib/", work_dir); execute_cmd("cp /usr/lib/libk5crypto* %s/usr/lib/", work_dir); execute_cmd("cp /usr/lib/libxml2* %s/usr/lib/", work_dir); execute_cmd("cp /usr/bin/php* %s/", work_dir); execute_cmd("chmod +rx %s/Main.php", work_dir); }
int execute_cmd(char *cmd, int in) { char *p = cmd; char *start_cmd = cmd; int pipefd[2]; while (*p) { switch (*p) { case '|': *p++ = 0; //创建一个管道 pipe(pipefd); //下面的语句执行后,程序分叉,第一叉在当前捕获的命令,第二 //叉在后面继续解析命令 //将写管道传给当前捕获的命令用于重定向其stdout if (fork_and_exec(start_cmd, in, pipefd[1]) > 0) { //将读管道传给将要被捕获的命令用于重定向其stdin goto call_forward_pipe_chain; } break; default: p++; } } fork_and_exec(start_cmd, in, -1); fflush(stdout); return 0; call_forward_pipe_chain: execute_cmd(p, pipefd[0]); fflush(stdout); return 0; }
int main(int argc, char * argv[]) { char current_path[] = "0:/"; printf(SHELL_BANNER",%s,v%d。\n", __DATE__, SHELL_VERSION); printf("输入help获取帮助.\n"); /* Loop to get char */ while(1) { int ch; /* 获取当前路径 */ /* 打印提示符 */ printf("[%s]#", current_path); ch = read_input(line_buffer, MAX_LINE_SIZE); printf("\n"); /* 回车键则执行命令 */ if (ch == SHELL_KEY_ENTER) { execute_cmd(line_buffer); } } return 0; }
/* * SPI Start Interrupt, this should never get called when chip select is high. * * NOTE: This is intentionally not done with an overflow interrupt, * as the software chip select interrupt will be triggered almost at * the same time as an SPI overflow, causing the SPI interrupt to not be * handled. */ ISR(USI_STR_vect, ISR_BLOCK) { // wait for overflow flag to become 1 while (!(USISR & _BV(USIOIF))) ; // get data from USIDR uint8_t recv_data = USIDR; // clear the SPI start flag USISR |= _BV(USISIF); // clear the overflow flag USISR |= _BV(USIOIF); // increment our received byte count and take appropiate action byte_cnt++; if (byte_cnt == 1) { // we don't have a command already, set the response // buffer to the command we received to let the // master confirm the given command if desired, top // bit is set if currently charging cur_command_ = recv_data; USIDR = cur_command_; } else if (byte_cnt == 2) { // execute the currently set command with // the newly given argument, set the response // buffer to our return value USIDR = execute_cmd(cur_command_, recv_data); } else { USIDR = 0x11; } }
uint8 FSDrive::Open(int channel, const uint8 *name, int name_len) { set_error(ERR_OK); // Channel 15: Execute file name as command if (channel == 15) { execute_cmd(name, name_len); return ST_OK; } // Close previous file if still open if (file[channel]) { fclose(file[channel]); file[channel] = NULL; } if (name[0] == '#') { set_error(ERR_NOCHANNEL); return ST_OK; } if (name[0] == '$') return open_directory(channel, name + 1, name_len - 1); return open_file(channel, name, name_len); }
/** * Drops the SAs for the given contact. * @param c - the contact to drop the SAs for * \note Should be called some time after the deregistration, to allow the 200 OK for * De-REGISTER and other messages to still reach the client and responses to be relayed * to the network. */ void P_security_drop(r_contact *c,r_security *s) { char drop[256]; r_ipsec *i; if (!s||!c) return; switch (s->type){ case SEC_NONE: break; case SEC_TLS: //TODO!!! break; case SEC_IPSEC: i = s->data.ipsec; if (!i) return; sprintf(drop,"%s %.*s %d %d %s %d %d %d %d %d %d", pcscf_ipsec_P_Drop, c->host.len,c->host.s, i->port_uc, i->port_us, pcscf_ipsec_host, pcscf_ipsec_port_c, pcscf_ipsec_port_s, i->spi_uc, i->spi_us, i->spi_pc, i->spi_ps); execute_cmd(drop); break; } }
void shell_loop (FILE *file) { struct shelldata sd; int c; /* setvbuf(file,NULL,_IONBF,0); fflush(file); */ char str[2048]; sd.update_cfg = cw_ktv_create(); sd.out = file; sprintf(sd.prompt,"%s","*"); do { fprintf (file, "actube[%s]:>", sd.prompt); fflush (file); str[0]=0; fgets (str, sizeof (str), file); execute_cmd (&sd, str); } while (c != EOF); }
int fix_gcc_result(const char *stderr_compiler) { if (oj_solution.lang != LANG_C99 && oj_solution.lang != LANG_C11 && oj_solution.lang != LANG_CPP98 && oj_solution.lang != LANG_CPP11 && oj_solution.lang != LANG_CPP14 && oj_solution.lang != LANG_CPP17) { return 0; } int comp_res = execute_cmd("/bin/grep -q 'compiler error' %s", stderr_compiler); if (!comp_res) { execute_cmd("/bin/sed -n -i '1p' stderr_compiler.txt"); return 1; } return 0; }
void copy_shell_runtime(char * work_dir) { execute_cmd("mkdir %s/lib", work_dir); execute_cmd("mkdir %s/lib64", work_dir); execute_cmd("mkdir %s/bin", work_dir); execute_cmd("cp /lib/* %s/lib/", work_dir); execute_cmd("cp /lib64/* %s/lib64/", work_dir); execute_cmd("cp -a /lib32 %s/", work_dir); execute_cmd("cp /bin/busybox %s/bin/", work_dir); execute_cmd("ln -s /bin/busybox %s/bin/sh", work_dir); execute_cmd("cp /bin/bash %s/bin/bash", work_dir); }
/* Get Problem's Input/Output/TimeLimit/MemoryLimit */ bool run_judge_client_problem(int solution_id, int problem_id, int &time_limit, int &memory_limit){ MYSQL_RES* mysql_result = mysql_con.run_sql_world("SELECT * FROM %s WHERE problem_id = %d", MYSQL_MESSAGE::problem_name, problem_id); MYSQL_ROW mysql_row = mysql_fetch_row(mysql_result); if(mysql_row != NULL){ /* Get I/O File from database. //Inpit char path[BUFFER_SIZE]; sprintf(path, "%d", solution_id); string file = string(path) + "/" + problem.in_file; FILE *fp = fopen(file.c_str(), "w"); fprintf(fp, "%s", mysql_row[PROBLEM_TABLE::input]); fclose(fp); //Output file = string(path) + "/" + problem.out_file; fp = fopen(file.c_str(), "w"); fprintf(fp, "%s", mysql_row[PROBLEM_TABLE::output]); fclose(fp); */ //IO FILE char cp_from[BUFFER_SIZE], cp_to[BUFFER_SIZE]; sprintf(cp_from, "%s/%d", io_file_path.c_str(), problem_id); sprintf(cp_to, "%d/%s", solution_id, problem.io_path.c_str()); execute_cmd("cp -a %s %s", cp_from, cp_to); //TimeLimit time_limit = atoi(mysql_row[PROBLEM_TABLE::time_limit]); //MemoryLimit memory_limit = atoi(mysql_row[PROBLEM_TABLE::memory_limit]); } else return false; }
int main(void) { int i, background; char input[MAX]; char path[MAX] = "."; char entry_dir[MAX] = {0}; char working_dir[MAX] = {0}; char *arguments[512] = {0}; /* enter up to 511 arguments, one is reserved for the execution cmd */ getcwd(entry_dir, sizeof(entry_dir)); /* get the entry directory */ /* infinite loop until the user enters exit */ while (1) { signal(SIGINT, ctrlc_handler); /* signalhandler to avoid CTRL+C killing the shell */ prompt(path); fgets(input, MAX, stdin); /* read from standardinput */ i = 0; while (input[i] != '\n') i++; input[i] = '\0'; /* remove newline from read string and replace it with \0 */ background = parse_input(input, arguments); /* parse string and set background/pipe option */ if (*arguments != 0){ /* press Enter without SEGfault :P */ /* all ifs are built-ins for the shell, except for the else */ if (strcmp(arguments[0], "exit") == 0) return 0; else if (background == 2) { execute_pipe(arguments); } else if (strcmp(arguments[0], "cd") == 0) { if (arguments[1] == NULL) { /* change to user's HOME if only cd is entered */ chdir(getenv("HOME")); getcwd(working_dir, sizeof(working_dir)); print_current_dir(entry_dir, working_dir, path); } else { chdir(arguments[1]); getcwd(working_dir, sizeof(working_dir)); print_current_dir(entry_dir, working_dir, path); } } else if (strcmp(arguments[0], "wait") == 0) { if (arguments[1] == NULL) /* maybe there is no pid given by the user */ puts("No PID!"); else { keepWaiting = 1; waiting(arguments); } } else { execute_cmd(arguments, background); } } } }
void execute_shell(SystemMem *SysMem_s) { char inputBuffer[MAX_INPUT_LENGTH]; // Taille max d'une commande saisie par l'utilisateur InputCmd InputCmd_s; // Struct de la commande saisie fflush(stdin); // DEBUG #ifdef DEBUG char count_str[MAX_INPUT_LENGTH]; char time_str[1000]; int count = 1; time_t starttime; starttime = time(NULL); #endif // Demande une commande à l'utilisateur while (fgets(inputBuffer, MAX_INPUT_LENGTH, stdin)) { // Récupération de la commande et du path dans la chaîne saisie par l'utilisateur if (parse_input_data(inputBuffer, &InputCmd_s) == 0) { // Traite la commande de fin if (is_exit_cmd(InputCmd_s.cmdStr)) break; // Quit // Traite les commandes if (strcmp(InputCmd_s.cmdStr, "") != 0 && is_valid_cmd(InputCmd_s)) // strcmp permet une saisie vide execute_cmd(SysMem_s, &InputCmd_s); } #ifdef DEBUG sprintf(count_str, "%d", count); sprintf(time_str, "%ld", (time(NULL) - starttime)); fprintf(stderr, "DEBUG-> ("); fprintf(stderr, count_str); fprintf(stderr, ") CMD: ["); fprintf(stderr, InputCmd_s.cmdStr); fprintf(stderr, "] PATH: ["); fprintf(stderr, InputCmd_s.pathStr); fprintf(stderr, "] WRITESTR: ["); fprintf(stderr, InputCmd_s.dataStr); fprintf(stderr, "] @"); fprintf(stderr, time_str); fprintf(stderr, "secs\n"); count++; #endif strcpy(InputCmd_s.cmdStr, ""); // Reset strcpy(InputCmd_s.pathStr, ""); // Reset strcpy(InputCmd_s.dataStr, ""); // Reset } }
void prepare_files(char * filename, int namelen, char * infile, int & p_id, char * work_dir, char * outfile, char * userfile, int runner_id) { // printf("ACflg=%d %d check a file!\n",ACflg,solution_id); char fname[BUFFER_SIZE]; strncpy(fname, filename, namelen); fname[namelen] = 0; sprintf(infile, "%s/data/%d/%s.in", oj_home, p_id, fname); execute_cmd("cp %s %sdata.in", infile, work_dir); sprintf(outfile, "%s/data/%d/%s.out", oj_home, p_id, fname); sprintf(userfile, "%s/run%d/user.out", oj_home, runner_id); }
SETUP() { static const cmd_add_t move = { .name = "move", .abbr = "m", .id = -1, .descr = "descr", .flags = HAS_EMARK | HAS_RANGE | HAS_BG_FLAG | HAS_QUOTED_ARGS | HAS_QMARK_NO_ARGS | HAS_SELECTION_SCOPE, .handler = &move_cmd, .min_args = 0, .max_args = NOT_DEF, }; add_builtin_commands(&move, 1); assert_success(execute_cmd("command udf a")); assert_success(execute_cmd("command mkcd! a")); assert_success(execute_cmd("command mkcd? a")); } static int move_cmd(const cmd_info_t *cmd_info) { move_cmd_called = 1; return 0; }
int handle_cmd() { wprintf(L"\n"); wprintf(L"CMD: "); move_begin_list(buffer); print_buffer(false); wprintf(L"\n"); free_buffer_content(); execute_cmd(); return RET_OK; }
/*实际应用中,处理服务器指令是异步方式,需要厂家处理完毕后主动上报一次设备状态*/ int ICACHE_FLASH_ATTR rawdata_set_callback(char *rawdata, int len) { // TODO: //get cmd from server, do your job here! int ret = 0; wsf_deb("%s %d \n", __FUNCTION__, __LINE__); ret = execute_cmd(rawdata, len); //ret=alink_device_post_raw_data(); // do your job end! delta_time = system_get_time(); device_status_change = 1; return ret; }
void cmd_thread_func() { while(1) { svcWaitSynchronization(new_cmd_event, U64_MAX); svcClearEvent(new_cmd_event); if(thread_exit) svcExitThread(); last_cmd = cmd.type; last_cmd_result = execute_cmd(sock, &cmd); svcSignalEvent(cmd_done_event); } }
/* * Function: create_default_fdisk_partition * * Parameters: op - CCIMObjectPath pointer that points to the object path * of the device to fdisk. * * Returns: Returns a CCIMProperty pointer. The CCIMProperty referenced * by the pointer will contain an mValue of cim_true for * success or cim_false on failure. * * Description: Executes the fdisk command on the device pointed to my 'op' * with the -B parameter. * * Notes: The calling program is responsible for releasing the memory * used by the returned CCIMProperty. */ CCIMProperty * create_default_fdisk_partition(CCIMObjectPath *op) { char devpath[MAXPATHLEN]; char err_file[L_tmpnam]; char command_line[CMDLEN]; int len; int error; /* This function is called from Solaris_DiskDrive, not Solaris_Disk. */ if (!check_rights("Solaris_DiskDrive") || op == NULL) { return (create_result(PROPFALSE)); } if (get_devpath(op, devpath, sizeof (devpath)) == cim_false) { util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_PARAMETER, CIM_ERR_FAILED, NULL, &error); return (create_result(PROPFALSE)); } make_fdisk_path(devpath); (void) tmpnam(err_file); /* * Build the fdisk command line. Some combinations of * parameters can cause fdisk to output a message and wait * for a y/n response, echo'ing an 'n' and piping it to * fdisk solves this problem. * * Using the form of fdisk (-F) that takes partition information * from a disk file so that multiple partitions can be created * by one request. */ len = snprintf(command_line, sizeof (command_line), "echo n | /usr/sbin/fdisk -B %s 2> %s", devpath, err_file); if (len < 0 || (len + 1) > sizeof (command_line)) { util_handleError(INVOKE_METHOD, CIM_ERR_FAILED, NULL, NULL, &error); return (create_result(PROPFALSE)); } /* Execute the command. */ if (!execute_cmd(command_line, err_file)) { return (create_result(PROPFALSE)); } return (create_result(PROPTRUE)); }
int double_close_chevron_operation(t_core *core, t_mod_pack *packet, t_module *mods) { if (packet->rd_write == ERROR && packet->av != NULL) { core->err_open = open_file(get_fd(packet, TOK_DCCHV), packet->av[0], get_flags(TOK_DCCHV), get_mode(TOK_DCCHV)); } else if (packet->rd_write != ERROR) return (execute_cmd(core, packet, mods)); else return (ERROR); return (NO_ERR); }
/** * We have data from the client, we must route it to the backend. * This is simply a case of sending it to the connection that was * chosen when we started the client session. * * @param instance The router instance * @param router_session The router session returned from the newSession call * @param queue The queue of data buffers to route * @return The number of bytes sent */ static int execute(ROUTER *instance, void *router_session, GWBUF *queue) { CLI_SESSION *session = (CLI_SESSION *)router_session; /* Extract the characters */ while (queue) { strncat(session->cmdbuf, GWBUF_DATA(queue), MIN(GWBUF_LENGTH(queue),cmdbuflen-1)); queue = gwbuf_consume(queue, GWBUF_LENGTH(queue)); } execute_cmd(session); return 1; }
int NOOP_test(static_config *jtpz,dynamic_config *dtpz) { char cmd[100] = "/root/njkk/testftp "; char result[100] = {0}; execute_cmd(cmd, result,jtpz,dtpz); if (strstr(result,"200") != NULL) { OpenPort_state = 1; return 0; } else { return -1; } }
int read_loop(int sockfd, struct in_addr *client_addr) { t_serv_fs serv_fs; int ret; serv_fs.client_addr = client_addr; if (!(init_serv_fs(&serv_fs))) return (0); while (1) { ret = execute_cmd(sockfd, &serv_fs); if (ret < 0) return (1); } return (1); }
static void test_delc_completion(void) { char *completion; assert_int_equal(0, execute_cmd("command udf a")); reset_completion(); assert_int_equal(5, complete_cmd("delc u")); assert_int_equal(2, get_completion_count()); if(get_completion_count() == 0) return; completion = next_completion(); assert_string_equal("udf", completion); free(completion); }
/* * Function: writeVolumeName * * Parameters: params - CCIMPropertyList pointer. Property list * containing the new disk label name. * op - CCIMObjectPath pointer. Object path containing * the deviceId of the disk to label. * * Returns: Returns a CCIMProperty pointer. The CCIMProperty referenced * by the pointer will contain an mValue of cim_true for * success or cim_false on failure. * * Description: Executes the fmthard -n volume_name command on the device * pointed to by 'op'. */ CCIMProperty * label_disk(CCIMPropertyList *params, CCIMObjectPath *op) { char devpath[MAXPATHLEN]; char command_line[CMDLEN]; int len; cimchar *label; int error; if (!check_rights("Solaris_Disk") || op == NULL || params == NULL) { return (create_result(PROPFALSE)); } if (get_devpath(op, devpath, sizeof (devpath)) == cim_false) { util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error); return (create_result(PROPFALSE)); } /* Extract the label from the input parameters */ if ((label = get_prop_val(params->mDataObject)) == NULL) { return (create_result(PROPFALSE)); } if (strlen(label) > 8) { util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error); return (create_result(PROPFALSE)); } /* Build the command line to execute */ len = snprintf(command_line, sizeof (command_line), "/usr/sbin/fmthard -n '%s' %s 2> /dev/null", label, devpath); if (len < 0 || (len + 1) > sizeof (command_line)) { util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error); return (create_result(PROPFALSE)); } /* Execute the command. */ if (!execute_cmd(command_line, "/dev/null")) { return (create_result(PROPFALSE)); } return (create_result(PROPTRUE)); }