Exemplo n.º 1
0
/*
 * Take a line of input and process it, return TRUE if profanity is to
 * continue, FALSE otherwise
 */
gboolean
process_input(char *inp)
{
    log_debug("Input received: %s", inp);
    gboolean result = FALSE;
    g_strstrip(inp);

    // add line to history if something typed
    if (strlen(inp) > 0) {
        cmd_history_append(inp);
    }

    // just carry on if no input
    if (strlen(inp) == 0) {
        result = TRUE;

    // handle command if input starts with a '/'
    } else if (inp[0] == '/') {
        char *inp_cpy = strdup(inp);
        char *command = strtok(inp_cpy, " ");
        result = cmd_execute(command, inp);
        free(inp_cpy);

    // call a default handler if input didn't start with '/'
    } else {
        result = cmd_execute_default(inp);
    }

    ui_input_clear();
    roster_reset_search_attempts();

    return result;
}
Exemplo n.º 2
0
void serverlist_connect() {
    static char cmd[100];
    int i;
    for (i = 1; i < cmd_argc(); i++) {
        char *string = cmd_argv(i);
        int id = atoi(string);
        if (string[0] && id >= 0 && id < server_count) {
            sprintf(cmd, "connect %s %d", serverlist[id].address, serverlist[id].port);
            cmd_execute(cmd_client(), cmd);
        } else {
            ui_output(cmd_client(), "Invalid id: %d.\n", id);
        }
    }
}
Exemplo n.º 3
0
void
sock_recv_and_exec(int sock)
{
   char   msg[64];

   if(sock_recv_msg(sock, msg, sizeof(msg)) == -1)
      return;

   if(!strcmp(msg, VITUNES_RUNNING))
      return;

   if(!kb_execute_by_name(msg))
      cmd_execute(msg);
}
Exemplo n.º 4
0
/*
 * The common entry for processing command.
 */
static void
cmd_received(cmd_t *cmd, boolean_t *quit, struct timespec *timeout)
{
	boolean_t badcmd, execute;
	int cmd_id = CMD_ID(cmd);

	execute = B_TRUE;
	*quit = B_FALSE;

	switch (cmd_id) {
	case CMD_QUIT_ID:
		*quit = B_TRUE;
		return;

	case CMD_RESIZE_ID:
		/*
		 * The screen resize signal would trigger this
		 * command. Destroy existing screen and curses
		 * resources and then re-init the curses resources.
		 */
		win_fix_fini();
		page_win_destroy();
		reg_curses_fini();
		if (reg_curses_init(B_FALSE)) {
			win_fix_init();
		} else {
			execute = B_FALSE;
		}

		timeout_set(timeout, DISP_DEFAULT_INTVAL);
		break;

	case CMD_REFRESH_ID:
		/*
		 * User hit the hotkey 'R' to refresh current window.
		 */
		timeout_set(timeout, DISP_DEFAULT_INTVAL);
		break;
	}

	if (execute) {
		cmd_execute(cmd, &badcmd);
	}
}
Exemplo n.º 5
0
int main(int argc, char** argv) 
{ 
	char command[MAXLEN]; 
	char **arguments; 	

	
	while(1)
	{
		printf("5550558721 Supanat Potiwarakorn > ");
		if (fgets(command, MAXLEN, stdin) == '\n');
		if (tokenize(command, DELIMITERS, &arguments) < 0) { 
			fprintf(stderr, "Failed to parse command"); 
			exit(1); 
		}
		if (strcasecmp(arguments[0], "exit") == 0) exit(EXIT_SUCCESS); // exiting command
		cmd_execute(arguments); // create a new child process for execution
	}  

} 
Exemplo n.º 6
0
Arquivo: io.c Projeto: dpc/xmppconsole
int io_handle_enter(int x, int y) {
    char* line = NULL;

    line = rl_copy_text(0, rl_end);
    rl_set_prompt("");
    rl_replace_line("", 1);
    rl_redisplay();

    cmd_execute(line);

    if (strcmp(line, "") != 0) {
        add_history(line);
    }
    free(line);

    rl_set_prompt(prompt);
    rl_redisplay();

    /* force readline to think that the current line was "eaten" and executed */
    rl_done = 1;
    return 0;
}
Exemplo n.º 7
0
void launcher (char *commbuff, FlowSource_t *FlowSource, char *process, int expire) {
FlowSource_t	*fs;
struct sigaction act;
char 		*args[MAXARGS];
int 		pid, stat;
srecord_t	*InfoRecord;

	InfoRecord = (srecord_t *)commbuff;

	syslog(LOG_INFO, "Launcher: Startup. auto-expire %s", expire ? "enabled" : "off" );
	done = launch = child_exit = 0;

	// process may be NULL, if we only expire data files
	if ( process ) {
		char 		*cmd = NULL;
		srecord_t	TestRecord;
		// check for valid command expansion
		strncpy(TestRecord.fname, "test", FNAME_SIZE-1);
		TestRecord.fname[FNAME_SIZE-1] = 0;
		strncpy(TestRecord.tstring, "200407110845", 15);	
		TestRecord.tstring[15] = 0;
		TestRecord.tstamp = 1;

		fs = FlowSource;
		while ( fs ) {
			cmd = cmd_expand(&TestRecord, fs->Ident, fs->datadir, process);
			if ( cmd == NULL ) {
				syslog(LOG_ERR, "Launcher: ident: %s, Unable to expand command: '%s'", fs->Ident, process);
				exit(255);
			}

			fs = fs->next;
		}
	}

	/* Signal handling */
	memset((void *)&act,0,sizeof(struct sigaction));
	act.sa_handler = SignalHandler;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	sigaction(SIGCHLD, &act, NULL);	// child process terminated
	sigaction(SIGTERM, &act, NULL);	// we are done
	sigaction(SIGINT, &act, NULL);	// we are done
	sigaction(SIGHUP, &act, NULL);	// run command

	while ( !done ) {
		// sleep until we get signaled
		syslog(LOG_DEBUG, "Launcher: Sleeping");
		select(0, NULL, NULL, NULL, NULL);
		syslog(LOG_DEBUG, "Launcher: Wakeup");
		if ( launch ) {	// SIGHUP
			launch = 0;

			if ( process ) {
				char 		*cmd = NULL;

				fs = FlowSource;
				while ( fs ) {
					// Expand % placeholders
					cmd = cmd_expand(InfoRecord, fs->Ident, fs->datadir, process);
					if ( cmd == NULL ) {
						syslog(LOG_ERR, "Launcher: ident: %s, Unable to expand command: '%s'", fs->Ident, process);
						continue;
					}
					// printf("Launcher: run command: '%s'\n", cmd);
					syslog(LOG_DEBUG, "Launcher: ident: %s run command: '%s'", fs->Ident, cmd);

					// prepare args array
					cmd_parse(cmd, args);
					if ( args[0] )
						cmd_execute(args);

					// do not flood the system with new processes
					sleep(1);
					// else cmd_parse already reported the error
					free(cmd);
					fs = fs->next;
				}
			}

			fs = FlowSource;
			while ( fs ) {
				if ( expire ) 
					do_expire(fs->datadir);
				fs = fs->next;
			}
		}
		if ( child_exit ) {
			syslog(LOG_INFO, "laucher child exit %d childs.", child_exit);
			while ( (pid = waitpid (-1, &stat, WNOHANG)) > 0  ) {
				if ( WIFEXITED(stat) ) {
					syslog(LOG_DEBUG, "launcher child %i exit status: %i", pid, WEXITSTATUS(stat));
				}
				if (  WIFSIGNALED(stat) ) {
					syslog(LOG_WARNING, "laucher child %i died due to signal %i", pid, WTERMSIG(stat));
				}

				child_exit--;
			}
			syslog(LOG_INFO, "laucher waiting childs done. %d childs", child_exit);
			child_exit = 0;
		}
		if ( done ) {
			syslog(LOG_INFO, "Launcher: Terminating.");
		}
	}

	waitpid (-1, &stat, 0);

	// we are done
	syslog(LOG_INFO, "Launcher: exit.");

} // End of launcher
Exemplo n.º 8
0
static int main_cmd(int argc, char *argv[])
{
	if (argc < 1) {
		return help();
	}

	char *cmd = *argv++; argc--;

	if (contains(cmd, "key")) {
		if (argc < 2) {
			return help();
		}
		uint32_t lockkey = strtoul(argv[0], NULL, 0);
		hdhomerun_device_tuner_lockkey_use_value(hd, lockkey);

		cmd = argv[1];
		argv+=2; argc-=2;
	}

	if (contains(cmd, "get")) {
		if (argc < 1) {
			return help();
		}
		return cmd_get(argv[0]);
	}

	if (contains(cmd, "set")) {
		if (argc < 2) {
			return help();
		}
		return cmd_set(argv[0], argv[1]);
	}

	if (contains(cmd, "scan")) {
		if (argc < 1) {
			return help();
		}
		if (argc < 2) {
			return cmd_scan(argv[0], NULL);
		} else {
			return cmd_scan(argv[0], argv[1]);
		}
	}

	if (contains(cmd, "save")) {
		if (argc < 2) {
			return help();
		}
		return cmd_save(argv[0], argv[1]);
	}

	if (contains(cmd, "upgrade")) {
		if (argc < 1) {
			return help();
		}
		return cmd_upgrade(argv[0]);
	}

	if (contains(cmd, "execute")) {
		return cmd_execute();
	}

	return help();
}
Exemplo n.º 9
0
/** @brief Main loop.
 */
int main(void)
{
#ifdef INIT_CODE
  do{ INIT_CODE }while(0);
#endif

  /* interruptions not used, moving interrupt vector not needed
  IVCR = (1<<IVCE);
  IVCR = (1<<IVSEL);
   */

#ifdef ENABLE_UART
  // UART init (all values have been already computed)
  UBRRxH = UART_UBRR_VAL>>8;
  UBRRxL = UART_UBRR_VAL;
  UCSRxA = UART_U2X_VAL;
  UCSRxB = (1<<RXENx) | (1<<TXENx);
  UCSRxC = UART_NBITS_VAL | UART_PARITY_VAL | UART_STOP_BIT_VAL;
#endif
#ifdef ENABLE_I2C_SLAVE
  // I2C init
  TWAR = I2C_ADDR << 1;
  TWCR = (1<<TWIE)|(1<<TWEN)|(1<<TWINT)|(1<<TWEA);
#endif

#ifdef ENABLE_UART
  SEND_MESSAGE("boot ENTER");
#endif
  // timeout before booting
  uint8_t i = (BOOT_TIMEOUT)*F_CPU/(65536*4*1000);
  for(;;) {
    // detect activity from client
    // set the proto_* method if needed

    // from UART
#ifdef ENABLE_UART
    if( (UCSRxA & (1<<RXCx)) ) {
      // UART is the default for proto_*
      break;
    }
#endif

    // from I2C
#ifdef ENABLE_I2C_SLAVE
    if( (TWCR & (1<<TWINT)) ) {
#ifdef ENABLE_UART
      proto_send = i2cs_send;
      proto_recv = i2cs_recv;
#endif
      break;
    }
#endif

    if( i == 0 ) {
      boot(); // timeout
    }
    i--;
    _delay_loop_2(0); // 65536*4 cycles
  }

  for(;;) {
    const uint8_t c = recv_u8();
    if( c == 0x00 ) {
      continue; // null command: ignore
    } else if( c == 0xff ) {
      // failure command
      reply_failure();
    }
    else if( c == 'i' ) cmd_infos();
    else if( c == 'm' ) cmd_mirror();
#ifndef DISABLE_EXECUTE
    else if( c == 'x' ) cmd_execute();
#endif
#ifndef DISABLE_PROG_PAGE
    else if( c == 'p' ) cmd_prog_page();
#endif
#ifndef DISABLE_MEM_CRC
    else if( c == 'c' ) cmd_mem_crc();
#endif
#ifndef DISABLE_FUSE_READ
    else if( c == 'f' ) cmd_fuse_read();
#endif
#ifndef DISABLE_COPY_PAGES
    else if( c == 'y' ) cmd_copy_pages();
#endif
#ifdef ENABLE_I2C_MASTER
    else if( c == '<' ) cmd_i2c_recv();
    else if( c == '>' ) cmd_i2c_send();
#endif
    else {
      reply_error(STATUS_UNKNOWN_COMMAND);
    }
  }

  return 1;
}
Exemplo n.º 10
0
/* ARGSUSED */
static void *
disp_handler(void *arg)
{
	disp_flag_t flag;
	int status = 0;
	cmd_t cmd;
	boolean_t quit, pagelist_inited = B_FALSE;
	struct timespec timeout;
	uint64_t start_ms;
	int64_t diff_ms;

	/*
	 * Wait cons thread to complete initialization.
	 */
	if (!consthr_init_wait()) {
		debug_print(NULL, 2, "Timeout for waiting cons thread to "
		    "complete initialization\n");

		/*
		 * The cons thread should exit with error or startup failed,
		 * disp thread stops running.
		 */
		goto L_EXIT;
	}

	/*
	 * NumaTOP contains multiple windows. It uses double linked list
	 * to link all of windows.
	 */
	page_list_init();
	pagelist_inited = B_TRUE;

	timeout_set(&timeout, 0);
	start_ms = current_ms();

	for (;;) {
		status = 0;
		(void) pthread_mutex_lock(&s_disp_ctl.mutex);
		flag = s_disp_ctl.flag;
		while (flag == DISP_FLAG_NONE) {
			status = pthread_cond_timedwait(&s_disp_ctl.cond,
			    &s_disp_ctl.mutex, &timeout);
			flag = s_disp_ctl.flag;
			if (status == ETIMEDOUT) {
				break;
			}
		}

		if (flag == DISP_FLAG_CMD) {
			(void) memcpy(&cmd, &s_disp_ctl.cmd, sizeof (cmd));
		}

		s_disp_ctl.flag = DISP_FLAG_NONE;
		(void) pthread_mutex_unlock(&s_disp_ctl.mutex);

		diff_ms = current_ms() - start_ms;
		if (g_run_secs <= diff_ms / MS_SEC) {
			g_run_secs = TIME_NSEC_MAX;
			debug_print(NULL, 2,
			    "disp: it's time to exit\n");
			continue;
		}

		if ((status == ETIMEDOUT) && (flag == DISP_FLAG_NONE)) {
			if (page_current_get() == NULL) {
				timeout_set(&timeout, DISP_DEFAULT_INTVAL);
				continue;
			}

			/*
			 * Force a 'refresh' operation.
			 */
			CMD_ID_SET(&cmd, CMD_REFRESH_ID);
			cmd_execute(&cmd, NULL);
			timeout_set(&timeout, DISP_DEFAULT_INTVAL);
			continue;
		}

		switch (flag) {
		case DISP_FLAG_QUIT:
			debug_print(NULL, 2,
			    "disp: received DISP_FLAG_QUIT\n");
			goto L_EXIT;

		case DISP_FLAG_CMD:
			cmd_received(&cmd, &quit, &timeout);
			if (quit) {
				debug_print(NULL, 2,
				    "disp thread received CMD_QUIT_ID\n");
				goto L_EXIT;
			}
			break;

		case DISP_FLAG_PROFILING_DATA_READY:
		case DISP_FLAG_CALLCHAIN_DATA_READY:
		case DISP_FLAG_LL_DATA_READY:
		case DISP_FLAG_PQOS_CMT_READY:
			/*
			 * Show the page.
			 */
			(void) page_next_execute(B_FALSE);
			timeout_set(&timeout, DISP_DEFAULT_INTVAL);
			break;

		case DISP_FLAG_PROFILING_DATA_FAIL:
		case DISP_FLAG_CALLCHAIN_DATA_FAIL:
		case DISP_FLAG_LL_DATA_FAIL:
		case DISP_FLAG_PQOS_CMT_FAIL:
			/*
			 * Received the notification that the perf counting
			 * was failed.
			 */
			debug_print(NULL, 2,
			    "disp: profiling/callchain/LL data failed.\n");
			disp_go_home();
			break;

		case DISP_FLAG_SCROLLUP:
			/*
			 * User hits the "UP" key.
			 */
			key_scroll(SCROLL_UP);
			if (status == ETIMEDOUT) {
				timeout_set(&timeout, DISP_DEFAULT_INTVAL);
			}
			break;

		case DISP_FLAG_SCROLLDOWN:
			/*
			 * User hits the "DOWN" key.
			 */
			key_scroll(SCROLL_DOWN);
			if (status == ETIMEDOUT) {
				timeout_set(&timeout, DISP_DEFAULT_INTVAL);
			}
			break;

		case DISP_FLAG_SCROLLENTER:
			/*
			 * User selects a scroll item and hit the "ENTER".
			 */
			scroll_enter();
			if (status == ETIMEDOUT) {
				timeout_set(&timeout, DISP_DEFAULT_INTVAL);
			}
			break;

		default:
			break;
		}
	}

L_EXIT:
	if (pagelist_inited) {
		page_list_fini();
	}

	/*
	 * Let the perf thread exit first.
	 */
	perf_fini();

	debug_print(NULL, 2, "disp thread is exiting\n");
	return (NULL);
}
Exemplo n.º 11
0
int process_dcload_udp(ether_header_t *ether, ip_header_t *ip, udp_header_t *udp)
{
  ip_udp_pseudo_header_t *pseudo;
  unsigned short i;
  command_t *command;

  if (tool_ip && (tool_port != ntohs(udp->src) || tool_ip != ntohl(ip->src)))
    return -1;

  pseudo = (ip_udp_pseudo_header_t *)pkt_buf;
  pseudo->src_ip = ip->src;
  pseudo->dest_ip = ip->dest;
  pseudo->zero = 0;
  pseudo->protocol = ip->protocol;
  pseudo->udp_length = udp->length;
  pseudo->src_port = udp->src;
  pseudo->dest_port = udp->dest;
  pseudo->length = udp->length;
  pseudo->checksum = 0;
  memset(pseudo->data, 0, ntohs(udp->length) - 8 + (ntohs(udp->length)%2));
  memcpy(pseudo->data, udp->data, ntohs(udp->length) - 8);

  /* checksum == 0 means no checksum */
  if (udp->checksum != 0)
      i = checksum((unsigned short *)pseudo, (sizeof(ip_udp_pseudo_header_t) + ntohs(udp->length) - 9 + 1)/2);
  else
      i = 0;
  /* checksum == 0xffff means checksum was really 0 */
  if (udp->checksum == 0xffff)
      udp->checksum = 0;

  if (i != udp->checksum) {
/*    scif_puts("UDP CHECKSUM BAD\n"); */
    return -1;
  }

  if (!tool_ip) {
    printf("Set dc-tool IP to 0x%x, port %d\n", ntohl(ip->src), ntohs(udp->src));
    tool_ip = ntohl(ip->src);
    tool_port = ntohs(udp->src);
    memcpy(tool_mac, ether->src, 6);
  } else {
/*     if (tool_ip != ntohs(ip->src)) */
/*       return -1; */
  }

  make_ether(ether->src, ether->dest, (ether_header_t *)pkt_buf);

  command = (command_t *)udp->data;

/*   printf("Received command '%c%c%c%c'\n",  */
/* 	 command->id[0], */
/* 	 command->id[1], */
/* 	 command->id[2], */
/* 	 command->id[3]); */

  if (!memcmp(command->id, CMD_EXECUTE, 4)) {
      cmd_execute(ether, ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_REBOOT, 4)) {
      cmd_reboot(ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_LOADBIN, 4)) {
      cmd_loadbin(ip, udp, command);
  } else  
  if (!memcmp(command->id, CMD_PARTBIN, 4)) {
      cmd_partbin(ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_DONEBIN, 4)) {
      cmd_donebin(ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_SENDBINQ, 4)) {
      cmd_sendbinq(ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_SENDBIN, 4)) {
      cmd_sendbin(ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_VERSION, 4)) {
      cmd_version(ip, udp, command);
  } else
  if (!memcmp(command->id, CMD_RETVAL, 4)) {
      cmd_retval(ip, udp, command);
  } else {
    tool_ip = 0;
    return -1;
  }

  return 0;
}