Exemplo n.º 1
0
void
consserve(void)
{
	con_session();
	cmd_exec("cfs");
	cmd_exec("user");
}
Exemplo n.º 2
0
void run_cmd(const struct cmd *cmd, int argc, char *argv[], FILE *out) {
	/* This function is for launching program that is beging tested with monitoring
	 * of all function calls and exits.
	 *	Args:	*cmd	-	pointer to the command that will be launched
	 *			argc	-	the number of arguments passed to pragram
	 *			argv	-	array of arguments
	 *			out		-	output file to write profiling info
	 */
	int res = 0, run = 0;
	clock_t begin, end;
	set_profiling_mode(DISABLED);
	initialize_hashtable();

	printf("Initialization...\n");
	/*trace_block_hashtable_init();*/
	printf("Executing command\n");
	begin = clock();
	for (run = 0; run < run_count; run++) {
		printf ("TBPROF RUN #%d\n", run);
		set_profiling_mode(CYG_PROFILING);
		res = cmd_exec(cmd, argc, argv);
		set_profiling_mode(DISABLED);
	}
	end = clock();
	printf("Program exited with code %d. Time: %0.3lfs. Profiling finished.\n",
			res, 1. * (end - begin) / CLOCKS_PER_SEC);

	argc++;
	cmd = NULL;
	print_data_to_file(out);
}
Exemplo n.º 3
0
static int netns_exec(int argc, char **argv)
{
	/* Setup the proper environment for apps that are not netns
	 * aware, and execute a program in that environment.
	 */
	const char *cmd;

	if (argc < 1 && !do_all) {
		fprintf(stderr, "No netns name specified\n");
		return -1;
	}
	if ((argc < 2 && !do_all) || (argc < 1 && do_all)) {
		fprintf(stderr, "No command specified\n");
		return -1;
	}

	if (do_all)
		return do_each_netns(on_netns_exec, --argv, 1);

	if (netns_switch(argv[0]))
		return -1;

	/* ip must return the status of the child,
	 * but do_cmd() will add a minus to this,
	 * so let's add another one here to cancel it.
	 */
	cmd = argv[1];
	return -cmd_exec(cmd, argv + 1, !!batch_mode);
}
Exemplo n.º 4
0
void cmd_remote_handler( int rc, int sock ) {
	char* argv[32];
	int argc;

	IP clientaddr;
	socklen_t addrlen_ret;
	socklen_t addrlen;
	char request[1500];
	REPLY reply;

	addrlen_ret = sizeof(IP);
	rc = recvfrom( sock, request, sizeof(request) - 1, 0, (struct sockaddr*)&clientaddr, &addrlen_ret );
	if( rc <= 0 ) {
		return;
	} else {
		request[rc] = '\0';
	}

	/* Initialize reply and reserve room for return status */
	r_init( &reply, false );
	r_printf( &reply, "_" );

	/* Split up the command line into an argument array */
	cmd_to_args( request, &argc, &argv[0], N_ELEMS(argv) );

	/* Execute command line */
	rc = cmd_exec( &reply, argc, argv );

	/* Insert return code */
	reply.data[0] = (rc == 0) ? '0' : '1';

	addrlen = addr_len( &clientaddr );
	rc = sendto( sock, reply.data, reply.size, 0, (struct sockaddr *)&clientaddr, addrlen );
}
Exemplo n.º 5
0
int exec_call(void) {
	int ecode;
	struct task *task = task_self();
	const char *path = task_resource_argv_path(task);
	const char *cmd_name = exec_cmd_name(path);
	const struct shell *sh = shell_lookup(cmd_name);
	int c;
	char **v;

	if (strcmp(cmd_name, path))
		task_resource_argv_insert(task, cmd_name, 0);

	c = task_resource_argv_argc(task);
	v = task_resource_argv_argv(task);

	/* FIXME pass argv to shell_exec */
	if (sh) {
		ecode = shell_run(sh);
	} else {
		const struct cmd *cmd;

		cmd = cmd_lookup(cmd_name);

		if (cmd) {
			task_self_module_ptr_set(cmd2mod(cmd));
			ecode = cmd_exec(cmd, c, v);
		} else {
			ecode = ENOENT;
		}
	}

	return ecode;
}
Exemplo n.º 6
0
int shell (int argc, char *argv[]) {
  char *s = malloc(INPUT_STRING_SIZE+1);			/* user input string */
  char cwd[MAX_FILE_SIZE+1];
  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);
  
  //getcwd(cwd, MAX_FILE_SIZE);
  lineNum=0;
  //fprintf(stdout, "%d - %s: ", cwd, lineNum);
  while ((s = freadln(stdin))){
    
    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{
	cmd_exec(t);
    }
    fprintf(stdout, "%d %s: ", ++lineNum, get_current_dir_name());
  }
  return 0;
}
Exemplo n.º 7
0
/*
 * Forward forever, or until a highlighted line appears.
 */
static int
forw_loop(int until_hilite)
{
	off_t curr_len;

	if (ch_getflags() & CH_HELPFILE)
		return (A_NOACTION);

	cmd_exec();
	jump_forw();
	curr_len = ch_length();
	highest_hilite = until_hilite ? curr_len : -1;
	ignore_eoi = 1;
	while (!sigs) {
		if (until_hilite && highest_hilite > curr_len) {
			ring_bell();
			break;
		}
		make_display();
		forward(1, 0, 0);
	}
	ignore_eoi = 0;
	ch_set_eof();

	/*
	 * This gets us back in "F mode" after processing
	 * a non-abort signal (e.g. window-change).
	 */
	if (sigs && !ABORT_SIGS())
		return (until_hilite ? A_F_UNTIL_HILITE : A_F_FOREVER);

	return (A_NOACTION);
}
Exemplo n.º 8
0
void cmd_console_handler( int rc, int fd ) {
	char request[512];
	char *req;
	REPLY reply;
	char *argv[32];
	int argc;

	if( rc == 0 ) {
		return;
	}

	/* Read line */
	req = fgets( request, sizeof(request), stdin );

	if( req == NULL ) {
		return;
	}

	/* Split up the command line into an argument array */
	cmd_to_args( request, &argc, &argv[0], N_ELEMS(argv) );

	/* Initialize reply */
	r_init( &reply, true );

	/* Execute command line */
	rc = cmd_exec( &reply, argc, argv );

	if( rc == 0 ) {
		fprintf( stdout, "%.*s\n", (int) reply.size, reply.data );
	} else {
		fprintf( stderr, "%.*s\n", (int) reply.size, reply.data );
	}
}
Exemplo n.º 9
0
// ****************************************************************
// * The main function puts everything together so that the shell *
// * can work.													  *
// ****************************************************************
int main(int argc, char **argv, char **envp) 
{
	int fd, i;
	char c;
	char *input_str = calloc(BUFFERSIZE, sizeof(char*));
	char *cmd = calloc(BUFFERSIZE, sizeof(char*));

	// ignore the standard interrupt signal (ctrl+c)
	signal(SIGINT, SIG_IGN);
	// assign interrupt signal (ctrl+c) to the signal handler function
	signal(SIGINT, sig_hdlr);

	// prepare screen and fetch necessary data
	initilize(envp);

	// main loop might be stopped by typing 'quit', 'exit' or by pressing 'ctrl+d'
	while(strcmp(input_str, QUIT_CMD) != 0 && strcmp(input_str, EXIT_CMD) != 0 && c != EOF) {
		// get input
		c = getchar();
		// this switch-case statement read and prepare the input string
		switch(c) {
			case NEWLINE_SYMBOL:
				// if no command is inserted, just print the prompt again
				if(input_str[0] != NULL_SYMBOL) {
					// erase cmd variable
					memset(cmd, 0, BUFFERSIZE);
					// parse the command line
					cmd = prepare_inputs(input_str);
					// special case: change directory call
					if(strncmp(cmd, CD, 2) == 0) {
						cd(inputs[1]);
					// all other command calls
					} else {
						get_cmd_pth(cmd);
						cmd_exec(cmd, envp);
					}
					free_arr(inputs);
				}
				// print the prompt again after hitting enter
				print_prompt();
				memset(input_str, 0, BUFFERSIZE);
				break;
			default:
				// prepare the input string
				strncat(input_str, &c, 1);
				break;
		}
	}

	// free allocated memories
	free(cmd);
	free(input_str);
	free_arr(paths);

	// print new line if 'ctrl+d' is pressed
	if(c == EOF) printf(NEWLINE_STR);

	// end of main
	return 0;
}
Exemplo n.º 10
0
int main(void)
{
	int i;
	char outbuf[28];

	srand(time(NULL));
	for (i = 0; i < sizeof(testvectors) / sizeof(testvectors[0]); i++) {
		struct test *t = &testvectors[i];
		char *inbuf = malloc(strlen(t->input) + 1);
		int k;

		/* Reset output buffer with some fuzzy garbage.. */
		for (k = 0; k < sizeof(outbuf); k++)
			outbuf[k] = rand() % 256;

		/* Duplicate string in writable memory for strtok */
		strcpy(inbuf, t->input);

		cmd_exec(commandlist, inbuf, outbuf, sizeof(outbuf));

		if (!strcmp(outbuf, t->expected))
			printf("'%s' -> '%s' OK!\n", t->input, outbuf);
		else {
			printf("'%s' -> '%s' (expected '%s') FAILED!\n", t->input,
			    outbuf, t->expected);

			free(inbuf);
			return EXIT_FAILURE;
		}

		free(inbuf);
	}

	return EXIT_SUCCESS;
}
Exemplo n.º 11
0
/*
* Parses the input into commands and arguments using whitespace
* Then calls the associated function or error
* Maximum number of arguments is 5
*/
void parse(char *in)
{
	int argNum = 1;
	char *arg, *argArr[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
	arg = (char *) malloc(sizeof(char) * (strlen(in) + 1));

	/* Parse command */
	arg = strtok(in, " \r\n\t");
	argArr[0] = arg;
	if (argArr[0] == NULL) {
		fprintf(stderr, "ERROR: unknown command\n");
		return;
	}

	/* Parse arguments */
	arg = strtok(NULL, " \r\n\t");
	while (arg != NULL && argNum < 6) {
		if (strcmp(arg, " ") && strcmp(arg, "\r")
			&& strcmp(arg, "\n")) {
			argArr[argNum] = arg;
			argNum++;
		}
		arg = strtok(NULL, " \r\n\t");
	}

	/* Execute according to command */
	if (strcmp(argArr[0], "exit") == 0) {
		printf("EXITING SHELL...\n");
		exit(EXIT_SUCCESS);
	} else if (strcmp(argArr[0], "cd") == 0) {
		cmd_cd(argArr[1]);
	} else if (strcmp(argArr[0], "pushd") == 0) {
		char *oldwd = (char *) malloc(sizeof(char) * strlen(cwd));
		strcpy(oldwd, cwd);
		if (cmd_cd(argArr[1]) == 0)
			dirStack = stackPush(dirStack, oldwd);
	} else if (strcmp(argArr[0], "popd") == 0) {
		if (dirStack != NULL) {
			cmd_cd(dirStack->str);
			dirStack = stackPop(dirStack);
		} else {
			fprintf(stderr, "ERROR: stack is empty\n");
		}
	} else if (strcmp(argArr[0], "dirs") == 0) {
		stackPrint(dirStack);
	} else if (strcmp(argArr[0], "path") == 0) {
		if (argArr[1] == NULL && argArr[1] == NULL)
			listPrint(pathStack);
		else if (strcmp(argArr[1], "+") == 0)
			pathFind(1, argArr[2]);
		else if (strcmp(argArr[1], "-") == 0)
			pathFind(-1, argArr[2]);
		else
			fprintf(stderr, "ERROR: bad flag: %s\n", argArr[1]);
	} else {
		cmd_exec(argArr, argNum);
	}
};
Exemplo n.º 12
0
static void serve(int client){
	int n;
	struct cmd_t cmd;

	n = read(client, (void *) &cmd, sizeof(cmd));
	if (n != sizeof(cmd)) return;

	cmd_exec(client, cmd);
}
Exemplo n.º 13
0
int main(){
	char line[100], token[10][20] = {"","","","","","","","","",""};
	char* temp;
	int i = 0, newlineChecker = 0;

	while(scanf("%[^\n]\n", line) != EOF){

		struct command_t command;

        for(i = 0; i < 10; i++){
			strcpy(token[i], "");
		}
		for(i = 0; i < 10; i++){
			strcpy(command.token[i], "");
		}

		temp = strtok(line, " ");
		i = 0;
		while(temp != 0 && i < 10){
			strcpy(token[i], temp);
			i++;
			temp = strtok(NULL, " ");
		}

		i = 0;
		while(strcmp(token[i], "") != 0){
			strcpy(command.token[i], token[i]);
			i++;
		}

		if(newlineChecker != 0)
			printf("\n");
		int errCode = 0;
		if((errCode = cmd_exec(&command)) == 0){
			if(command.result != 42)
				printf("%d", command.result);
			else
				printf("the answer to life, the universe and everything else");

		}
		else{
			if(errCode == -1)
				printf("operation not supported");
			if(errCode == -2)
				printf("invalid command argument count");
			if(errCode == -3)
				printf("invalid command arguments");
			if(errCode == -4)
				printf("invalid input");
			if(errCode == -5)
				printf("invalid arithmetic operation");
		}
		newlineChecker = 1;
	}

	return 0;
}
Exemplo n.º 14
0
/*
 * process to synch blocks
 * it puts out a block/line every second
 * it waits 10 seconds if catches up.
 * in both cases, it takes about 10 seconds
 * to get up-to-date.
 *
 * it also updates the filter stats
 * and executes commands
 */
void
syncproc(void)
{
	char buf[4*1024];
	Filter *ft;
	uint32_t c0, c1;
	int32_t t, n, d;
	int i, p[2];

	/*
	 * make a pipe for commands
	 */
	if(pipe(p) < 0)
		panic("command pipe");
	sprint(buf, "#s/%s.cmd", service);
	srvfd(buf, cmdmode, p[0]);
	close(p[0]);
	cmdfd = p[1];
	notify(catchalarm);

	t = time(nil);
	for(;;){
		i = syncblock();
		alarmed = 0;
		alarm(i ? 1000: 10000);
		n = read(cmdfd, buf, sizeof buf - 1);
		if(n <= 0 && !alarmed)
			sleep(i ? 1000: 10000);
		alarm(0);
		if(n > 0){
			buf[n] = '\0';
			if(cmd_exec(buf))
				fprint(cmdfd, "done");
			else
				fprint(cmdfd, "unknown command");
		}
		n = time(nil);
		d = n - t;
		if(d < 0 || d > 5*60)
			d = 0;
		while(d >= 1) {
			d -= 1;
			for(i=0; i<f.nfilter; i++) {
				ft = f.filters[i];
				c0 = ft->count;
				c1 = c0 - ft->oldcount;
				ft->oldcount = c0;
				ft->filter[0] = famd(ft->filter[0], c1, 59, 60);
				ft->filter[1] = famd(ft->filter[1], c1, 599, 600);
				ft->filter[2] = famd(ft->filter[2], c1, 5999, 6000);
			}
		}
		t = n;
	}
}
Exemplo n.º 15
0
// ****************************************************************
// * This function clears the screen, for our new shell to open   *
// * and prints the prompt for the first time.  				  *
// * Also, it gets all the paths where the system commands may be *
// * stored, by calling get_paths().							  *
// ****************************************************************
void initilize(char **envp)
{
	char *cmd = calloc(BUFFERSIZE, sizeof(char*));

	get_paths(envp);
	cmd = prepare_inputs(CLEAR);
	get_cmd_pth(cmd);
	cmd_exec(cmd, envp);
	sig_hdlr(0);
	free_arr(inputs);
}
Exemplo n.º 16
0
int
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
{
	struct cmd	*cmd;
	int		 n;

	TAILQ_FOREACH(cmd, cmdlist, qentry) {
		if ((n = cmd_exec(cmd, ctx)) != 0)
			return (n);
	}
	return (0);
}
Exemplo n.º 17
0
int shell(FILE * f, const char * (* prompt)(void), 
		  void (* greeting)(FILE *), 
		  const struct shell_cmd * cmd_tab)
{
	char hist_buf[SIZEOF_CMD_HISTORY + SHELL_HISTORY_MAX * SHELL_LINE_MAX];
	char line[SHELL_LINE_MAX];
	struct cmd_history * history;
	int ret = 0;

	DCC_LOG(LOG_TRACE, "history_init()");
	history = history_init(hist_buf, sizeof(hist_buf), SHELL_LINE_MAX);

	if (greeting)
		greeting(f);

	do {
		char * stat;
		char * cp;

		fprintf(f, "%s", prompt());

		if (history_readline(history, f, line, SHELL_LINE_MAX) == NULL)
			return -1;

		if ((cp = shell_stripline(line)) == NULL)
			continue;

		history_add(history, cp);

		cp = line;

		ret = 0;

		while ((stat = cmd_get_next(&cp)) != NULL) {
			struct shell_cmd * cmd;

			if ((cmd = cmd_lookup(cmd_tab, stat)) == NULL) {
				fprintf(f, "Command not found!\n");
				break;
			}

			ret = cmd_exec(f, cmd, stat);

			if ((ret < 0) && (ret !=  SHELL_ABORT)) {
				fprintf(f, "Error: %d\n", -ret);
				break;
			}
			
		}
	} while (ret != SHELL_ABORT); 

	return 0;
}
Exemplo n.º 18
0
/********************************************************************
 *	モニタコマンド受信と実行.
 ********************************************************************
 */
void ProcessIO(void)
{
	// 返答パケットが空であること、かつ、
	// 処理対象の受信データがある.
	{	//if((ToPcRdy == 0)) {
		//受信データがあれば、受信データを受け取る.
		PacketToPC.raw[0]=Cmd0;		// CMD ECHOBACK

#if	APPLICATION_MODE
#if	PICAVR_WRITER
		//コマンドに対応する処理を呼び出す.
			 if(Cmd0 >= HIDASP_PAGE_TX)  {cmd_avrspx();}	// AVRライターコマンド.
		else 
#endif
			 if(Cmd0 >= PICSPX_SETADRS24){cmd_picspx();}	// PICライターコマンド.
		else 
#endif

		switch(Cmd0) {
		 case HIDASP_PEEK: 		{cmd_peek();break;}	// メモリー読み出し.
		 case HIDASP_POKE: 		{cmd_poke();break;}	// メモリー書き込み.
		 case HIDASP_JMP: 		{cmd_exec(
		 						BSWAP32(PacketFromPC.adrs),BSWAP16(PacketFromPC.size)
		 			);
		 			break;}	// 実行.
		 case HIDASP_PAGE_ERASE:{cmd_page_erase();break;}	//Flash消去.
		 case HIDASP_PAGE_WRITE:{cmd_page_write();break;}	//Flash書込.
		 case HIDASP_FLASH_LOCK:{cmd_flash_lock();break;}	//FlashLock.
		 case HIDASP_SET_MODE:  {cmd_set_mode();break;}
		 case HIDASP_SAMPLING: 	{cmd_sampling();break;}
		 case HIDASP_TEST: 		{cmd_echo();break;}			// 接続テスト.

#if	APPLICATION_MODE
		 case HIDASP_GET_STRING:{cmd_get_string();break;}
		 case HIDASP_USER_CMD:  {cmd_user_cmd();break;}
#endif
		 default: break;
		}
	}

	// 必要なら、返答パケットをインタラプト転送(EP1)でホストPCに返却する.
	if( ToPcRdy ) {
		USBputpacket(PacketToPC.raw,PACKET_SIZE);
		ToPcRdy = 0;

		if(poll_mode!=0) {
			if(mHIDRxIsBusy()) {	//コマンドが来ない限り送り続ける.
				make_report();
			}
		}
	}
}
Exemplo n.º 19
0
void	cmd_server(t_cmd *c, t_req *r)
{
  int	pid;
  int	signal;

  if (!(pid = fork()))
    {
      write(1, PROMPT_RES, strlen(PROMPT_RES));
      cmd_exec(c, r);
      exit(0);
    }
  wait(&signal);
}
Exemplo n.º 20
0
static sw_error_t
cmd_run_one(char *cmd_str)
{
    a_uint32_t *arg_list;
    int cmd_index = 0, cmd_index_sub = 0;

    if ((arg_list = cmd_parse(cmd_str, &cmd_index, &cmd_index_sub)) != NULL)
    {
        cmd_exec(arg_list, cmd_index, cmd_index_sub);
    }

    return SW_OK;
}
Exemplo n.º 21
0
Arquivo: srv.c Projeto: m101/ihf
int main(int argc, char *argv[]) {
    struct ihf_msg *msg = NULL;
    uint8_t *req = NULL;
    int ret = 0;
    int len;

    req = malloc(sizeof(char) * BUFMAX);
    if (!req) {
        fprintf(stderr, "cannot allocate receiving request buffer !\n");
        ret = -1;
        goto exit;
    }
    len = read(STDIN_FILENO, req, BUFMAX);

    msg = msg_unpack(req, len);
    if (!msg) {
        fprintf(stderr, "error unpacking message\n");
        ret = -1;
        goto exit;
    }
    switch (msg->type) {
        case MSG_TYPE_INIT:
            cmd_init();
            break;
        case MSG_TYPE_KILL:
            cmd_kill();
            break;
        case MSG_TYPE_EXEC:
            cmd_exec(msg->arg, msg->arglen);
            break;
        case MSG_TYPE_READ:
            cmd_read();
            break;
        case MSG_TYPE_WRITE:
            cmd_write(msg->arg, msg->arglen);
            break;
        default:
            fprintf(stderr, "unknown request type %d\n", msg->type);
            ret = -1;
            goto exit;
    }

exit:
    if (req)
        free(req);
    if (msg)
        free(msg);

    return ret;
}
Exemplo n.º 22
0
static void loop()
{
	char *line;
	char *argv[SHELL_ARGS_MAX_NUM];
	int argc;

	while (!is_exit) {
		line = readline(CONFIG_PROMPT);
		argc = cmd_parse(line, argv, SHELL_ARGS_MAX_NUM);
		if (argc <= 0)
			continue;
		cmd_exec(argc, argv);
	}
}
Exemplo n.º 23
0
void cmd_system(int argc, char * argv[])
{
	pid_t fork_pid;
	
	signal(SIGCHLD, &sig_chld_ignore);
	if((fork_pid = fork()) != 0)
	{
		while(waitpid(fork_pid, NULL, WNOHANG) <= 0)
			usleep(300);
	} else {
		cmd_exec(argc, argv);
		exit(0);
	}
	signal(SIGCHLD, &sig_chld_waitpid);
}
Exemplo n.º 24
0
int system_start(void) {
	const char *command;
	char *argv[10];
	int argc;
	const struct cmd *cmd;

	setup_tty(OPTION_STRING_GET(tty_dev));

	array_foreach(command, script_commands, ARRAY_SIZE(script_commands)) {
		argc = cmdline_tokenize((char *)command, argv);
		if (0 == strncmp(argv[0], "pthread", 7)) {
			cmd = cmd_lookup(argv[1]);
			continue;
		}
		cmd = cmd_lookup(argv[0]);
		cmd_exec(cmd, argc, argv);
	}
Exemplo n.º 25
0
/**
 * Execute a command line and display its output.
 *
 * @param conn The connection to lldpd.
 * @param fmt  Output format.
 * @param line Line to execute.
 * @return -1 if an error occurred, 0 if nothing was executed. 1 otherwise.
 */
static int
parse_and_exec(lldpctl_conn_t *conn, const char *fmt, const char *line)
{
	int cargc = 0; char **cargv = NULL;
	int n;
	log_debug("lldpctl", "tokenize command line");
	n = tokenize_line(line, &cargc, &cargv);
	switch (n) {
	case -1:
		log_warnx("lldpctl", "internal error while tokenizing");
		return -1;
	case 1:
		log_warnx("lldpctl", "unmatched quotes");
		return -1;
	}
	if (cargc == 0) return 0;
	n = cmd_exec(conn, fmt, cargc, (const char **)cargv);
	tokenize_free(cargc, cargv);
	return (n == 0)?-1:1;
}
Exemplo n.º 26
0
int untar(char* path,char* untarPath){
	
	if(checkWritingFolder(untarPath)){
		char* str = (char*)leash_malloc(strlen("tar -zxf ")+strlen(path)+strlen(" -C ")+strlen(untarPath)+10);
		sprintf(str,"tar -zxf %s -C %s",path, untarPath);
		Cmd* cmdUntar = cmd_init(str);
		free(str);
		cmd_exec(cmdUntar);
		if(cmdUntar->result){
			printf("Erreur untar\n");
			exit(1);
		}
		cmd_dest(cmdUntar);
	}else{
		printf("folder read_only/not exists\n");
		return 3;
	}


	return 0;
}
Exemplo n.º 27
0
int start(int ac, char *av[])
{
  if(ac < 3) {
    usage();
    return 0;
  }

  char *cmd = av[1];
  ac-=2;
  av+=2;
  if(strncmp(cmd,"type",5)==0)
    return cmd_type(ac, av);
  if(strncmp(cmd,"dir",4)==0)
    return cmd_dir(ac, av);
  if(strncmp(cmd,"stat",5)==0)
    return cmd_stat(ac, av);
  if(strncmp(cmd,"exec",5)==0)
    return cmd_exec(ac, av);

  usage();
  return 0;
}
Exemplo n.º 28
0
Arquivo: eif.c Projeto: elijah/eif
/*************************************
 * eif_away
 *
 * The main routine.
 */
void
eif_away()
{

	/* Stuff for the readline. */
	(void) rl_unbind_key(17);	/* Ctrl-Q */
	(void) rl_unbind_key(19);	/* Ctrl-S */

	/* initialize signal handling */
	(void) signal(SIGQUIT, eif_sigdebug);	/* Debugging */

	(void) signal(SIGALRM, SIG_IGN);
	(void) signal(SIGPIPE, eif_pipe);

	(void) signal(SIGINT, eif_interrupt);

	/* We want ^C to abort system calls. */
	/* siginterrupt(SIGINT, 1); */

	prt("\nWelcome to EIF\n");
	prt("Empire Interface Version " VERSION "\n\n");

	/*
	 * The problem with this is that the file is not actually executed
	 * here.  It is executed in the commandloop(). This just sets it up
	 * for input as an exec file.
	 */
	if (cntl.st.readstartup) {
		cmd_exec(cntl.st.startupf, 2);
	}
	/* Only allow up to 100 commands in history */
	stifle_history(100);

	/* Install readline event hook */
	rl_event_hook = (Function *)event_hook;

	while (1)
		commandloop();
}
Exemplo n.º 29
0
/********************************************************************
 *	モニタコマンド受信と実行.
 ********************************************************************
 */
void ProcessIO(void)
{
	// 返答パケットが空であること、かつ、
	// 処理対象の受信データがある.
	if((ToPcRdy == 0) && (USBHandleBusy(USBGenericOutHandle)==0) ) {
		//受信データがあれば、受信データを受け取る.
		memcpy64((char*)&PacketFromPC,(char*)OUTPacket);
		//次の読み込みを発行する.
		USBGenericOutHandle = USBGenRead(USBGEN_EP_NUM,(BYTE*)&OUTPacket
							  ,USBGEN_EP_SIZE);

		PacketToPC.raw[0]=Cmd0;		// CMD ECHOBACK
		//コマンドに対応する処理を呼び出す.
		     if(Cmd0==HIDASP_PEEK) 	{cmd_peek();}	// メモリー読み出し.
		else if(Cmd0==HIDASP_POKE) 	{cmd_poke();}	// メモリー書き込み.
		else if(Cmd0==HIDASP_JMP) 	{cmd_exec();}	// 実行.
		else if(Cmd0==HIDASP_TEST) 	{cmd_echo();}	// 接続テスト.
		else if(Cmd0==HIDASP_GET_STRING){cmd_get_string();}
		else if(Cmd0==HIDASP_USER_CMD)  {cmd_user_cmd();}
		else if(Cmd0==HIDASP_SET_MODE)  {cmd_set_mode();}
	}

	// 必要なら、返答パケットをバルク転送(EP1)でホストPCに返却する.
	if( ToPcRdy ) {
		if(!USBHandleBusy(USBGenericInHandle)) {
			memcpy64(INPacket,(char*)&PacketToPC);
			USBGenericInHandle=USBGenWrite(USBGEN_EP_NUM,(BYTE*)INPacket,USBGEN_EP_SIZE);	
			ToPcRdy = 0;

			if(poll_mode!=0) {
				if( USBHandleBusy(USBGenericOutHandle) ) {//コマンドが来ない限り送り続ける.
					make_report();
				}
			}
		}
	}
}
Exemplo n.º 30
0
void
GameEvent(CORE_DATA *cd)
{
	switch (cd->event) {
	case EVENT_START:
		RegisterPlugin(OPENCORE_VERSION, CORE_NAME, "cycad", OPENCORE_VERSION, __DATE__, __TIME__, "core handler", 0, 0);
		register_commands();
		break;
	case EVENT_COMMAND:
		switch (cd->cmd_id) {
		case CMD_DIE: cmd_die(cd); break;
		case CMD_STOPBOT: cmd_stopbot(cd); break;
		case CMD_GETFILE: cmd_getfile(cd); break;
		case CMD_PUTFILE: cmd_putfile(cd); break;
		case CMD_LISTBOTS: cmd_listbots(cd); break;
		case CMD_TYPES: cmd_types(cd); break;
		case CMD_LOADTYPES: cmd_loadtypes(cd); break;
		case CMD_LOG: cmd_log(cd); break;
		case CMD_CMDLOG: cmd_cmdlog(cd); break;
		case CMD_ABOUT: cmd_about(cd); break;
		case CMD_INSLIB: cmd_inslib(cd); break;
		case CMD_RMLIB: cmd_rmlib(cd); break;
		case CMD_HELP: cmd_help(cd); break;
		case CMD_SYSINFO: cmd_sysinfo(cd); break;
		case CMD_LOADOPS: cmd_loadops(cd); break;
		case CMD_LISTOPS: cmd_listops(cd); break;
		case CMD_EXEC: cmd_exec(cd); break;
		case CMD_STARTBOT: cmd_startbot(cd); break;
		case CMD_GO: cmd_go(cd); break;
		default: break;
		}
		break;
	default:
		break;
	}
}