Esempio n. 1
0
ATF_TC_BODY(exec_exitstatus, tc)
{
    {
        atf_check_result_t result;
        do_exec(tc, "exit-success", &result);
        ATF_CHECK(atf_check_result_exited(&result));
        ATF_CHECK(!atf_check_result_signaled(&result));
        ATF_CHECK(atf_check_result_exitcode(&result) == EXIT_SUCCESS);
        atf_check_result_fini(&result);
    }

    {
        atf_check_result_t result;
        do_exec(tc, "exit-failure", &result);
        ATF_CHECK(atf_check_result_exited(&result));
        ATF_CHECK(!atf_check_result_signaled(&result));
        ATF_CHECK(atf_check_result_exitcode(&result) == EXIT_FAILURE);
        atf_check_result_fini(&result);
    }

    {
        atf_check_result_t result;
        do_exec(tc, "exit-signal", &result);
        ATF_CHECK(!atf_check_result_exited(&result));
        ATF_CHECK(atf_check_result_signaled(&result));
        ATF_CHECK(atf_check_result_termsig(&result) == SIGKILL);
        atf_check_result_fini(&result);
    }
}
Esempio n. 2
0
static int swapsystem(char *cmd)
{
	char	*prog, *args;
	int	retcode;

	for (; elvspace(*cmd); cmd++)
	{
	}
	prog = safedup(cmd);
	for (args = prog; *args && !elvspace(*args); args++)
	{
	}
	if (*args)
		*args++ = '\0';
	retcode = do_exec(prog, args, USE_ALL|HIDE_FILE, 0xFFFF, NULL);
	if (retcode == RC_NOFILE)
	{
		safefree(prog);
		prog = safealloc(strlen(cmd) + 4, sizeof(char));
		strcpy(prog, "/c ");
		strcat(prog, cmd);
		retcode = do_exec(tochar8(o_shell), prog,
					USE_ALL|HIDE_FILE, 0xFFFF, NULL);
	}
	safefree(prog);
	return retcode;
}
Esempio n. 3
0
int
execvpe(const char* file, char* const argv[], char* const environment[])
{
	// let do_exec() handle cases where file is a path (or invalid)
	if (file == NULL || strchr(file, '/') != NULL)
		return do_exec(file, argv, environment, true);

	// file is just a leaf name, so we have to look it up in the path

	// get the PATH
	const char* paths = getenv("PATH");
	if (paths == NULL) {
		__set_errno(B_ENTRY_NOT_FOUND);
		return -1;
	}

	int fileNameLen = strlen(file);

	// iterate through the paths
	const char* pathEnd = paths - 1;
	while (pathEnd != NULL) {
		paths = pathEnd + 1;
		pathEnd = strchr(paths, ':');
		int pathLen = (pathEnd ? pathEnd - paths : strlen(paths));

		// We skip empty paths and those that would become too long.
		// The latter is not really correct, but practically irrelevant.
		if (pathLen == 0
			|| pathLen + 1 + fileNameLen >= B_PATH_NAME_LENGTH) {
			continue;
		}

		// concatinate the program path
		char path[B_PATH_NAME_LENGTH];
		memcpy(path, paths, pathLen);
		path[pathLen] = '\0';

		if (path[pathLen - 1] != '/')
			strcat(path, "/");
		strcat(path, file);

		// check whether it is a file
		struct stat st;
		if (stat(path, &st) != 0 || !S_ISREG(st.st_mode))
			continue;

		// if executable, execute it
		if (access(path, X_OK) == 0)
			return do_exec(path, argv, environment, true);
	}

	__set_errno(B_ENTRY_NOT_FOUND);
	return -1;
}
Esempio n. 4
0
void program_thread(void *data) {
  exec_args_t exec_args;
  switch ((int)data) {
  case 1:
    exec_args.prog_name = "prog";
    exec_args.argv = (char *[]){"argument1", "ARGUMENT2", "a-r-g-u-m-e-n-t-3"};
    exec_args.argc = 3;
    do_exec(&exec_args);
  case 2:
    exec_args.prog_name = "prog";
    exec_args.argv = (char *[]){"String passed as argument."};
    exec_args.argc = 1;
    do_exec(&exec_args);
  case 3:
    exec_args.prog_name = "prog";
    exec_args.argv = (char *[]){"abort_test"};
    exec_args.argc = 1;
    do_exec(&exec_args);
  }
}

int main() {
  /* This is a simple demonstration of the exec functionality. It
   * requests to substitute current thread's image with program
   * called "prog", which is implemented in ./user/prog.c, and after
   * compilation embedded in the kernel image.

   * As the loaded program has no means to communicate with the
   * system, because system calls are not yet implemented, it runs
   * quietly. To test its behavior with a debugger, after starting
   * gdb issue the command:
   *    add-symbol-file user/prog.uelf 0x00400000
   * which will load the symbols for the user program. You may then
   * e.g. break at its main(), and see that argc and argv are set
   * correctly. If you let it run further, you may `print textarea`
   * to see that it accesses a string in .data and copies it to
   * .bss.
   */

  thread_t *td1 = thread_create("user_thread1", program_thread, (void *)1);
  thread_t *td2 = thread_create("user_thread2", program_thread, (void *)2);
  thread_t *td3 = thread_create("user_thread3", program_thread, (void *)3);

  sched_add(td1);
  sched_add(td2);
  sched_add(td3);

  sched_run();

  return 0;
}
Esempio n. 5
0
/*===========================================================================*
 *				sys_task				     *
 *===========================================================================*/
PUBLIC void sys_task()
{
/* Main entry point of sys_task.  Get the message and dispatch on type. */

  register int r;

  while (TRUE) {
	receive(ANY, &m);

	switch (m.m_type) {	/* which system call */
	    case SYS_FORK:	r = do_fork(&m);	break;
	    case SYS_NEWMAP:	r = do_newmap(&m);	break;
	    case SYS_EXEC:	r = do_exec(&m);	break;
	    case SYS_XIT:	r = do_xit(&m);		break;
	    case SYS_GETSP:	r = do_getsp(&m);	break;
	    case SYS_TIMES:	r = do_times(&m);	break;
	    case SYS_ABORT:	r = do_abort(&m);	break;
#if (CHIP == M68000)
	    case SYS_FRESH:	r = do_fresh(&m);	break;
#endif
	    case SYS_SIG:	r = do_sig(&m);		break;
	    case SYS_KILL:	r = do_kill(&m);	break;
	    case SYS_COPY:	r = do_copy(&m);	break;
	    case SYS_GBOOT:	r = do_gboot(&m);	break;
	    case SYS_UMAP:	r = do_umap(&m);	break;
	    case SYS_MEM:	r = do_mem(&m);		break;
	    case SYS_TRACE:	r = do_trace(&m);	break;
	    default:		r = E_BAD_FCN;
	}

	m.m_type = r;		/* 'r' reports status of call */
	send(m.m_source, &m);	/* send reply to caller */
  }
}
Esempio n. 6
0
File: exec.c Progetto: Cougar/pwm
void wm_exec(const char *cmd)
{
	int pid;
	char *tmp;
	int tmp_len;

	pid=fork();
	
	if(pid<0)
		warn_err();
	
	if(pid!=0)
		return;
	
	setup_environ(SCREEN->xscr);
	
	close(wglobal.conn);
	
	tmp_len = strlen(cmd)+8;
	tmp=ALLOC_N(char, tmp_len);
	
	if(tmp==NULL)
		die_err();
	
	snprintf(tmp, tmp_len, "exec %s", cmd);
	
	do_exec(tmp);
}
Esempio n. 7
0
void do_fork_exec(char *cmdline, int *pid, int *stdin_fd, int *stdout_fd,
		  int *stderr_fd)
{
	int inpipe[2], outpipe[2], errpipe[2];

	if (pipe(inpipe) || pipe(outpipe) || (stderr_fd && pipe(errpipe))) {
		perror("pipe");
		exit(1);
	}
	switch (*pid = fork()) {
	case -1:
		perror("fork");
		exit(-1);
	case 0:
		if (stderr_fd) {
			fix_fds(inpipe[0], outpipe[1], errpipe[1]);
		} else
			fix_fds(inpipe[0], outpipe[1], 2);

		do_exec(cmdline);
		exit(-1);
	default:;
	}
	close(inpipe[0]);
	close(outpipe[1]);
	*stdin_fd = inpipe[1];
	*stdout_fd = outpipe[0];
	if (stderr_fd) {
		close(errpipe[1]);
		*stderr_fd = errpipe[0];
	}
}
Esempio n. 8
0
/*===========================================================================*
 *				sys_task				     *
 *===========================================================================*/
PUBLIC sys_task()
{
/* Main entry point of sys_task.  Get the message and dispatch on type. */

  register int r;

  while (TRUE) {
	receive(ANY, &m);

	switch (m.m_type) {	/* which system call */
	    case SYS_FORK:	r = do_fork(&m);	break;
	    case SYS_NEWMAP:	r = do_newmap(&m);	break;
	    case SYS_EXEC:	r = do_exec(&m);	break;
	    case SYS_XIT:	r = do_xit(&m);		break;
	    case SYS_GETSP:	r = do_getsp(&m);	break;
	    case SYS_TIMES:	r = do_times(&m);	break;
	    case SYS_ABORT:	r = do_abort(&m);	break;
	    case SYS_SIG:	r = do_sig(&m);		break;
	    case SYS_COPY:	r = do_copy(&m);	break;
	    default:		r = E_BAD_FCN;
	}

	m.m_type = r;		/* 'r' reports status of call */
	send(m.m_source, &m);	/* send reply to caller */
  }
}
Esempio n. 9
0
void init_user() {
    //test_file();
    do_exec("/home/init", NULL);
    while(1) {
        ;
    }
}
Esempio n. 10
0
static ERL_NIF_TERM
evaluate_command(esqlite_command *cmd, esqlite_connection *conn)
{
    switch(cmd->type) {
    case cmd_open:
	    return do_open(cmd->env, conn, cmd->arg);
    case cmd_exec:
	    return do_exec(cmd->env, conn, cmd->arg);
    case cmd_changes:
	    return do_changes(cmd->env, conn, cmd->arg);
    case cmd_prepare:
	    return do_prepare(cmd->env, conn, cmd->arg);
    case cmd_step:
	    return do_step(cmd->env, conn->db, cmd->stmt);
    case cmd_reset:
	    return do_reset(cmd->env, conn->db, cmd->stmt);
    case cmd_bind:
	    return do_bind(cmd->env, conn->db, cmd->stmt, cmd->arg);
    case cmd_column_names:
	    return do_column_names(cmd->env, cmd->stmt);
    case cmd_close:
	    return do_close(cmd->env, conn, cmd->arg);
	case cmd_insert:
	    return do_insert(cmd->env, conn, cmd->arg);
    default:
	    return make_error_tuple(cmd->env, "invalid_command");
    }
}
process_rq( char *rq, int fd )
{
	char	cmd[BUFSIZ], arg[BUFSIZ];
	int 	whatiscmd = 0;

	/* create a new process and return if not the child */
	if ( fork() != 0 )
		return;

	strcpy(arg, "./");		/* precede args with ./ */
	if ( sscanf(rq, "%s%s", cmd, arg+2) != 2 )
		return;

	if ( strcmp(cmd,"GET") == 0 )
		whatiscmd=0;
	else if (strcmp(cmd,"HEAD") == 0 )
		whatiscmd=1;
	else
		printf("That command is not yet implemented\n");


	switch (whatiscmd){

		case 0:
			do_exec( arg, fd );
			break;
		case 1:

			do_exec1( arg, fd );
			break;
		default:
			printf("That command is not yet implemented\n");
}

}
Esempio n. 12
0
int do_proc_op(void *t, int proc_id)
{
	struct task_struct *task;
	struct thread_struct *thread;
	int op, pid;

	task = t;
	thread = &task->thread;
	op = thread->request.op;
	switch(op){
	case OP_NONE:
	case OP_TRACE_ON:
		break;
	case OP_EXEC:
		pid = thread->request.u.exec.pid;
		do_exec(thread->mode.tt.extern_pid, pid);
		thread->mode.tt.extern_pid = pid;
		cpu_tasks[task_thread_info(task)->cpu].pid = pid;
		break;
	case OP_FORK:
		attach_process(thread->request.u.fork.pid);
		break;
	case OP_CB:
		(*thread->request.u.cb.proc)(thread->request.u.cb.arg);
		break;
	case OP_REBOOT:
	case OP_HALT:
		break;
	default:
		tracer_panic("Bad op in do_proc_op");
		break;
	}
	thread->request.op = OP_NONE;
	return(op);
}
Esempio n. 13
0
int do_log(int nargs, char **args)
{
    char* par[nargs+3];
    char* value;
    int i;

    par[0] = "exec";
    par[1] = "/system/bin/log";
    par[2] = "-tinit";
    for (i = 1; i < nargs; ++i) {
        value = args[i];
        if (value[0] == '$') {
            /* system property if value starts with '$' */
            value++;
            if (value[0] != '$') {
                value = (char*) property_get(value);
                if (!value) value = args[i];
            }
        }
        par[i+2] = value;
    }
    par[nargs+2] = NULL;

    return do_exec(nargs+2, par);
}
Esempio n. 14
0
File: eval.c Progetto: S010/misc
struct expr    *
exec(struct expr * e, struct context * ctx)
{
	struct expr    *a, *re;
	struct args     args;
	struct list    *l;

	if (!e || list_len(e) < 2) {
		free_expr(e);
		return empty_list();
	}
	memset(&args, 0, sizeof(args));
	for (l = e->v.list->next; l != NULL; l = l->next) {
		a = eval(l->v, ctx);
		build_argv(a, &args);
		full_free_expr(a);
	}

	re = do_exec(&args);

	free_expr(e);
	free_args(&args);

	return re;
}
Esempio n. 15
0
File: t.c Progetto: B-Rich/CptS460
/****************** syscall handler in C ***************************/
int kcinth()
{
    u16    segment, offset;
    int    a,b,c,d, r;
    segment = running->uss; 
    offset = running->usp;

    /** get syscall parameters from ustack **/
    a = get_word(segment, offset + 2*PA);
    b = get_word(segment, offset + 2*PB);
    c = get_word(segment, offset + 2*PC);
    d = get_word(segment, offset + 2*PD);

    // UNCOMMENT TO SEE syscalls into kernel
    // printf("proc%d syscall a=%d b=%d c=%d d=%d\n", running->pid, a,b,c,d);

    switch(a){
        case 0 : r = running->pid;     break;
        case 1 : r = do_ps();          break;
        case 2 : r = chname(b);        break;
        case 3 : r = kmode();          break;
        case 4 : r = tswitch();        break;
        case 5 : r = do_wait(b);       break;
        case 6 : r = do_exit(b);       break;
        case 7 : r = do_fork();        break;
        case 8 : r = do_exec(b);       break;

        case 90: r =  getc();          break;
        case 91: r =  putc(b);         break;       
        case 99: do_exit(b);           break;
        default: printf("invalid syscall # : %d\n", a); 
    }
    put_word(r, segment, offset + 2*AX);
}
Esempio n. 16
0
static void
start_next_task (System *system)
{
  unsigned task_index = system->n_finished_tasks + system->n_running_tasks;
  int stderr_pipe[2], stdout_pipe[2], stdin_pipe[2];
  int pid;
  Task *task = system->tasks->pdata[task_index];
  g_assert (task->state == TASK_WAITING);

  do_pipe (stdin_pipe);
  do_pipe (stdout_pipe);
  do_pipe (stderr_pipe);

retry_fork:
  pid = fork ();
  if (pid < 0)
    {
      if (errno == EINTR)
        goto retry_fork;
      else
        g_error ("error forking");
    }
  else if (pid == 0)
    {
      /* child process */
      dup2 (stdin_pipe[0], STDIN_FILENO);
      dup2 (stdout_pipe[1], STDOUT_FILENO);
      dup2 (stderr_pipe[1], STDERR_FILENO);
      do_exec (task->str);
      _exit (127);
    }

  /* parent process */
  close (stdin_pipe[0]);
  close (stdout_pipe[1]);
  close (stderr_pipe[1]);
  task->state = TASK_RUNNING;
  system->n_unstarted_tasks--;
  system->n_running_tasks++;
  task->info.running.pid = pid;
  task->info.running.stdin_fd = stdin_pipe[1];
  task->info.running.stdin_source = NULL;
  task->info.running.stdout_fd = stdout_pipe[0];
  task->info.running.stdout_source = NULL;
  task->info.running.stderr_fd = stderr_pipe[0];
  task->info.running.stderr_source = NULL;
  task->info.running.stdin_output_buffer = g_byte_array_new ();
  task->info.running.stdout_input_buffer = g_byte_array_new ();
  task->info.running.stderr_input_buffer = g_byte_array_new ();
  task->info.running.stdout_source = g_source_fd_new (task->info.running.stdout_fd, G_IO_IN, handle_stdout_readable, task);
  task->info.running.stderr_source = g_source_fd_new (task->info.running.stderr_fd, G_IO_IN, handle_stderr_readable, task);
  g_child_watch_add (pid, handle_child_watch_terminated, task);
  GTimeVal cur_time;
  g_get_current_time (&cur_time);
  SystemTrap *trap;
  for (trap = task->system->trap_list; trap; trap = trap->next)
    if (trap->funcs->handle_started)
      trap->funcs->handle_started (task, &cur_time, task->str, trap->trap_data);
}
Esempio n. 17
0
/*
 * Return value is kept in the same buf.
 */
void msg_exec(message_t msg)
{
	/*
	 * Return value is kept in the same buf.
	 */
	msg->w1 = do_exec(msg->tid, (char *)msg->snd_ptr, (struct vn_object *)msg->rcv_ptr);
	reply_message(msg->tid, msg);
}
Esempio n. 18
0
ATF_TC_BODY (exec_success, tc)
{
    atf_process_status_t status;

    do_exec (tc, "exit-success", &status);
    ATF_CHECK (atf_process_status_exited (&status));
    ATF_CHECK_EQ (atf_process_status_exitstatus (&status), EXIT_SUCCESS);
    atf_process_status_fini (&status);
}
Esempio n. 19
0
ATF_TC_BODY (exec_failure, tc)
{
    atf_process_status_t status;

    do_exec (tc, "exit-failure", &status);
    ATF_CHECK (atf_process_status_exited (&status));
    ATF_CHECK_EQ (atf_process_status_exitstatus (&status), EXIT_FAILURE);
    atf_process_status_fini (&status);
}
Esempio n. 20
0
void start(uint16_t arg)
{
        init_tarfs();
        tarfs_dir();

        do_exec("bin/shell");

        while(TRUE)     
	  Yield();
}
Esempio n. 21
0
int main() {
  exec_args_t exec_args;
  exec_args.prog_name = "fd_test";
  exec_args.argv = (char *[]){"fd_test"};
  exec_args.argc = 1;

  do_exec(&exec_args);

  return 0;
}
Esempio n. 22
0
int sys_execve(char __user *filename,
	       char __user **argv,
	       char __user **envp)
{
	int ret = 0;
	pt_regs *regs = get_pt_regs();

	ret = do_exec(filename, argv, envp, regs);
	if (!ret)
		ret = regs->r0;

	return ret;
}
Esempio n. 23
0
File: exec.c Progetto: jmgc/noah
int
load_script(const char *script, size_t len, const char *elf_path, int argc, char *argv[], char **envp)
{
  const char *script_end = script + len;
  char sb_argv[SB_ARGC_MAX][LINUX_PATH_MAX];
  int sb_argc;
  size_t n;

  script += 2;                  /* skip shebang */

  for (sb_argc = 0; sb_argc < SB_ARGC_MAX; ++sb_argc) {
    while (isspace(*script) && *script != '\n') {
      if (script == script_end)
        goto parse_end;
      script++;
    }

    for (n = 0; ! isspace(script[n]); ++n) {
      if (script + n == script_end)
        goto parse_end;
    }
    if (n == 0) {
      goto parse_end;
    }
    if (n > LINUX_PATH_MAX - 1) {
      return -LINUX_ENAMETOOLONG;
    }
    strncpy(sb_argv[sb_argc], script, n);
    sb_argv[sb_argc][n] = 0;

    script += n;                /* skip interp */
  }

 parse_end:
  if (sb_argc == 0) {
    return -LINUX_EFAULT;
  }

  int newargc = sb_argc + argc;
  char *newargv[newargc];
  for (int i = 0; i < sb_argc; ++i) {
    newargv[i] = sb_argv[i];
  }
  newargv[sb_argc] = elf_path;
  memcpy(newargv + sb_argc + 1, argv + 1, (argc - 1) * sizeof(char *));

  do_exec(newargv[0], newargc, newargv, envp);

  return 0;
}
int cmd(string str) {
  string err;

  mixed ret = do_exec(str, ref err);
  if (err == "fail")
    return 0;
  if (err == 0) {
    this_player()->more_string(sprintf("\nReturns: %O\n", ret),
                               "Exec results");
  } else {
    printf("Exec failed: %s", err);
  }
  return 1;
}
Esempio n. 25
0
static bool systemInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args,
	uint32_t argCount, NPVariant *variant)
{

	if (name == systemMethodIdentifiers[SYSTEM_METHOD_EXEC]) {
		if (argCount != 1) {
			fprintf(stderr, "%s: bad arguments", prog);
			return false;
		}
		return do_exec(args[0], variant);
	}

	return false;
}
Esempio n. 26
0
int main(int argc, char *argv[])
{
	if (argc == 3 && !strcmp(argv[1], "exec")) {
		unsigned long parent_dscr;

		parent_dscr = atoi(argv[2]);
		do_exec(parent_dscr);
	} else if (argc != 1) {
		fprintf(stderr, "Usage: %s\n", argv[0]);
		exit(1);
	}

	prog = argv[0];
	return test_harness(dscr_inherit_exec, "dscr_inherit_exec_test");
}
Esempio n. 27
0
/* Spawn a new process and immediately detach from it.  The name of
   the program to exec is PGMNAME and its arguments are in ARGV (the
   programname is automatically passed as first argument).
   Environment strings in ENVP are set.  An error is returned if
   pgmname is not executable; to make this work it is necessary to
   provide an absolute file name.  All standard file descriptors are
   connected to /dev/null. */
gpg_error_t
gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
                              const char *envp[] )
{
    pid_t pid;
    int i;

    if (getuid() != geteuid())
        return gpg_error (GPG_ERR_BUG);

    if (access (pgmname, X_OK))
        return gpg_error_from_syserror ();

    pid = fork ();
    if (pid == (pid_t)(-1))
    {
        log_error (_("error forking process: %s\n"), strerror (errno));
        return gpg_error_from_syserror ();
    }
    if (!pid)
    {
        pid_t pid2;

        gcry_control (GCRYCTL_TERM_SECMEM);
        if (setsid() == -1 || chdir ("/"))
            _exit (1);

        pid2 = fork (); /* Double fork to let init take over the new child. */
        if (pid2 == (pid_t)(-1))
            _exit (1);
        if (pid2)
            _exit (0);  /* Let the parent exit immediately. */

        if (envp)
            for (i=0; envp[i]; i++)
                putenv (xstrdup (envp[i]));

        do_exec (pgmname, argv, -1, -1, -1, NULL);

        /*NOTREACHED*/
    }

    if (waitpid (pid, NULL, 0) == -1)
        log_error ("waitpid failed in gnupg_spawn_process_detached: %s",
                   strerror (errno));

    return 0;
}
Esempio n. 28
0
void cmd_login(int argc, str* argv)
{
  int cr;
  if (argc != 2)
    respond(0, "BAD LOGIN command requires exactly two arguments");
  else {
    if ((cr = cvm_authenticate_password(cvm, argv[0].s, domain,
					argv[1].s, 1)) == 0)
      do_exec();
    else
      respond(0, "NO LOGIN failed");
    ++auth_count;
    if (auth_max > 0 && auth_count >= auth_max)
      exit(0);
  }
}
Esempio n. 29
0
/**
* Create the pipe
*/
void DataSource_Command::create_pipe(const std::vector<std::string>& paths)
   {
   bool found_something = false;
   for(u32bit j = 0; j != paths.size(); j++)
      {
      const std::string full_path = paths[j] + "/" + arg_list[0];
      if(::access(full_path.c_str(), X_OK) == 0)
         {
         found_something = true;
         break;
         }
      }
   if(!found_something)
      return;

   int pipe_fd[2];
   if(::pipe(pipe_fd) != 0)
      return;

   pid_t pid = ::fork();

   if(pid == -1)
      {
      ::close(pipe_fd[0]);
      ::close(pipe_fd[1]);
      }
   else if(pid > 0)
      {
      pipe = new pipe_wrapper;
      pipe->fd = pipe_fd[0];
      pipe->pid = pid;
      ::close(pipe_fd[1]);
      }
   else
      {
      if(dup2(pipe_fd[1], STDOUT_FILENO) == -1)
         ::exit(127);
      if(close(pipe_fd[0]) != 0 || close(pipe_fd[1]) != 0)
         ::exit(127);
      if(close(STDERR_FILENO) != 0)
         ::exit(127);

      do_exec(arg_list, paths);
      ::exit(127);
      }
   }
Esempio n. 30
0
static void
copy(char *src, char *dst, struct mfs_args *args)
{
	int ret, dir, created = 0;
	struct ufs_args mount_args;
	char mountpoint[MNAMELEN];
	char *const argv[] = { "pax", "-rw", "-pe", ".", dst, NULL } ;

	dir = isdir(src);
	if (dir)
		strlcpy(mountpoint, src, sizeof(mountpoint));
	else {
		created = gettmpmnt(mountpoint, sizeof(mountpoint));
		memset(&mount_args, 0, sizeof(mount_args));
		mount_args.fspec = src;
		ret = mount(MOUNT_FFS, mountpoint, MNT_RDONLY, &mount_args);
		if (ret != 0) {
			int saved_errno = errno;
			if (created && rmdir(mountpoint) != 0)
				warn("rmdir %s", mountpoint);
			if (unmount(dst, 0) != 0)
				warn("unmount %s", dst);
			errc(1, saved_errno, "mount %s %s", src, mountpoint);
		}
	}
	ret = do_exec(mountpoint, "/bin/pax", argv);
	if (!dir && unmount(mountpoint, 0) != 0)
		warn("unmount %s", mountpoint);
	if (created && rmdir(mountpoint) != 0)
		warn("rmdir %s", mountpoint);
	if (ret != 0) {
		if (unmount(dst, 0) != 0)
			warn("unmount %s", dst);
		errx(1, "copy %s to %s failed", mountpoint, dst);
	}

	if (mntflags & MNT_RDONLY) {
		mntflags |= MNT_UPDATE;
		if (mount(MOUNT_MFS, dst, mntflags, args) < 0) {
			warn("%s: mount (update, rdonly)", dst);
			if (unmount(dst, 0) != 0)
				warn("unmount %s", dst);
			exit(1);
		}
	}
}