Ejemplo n.º 1
0
/* apply command list in the command buffer to the active lines in a
   range; return false if error */
static bool exec_global( const char ** const ibufpp, const int gflags,
                         const bool interactive )
  {
  static char * buf = 0;
  static int bufsz = 0;
  const char * cmd = 0;

  if( !interactive )
    {
    if( traditional() && !strcmp( *ibufpp, "\n" ) )
      cmd = "p\n";			/* null cmd_list == `p' */
    else
      {
      if( !get_extended_line( ibufpp, 0, false ) ) return false;
      cmd = *ibufpp;
      }
    }
  clear_undo_stack();
  while( true )
    {
    const line_t * const lp = next_active_node();
    if( !lp ) break;
    set_current_addr( get_line_node_addr( lp ) );
    if( current_addr() < 0 ) return false;
    if( interactive )
      {
      /* print current_addr; get a command in global syntax */
      int len;
      if( !display_lines( current_addr(), current_addr(), gflags ) )
        return false;
      do { *ibufpp = get_tty_line( &len ); }
      while( *ibufpp && len > 0 && (*ibufpp)[len-1] != '\n' );
      if( !*ibufpp ) return false;
      if( len == 0 )
        { set_error_msg( "Unexpected end-of-file" ); return false; }
      if( len == 1 && !strcmp( *ibufpp, "\n" ) ) continue;
      if( len == 2 && !strcmp( *ibufpp, "&\n" ) )
        { if( !cmd ) { set_error_msg( "No previous command" ); return false; } }
      else
        {
        if( !get_extended_line( ibufpp, &len, false ) ||
            !resize_buffer( &buf, &bufsz, len + 1 ) ) return false;
        memcpy( buf, *ibufpp, len + 1 );
        cmd = buf;
        }
      }
    *ibufpp = cmd;
    while( **ibufpp ) if( exec_command( ibufpp, 0, true ) < 0 ) return false;
    }
  return true;
  }
Ejemplo n.º 2
0
/**
 * \fn void mainLoop ()
 * \brief mainLoop of smtp transaction
 */
void
mainLoop ()
{
  char client_commands[COMMAND_BUFFER_SIZE];
  for (;;)
    {
      while (fgets_timeout
	     (client_commands, COMMAND_BUFFER_SIZE - 1, stdin,
	      TIMEOUT_COMMAND) != 0)
	{
	  exec_command (client_commands);
	}
    }
}
Ejemplo n.º 3
0
/* ************************************************************************* *
 * 入力文字列の解析
 * ************************************************************************* */
int
parse_input (char *str) {
  char command[2];
  strncpy(command, str, 2);
  if (command[0] == '%') {
    subst(str, '\n', '\0');
    exec_command(command[1], str, str);
  } else {
    add_profile(&profile_data[nprofiles], str);
    nprofiles++;
    strcpy(str, "fileread success\n");
  }
  return 1;
}
bool nscapi::core_wrapper::exec_command(const std::string target, std::string request, std::string & result) const {
	char *buffer = NULL;
	unsigned int buffer_size = 0;
	bool retC = NSCAPI::api_ok(exec_command(target.c_str(), request.c_str(), static_cast<unsigned int>(request.size()), &buffer, &buffer_size));

	if (buffer_size > 0 && buffer != NULL) {
		result = std::string(buffer, buffer_size);
	}

	DestroyBuffer(&buffer);
	if (!retC) {
		CORE_LOG_ERROR("Failed to execute command on " + target);
	}
	return retC;
}
Ejemplo n.º 5
0
static int	initiate_env_command(char **bin_paths, char **command, char **env)
{
	char		*complete_cmd;
	int			i;

	i = 0;
	if (bin_paths)
		while (bin_paths[i])
		{
			complete_cmd = ft_join_paths(bin_paths[i], command[0]);
			if (access(complete_cmd, F_OK) == 0)
			{
				if (access(complete_cmd, X_OK) == 0)
					return (exec_command(complete_cmd, command, env));
				else
					return (catch_env_error(1, command[0]));
			}
			i++;
			free(complete_cmd);
		}
	else
		return (exec_command(command[0], &command[0], env));
	return (-1);
}
Ejemplo n.º 6
0
NSCAPI::nagiosReturn nscapi::core_wrapper::exec_command(const std::string target, std::string request, std::string & result) {
	char *buffer = NULL;
	unsigned int buffer_size = 0;
	NSCAPI::nagiosReturn retC = exec_command(target.c_str(), request.c_str(), static_cast<unsigned int>(request.size()), &buffer, &buffer_size);

	if (buffer_size > 0 && buffer != NULL) {
		result = std::string(buffer, buffer_size);
	}

	DestroyBuffer(&buffer);
	if (retC != NSCAPI::isSuccess) {
		CORE_LOG_ERROR("Failed to execute command on " + target + ": " + strEx::s::xtos(retC));
	}
	return retC;
}
Ejemplo n.º 7
0
static void
server (int sock)
{
    int command;

    msock = sock;
    quit_server = 0;

    check_version ();
    do {
	if (rpc_get (sock, RPC_INT, &command, RPC_END)
	    && (logged_in || command == MC_LOGIN))
	    exec_command (command);
    } while (!quit_server);
}
Ejemplo n.º 8
0
int stasis_app_send_command_async(struct stasis_app_control *control,
                                  stasis_app_command_cb command_fn, void *data)
{
    RAII_VAR(struct stasis_app_command *, command, NULL, ao2_cleanup);

    if (control == NULL) {
        return -1;
    }

    command = exec_command(control, command_fn, data);
    if (!command) {
        return -1;
    }

    return 0;
}
Ejemplo n.º 9
0
void *stasis_app_send_command(struct stasis_app_control *control,
	stasis_app_command_cb command_fn, void *data)
{
	RAII_VAR(struct stasis_app_command *, command, NULL, ao2_cleanup);

	if (control == NULL) {
		return NULL;
	}

	command = exec_command(control, command_fn, data);
	if (!command) {
		return NULL;
	}

	return command_join(command);
}
Ejemplo n.º 10
0
static int network_set_trigger(const struct iio_device *dev,
		const struct iio_device *trigger)
{
	int ret;
	char buf[1024];
	if (trigger)
		snprintf(buf, sizeof(buf), "SETTRIG %s %s\r\n",
				dev->id, trigger->id);
	else
		snprintf(buf, sizeof(buf), "SETTRIG %s\r\n", dev->id);

	network_lock(dev->ctx->pdata);
	ret = (int) exec_command(buf, dev->ctx->pdata->fd);
	network_unlock(dev->ctx->pdata);
	return ret;
}
Ejemplo n.º 11
0
static ssize_t write_rwbuf_command(const struct iio_device *dev,
		const char *cmd, bool do_exec)
{
	struct iio_device_pdata *pdata = dev->pdata;
	int fd = pdata->fd;

	if (pdata->wait_for_err_code) {
		ssize_t ret = read_error_code(fd);

		pdata->wait_for_err_code = false;
		if (ret < 0)
			return ret;
	}

	return do_exec ? exec_command(cmd, fd) : write_command(cmd, fd);
}
Ejemplo n.º 12
0
static int spawn_command(const char *file, char *const *av, char *const *envp)
{
    pid_t pid, wait_pid;
    int status;
    pid = fork();
    if (pid < 0) {
        return -1;              /* fork failed */
    }
    if (pid > 0) {              /* parent */
        status = 0;
        wait_pid = waitpid(pid, &status, 0);
        if (wait_pid == pid) {
            if (WIFEXITED(status))
                return WEXITSTATUS(status);
            else
                return INVALID_RET_INTR;
        } else {
            return -1;          /* some waitpid error */
        }
    } else {
        int f;
        /* somewhat random upper limit. ignore errors on purpose */
        for (f = 0; f < 256; f++)
            (void) fsync(f);

        if (exec_command(file, av, envp)) {
            /* let's hope no-one uses these values  */
            switch (errno) {
            case E2BIG:
                exit(INVALID_RET_E2BIG);
            case ETXTBSY:
                exit(INVALID_RET_ETXTBSY);
            case ENOENT:
                exit(INVALID_RET_ENOENT);
            case ENOEXEC:
                exit(INVALID_RET_ENOEXEC);
            case ENOMEM:
                exit(INVALID_RET_ENOMEM);
            default:
                exit(INVALID_RET_UNKNOWN);
            }
            return -1;
        }
    }
    return 0;
}
Ejemplo n.º 13
0
void
html_editor::insert_image()
{
  QString filters;
  filters += tr("Image files (*.png *.jpg *.jpeg *.gif)") + ";;";
  filters += tr("PNG files (*.png)") + ";;";
  filters += tr("JPEG files (*.jpg *.jpeg)") + ";;";
  filters += tr("GIF files (*.gif)") + ";;";
  filters += tr("All Files (*)");

  QString fname = QFileDialog::getOpenFileName(this, tr("Open image..."),
					       QString(), filters);
  if (!fname.isEmpty() && QFile::exists(fname)) {
    QUrl url = QUrl::fromLocalFile(fname);
    exec_command("insertImage", url.toString());
  }
}
Ejemplo n.º 14
0
void set_volume(int volume) {
	char *command[4];
	char *vol;
	int pid;

	command[0] = MIXER_COMMAND;
	command[1] = MIXER_OPT;
	command[2] = (char *) calloc(1, 4);
	command[3] = NULL;
	sprintf(command[2], "%d", volume);
	pid = exec_command(command);
	while (waitpid(pid, NULL, 0) != pid);
	free(command[2]);
	fprintf(lcddev, "\fVolume: %d", volume);
	fflush(lcddev);
	usleep(700000);
}
Ejemplo n.º 15
0
void	loop(t_all *all)
{
	char	*buff;

	buff = NULL;
	//f_cpy(all);
	while (1)
	{
		ft_putstr("$: ");
		if (get_next_line(0, &buff) == 0)
			return ;
		if (*buff == 4)
			free_all(all);
		all->cmd2exec = parse_command(buff);
		exec_command(all);
	}
}
Ejemplo n.º 16
0
int stasis_app_send_command_async(struct stasis_app_control *control,
	stasis_app_command_cb command_fn, void *data,
	command_data_destructor_fn data_destructor)
{
	RAII_VAR(struct stasis_app_command *, command, NULL, ao2_cleanup);

	if (control == NULL || control->is_done) {
		return -1;
	}

	command = exec_command(control, command_fn, data, data_destructor);
	if (!command) {
		return -1;
	}

	return 0;
}
Ejemplo n.º 17
0
static ssize_t network_read_attr_helper(const struct iio_device *dev,
		const struct iio_channel *chn, const char *attr, char *dst,
		size_t len, bool is_debug)
{
	long read_len;
	ssize_t ret;
	char buf[1024];
	struct iio_context_pdata *pdata = dev->ctx->pdata;
	int fd = pdata->fd;
	const char *id = dev->id;

	if (chn)
		snprintf(buf, sizeof(buf), "READ %s %s %s %s\r\n", id,
				chn->is_output ? "OUTPUT" : "INPUT",
				chn->id, attr ? attr : "");
	else if (is_debug)
		snprintf(buf, sizeof(buf), "READ %s DEBUG %s\r\n",
				id, attr ? attr : "");
	else
		snprintf(buf, sizeof(buf), "READ %s %s\r\n",
				id, attr ? attr : "");

	network_lock(pdata);
	read_len = exec_command(buf, fd);
	if (read_len < 0) {
		network_unlock(pdata);
		return (ssize_t) read_len;
	}

	if ((unsigned long) read_len > len) {
		ERROR("Value returned by server is too large\n");
		network_unlock(pdata);
		return -EIO;
	}

	ret = read_all(dst, read_len, fd);
	network_unlock(pdata);

	if (ret < 0) {
		iio_strerror(-ret, buf, sizeof(buf));
		ERROR("Unable to read response to READ: %s\n", buf);
		return ret;
	}

	return read_len;
}
Ejemplo n.º 18
0
u64 check_prog_version(char *prog)
{
    char stderrbuf[2048];
    char command[2048];
    char options[1024];
    char temp1[1024];
    char delims[]="\n\r";
    char *saveptr;
    char *result;
    int foundversion;
    int x, y, z;
    
    // init
    memset(options, 0, sizeof(options));
    memset(stderrbuf, 0, sizeof(stderrbuf));
    
    if (exec_command(command, sizeof(command), NULL, NULL, 0, stderrbuf, sizeof(stderrbuf), "%s -V", prog)!=0)
    {   errprintf("program %s was not found or has bad permissions.\n", prog);
        return -1;
    }
    
    foundversion=false;
    result=strtok_r(stderrbuf, delims, &saveptr);
    while (result != NULL && foundversion==false)
    {   if ((memcmp(result, prog, strlen(prog))==0))
            foundversion=true;
        else
            result = strtok_r(NULL, delims, &saveptr);
    }
    
    if (foundversion==false)
    {   errprintf("can't parse %s version number: no match\n", prog);
        return 0;
    }
    
    x=y=z=0;
    sscanf(result, "%s %d.%d.%d", temp1, &x, &y, &z);
    
    if (x==0 && y==0)
    {   errprintf("can't parse %s version number: x=y=0\n", prog);
        return 0;
    }
    
    return PROGVER(x,y,z);
}
Ejemplo n.º 19
0
int main(void)
{
	char line[MAXLINE];
	int i;
	char ** arglist;

	struct sigaction act;

	signal(SIGINT, SIG_IGN);	
	signal(SIGQUIT, SIG_IGN);
	signal(SIGTSTP, SIG_IGN);

	act.sa_handler = child_handler;
	sigfillset(&act.sa_mask);
	act.sa_flags = SA_RESTART;
	sigaction(SIGCHLD,&act,NULL);



	fputs("minishell> ",stdout);

	while(fgets(line,MAXLINE,stdin))
	{
		if(!strncmp(line,"exit",4))
		{
			exit(0);
		}

		if(arglist=command_parse(line))
		{
			if(!check_builtin(arglist))
			{
//				for(i=0;arglist[i];i++)
//				{
				//	printf("[%d] : %s\n", i,arglist[i]);
					exec_command(arglist);
//				}
			}	
			command_freelist(arglist);
		}

		fputs("minishell> ",stdout);
	}
	return 0;
}
Ejemplo n.º 20
0
int main(int argc, char * argv[]){
	while(1){                  // a loop
		//load FileSystem
		if(!lfs_load()){
			printf("loading errors!\n");
			exit(1);
		}
		
		//login

		//int login_status=-1;		// To record the login status of the file system
	

		if(lfs_login()!=1){
			printf("login errors"); 
			return 1;				// exit program
		}
		else
			show_welcome_messages();

		// load user data
		if(!lfs_usr_load()){
			printf("usr file loading errors!\n");
			exit(1);
		}
	
		//display tips for user how to use
		// exec commands
		int flag=1;  // temp value, you should make it global
		char command[50]="help";
		
		while(flag){
			printf("%s@root:~$ ",currUser);
			gets(command);
			flag=exec_command(command);
			if(!strcmp(currUser,"none"))               // when user logoff, prompt new login
				break;							
		}
	
		//store datas
		store_data();
	}

	return 0;
}
Ejemplo n.º 21
0
void		exec_multi_command(t_mysh *mysh, char *com)
{
  if (com)
    {
      mysh->tab_com = get_command(com);
      if (comp_str(com, "<<") || comp_str(com, ">>") || comp_str(com, "<")
	  || comp_str(com, ">") || comp_str(com, "|"))
	{
	  my_putstr("Ambiguous output redirect.\n");
	  clean_mem(mysh);
	  exit(42);
	}
      my_builtins(mysh);
      exec_command(mysh);
    }
  else
    clean_mem(mysh);
}
Ejemplo n.º 22
0
void command_prompt(void) {
    char input[MAX_INPUT];
    char *name;
    char *args[MAX_ARGS];
    int argc;
    int w;

    while (1) {
        puts(working_dir);
        puts(" >>> ");
        gets(input, MAX_INPUT);
        // Set not to wait if the first char of the input is '~'.
        w = input[0] != '~';
        // If set not to wait, ignore the first char of the input ('~').
        argc = w ? parse_input(input, &name, args) : parse_input(input + 1, &name, args);
        exec_command(name, argc, args, w);
    }
}
Ejemplo n.º 23
0
int parse_line(char *line)
{
  int cmd,std=1;
  char *param;
  
  if(*line == '%'){
    cmd = line[1];
    param = &line[3];
    exec_command(cmd,param);
  }else if(*line == '\0'){
    fprintf(stderr,"error: no input\n\n:");
    return 0;
  }else if(profile_data_nitems == MAX_PROFILES){
    fprintf(stderr,"error: over the limit of datas\n\n:");
  }else {
    new_profile(&profile_data_store[profile_data_nitems],line,std);
  }
  return 0;
}
Ejemplo n.º 24
0
int run_server()
{
	pid_t pid;


	//Fork
	pid = fork();

	if(pid == -1) {
		return -1;

	} else if(pid != 0) {
		//Parent process
		return pid;
	}

	//Child process
	//Replaces stdin stdou&stderr
	//stdin
	if(dup2(pipe_input[FD_READ], STDIN_FILENO) == -1) {
		exit(-1);
	}

	//stdout
	if(dup2(pipe_output[FD_WRITE], STDOUT_FILENO) == -1) {
		exit(-1);
	}

	//stderr
	if(dup2(pipe_output[FD_WRITE], STDERR_FILENO) == -1) {
		exit(-1);
	}

	//Change work directory
	if(chdir(server_dir) != 0) {
		exit(-1);
	}

	//Exec
	exec_command(server_cmd);
	exit(-1);
	return -1;
}
Ejemplo n.º 25
0
int main(int argc, char * argv[], char * envp[]){
  int exit_stat = 0;

  while(1){
    //read line of input
    char* input = readline("CSE451Shell\% ");
    if(!strcmp(input, "")){
      free(input);               
      continue;
    }
    //call exec_command with given input
    exit_stat = exec_command(input, exit_stat);
    free(input);    //free the input string
  }

  


  return 0;
}
Ejemplo n.º 26
0
int	exec_select_execution(t_node *node, t_global *global)
{
  int	status;

  if ((status = exec_select_execution_other(node, global)) >= EXIT_FAILURE)
    return (status);
  if (node->id == CMD)
    {
      if ((status = exec_command(node, global->env, global)) >= EXIT_FAILURE)
	return (status);
    }
  else if (node->id == S_RED_RIGHT || node->id == D_RED_RIGHT || \
	   node->id == S_RED_LEFT || node->id == D_RED_LEFT || \
	   node->id == S_RED_RIGHT_ERR || node->id == D_RED_RIGHT_ERR)
    {
      if ((status = exec_redirection(node, global, node->id)) >= EXIT_FAILURE)
	return (status);
    }
  return (EXIT_SUCCESS);
}
Ejemplo n.º 27
0
static void bridge_after_cb(struct ast_channel *chan, void *data)
{
	struct stasis_app_control *control = data;
	SCOPED_AO2LOCK(lock, control);

	ast_debug(3, "%s, %s: Channel leaving bridge\n",
		ast_channel_uniqueid(chan), control->bridge->uniqueid);

	ast_assert(chan == control->channel);

	/* Restore the channel's PBX */
	ast_channel_pbx_set(control->channel, control->pbx);
	control->pbx = NULL;

	/* No longer in the bridge */
	control->bridge = NULL;

	/* Wakeup the command_queue loop */
	exec_command(control, NULL, NULL);
}
Ejemplo n.º 28
0
int	my_script_command(char *command)
{
  int	fd_file;
  char	buff[512];
  time_t	date;

  fd_file = xopen("typescript", O_WRONLY | O_CREAT | O_TRUNC, 0644);
  printf("Script started, file is typescript\n");
  time(&date);
  strcpy(buff, "Script started on ");
  strcat(buff, ctime(&date));
  xwrite(fd_file, buff, strlen(buff));
  exec_command(command);
  printf("Script done, file is typescript\n");
  strcpy(buff, "Script done on ");
  strcat(buff, ctime(&date));
  xwrite(fd_file, buff, strlen(buff));
  xclose(fd_file);
  return (EXIT_SUCCESS);
}
Ejemplo n.º 29
0
int		redir_to(int idx_cmd, t_group *grp)
{
	t_redir *curr;
	int		exec;
	int		redir_all;

	curr = grp->sh_cmd[idx_cmd];
	exec = false;
	while (curr != NULL)
	{
		if (curr->symbol && curr->symbol[0] == '>')
		{
			redir_all = (ft_strcmp(curr->symbol, ">&") == 0) ||
			(ft_strcmp(curr->symbol, ">>&") == 0) ? 1 : 0;
			exec = exec_command(curr->fd, grp, redir_all);
		}
		curr = curr->next;
	}
	return (exec);
}
Ejemplo n.º 30
0
static int network_open(const struct iio_device *dev,
		size_t samples_count, bool cyclic)
{
	struct iio_context_pdata *pdata = dev->ctx->pdata;
	char buf[1024], *ptr;
	size_t i;
	int ret, fd;

	if (dev->pdata->fd >= 0)
		return -EBUSY;

	fd = create_socket(pdata->addrinfo);
	if (fd < 0)
		return fd;

	snprintf(buf, sizeof(buf), "OPEN %s %lu ",
			dev->id, (unsigned long) samples_count);
	ptr = buf + strlen(buf);

	for (i = dev->words; i > 0; i--) {
		snprintf(ptr, (ptr - buf) + i * 8, "%08x", dev->mask[i - 1]);
		ptr += 8;
	}

	strcpy(ptr, cyclic ? " CYCLIC\r\n" : "\r\n");

	network_lock_dev(dev->pdata);
	ret = (int) exec_command(buf, fd);
	network_unlock_dev(dev->pdata);

	if (ret < 0) {
		close(fd);
		return ret;
	}

	dev->pdata->is_tx = iio_device_is_tx(dev);
	dev->pdata->is_cyclic = cyclic;
	dev->pdata->fd = fd;
	dev->pdata->wait_for_err_code = false;
	return 0;
}