Advertisement
Guest User

Para Victor

a guest
May 24th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. int sh_launch(char **args){
  2.  pid_t pid, wpid;
  3.  int status;
  4.  char *argv[] = {NULL, "-c", "env", 0};
  5.  char *envp[] = {
  6.    "USER=me",
  7.    "HOME=/"
  8.    "PATH=/bin:/usr/bin",
  9.    0,
  10.  };
  11. argv[0] = concat("/bin/", *args);
  12.  
  13.  pid = fork();
  14.  if (pid == 0) {
  15.    // Proceso hijo
  16.    if (execve(argv[0], args, envp) == -1 ) {  
  17.      perror("sh");
  18.    }
  19.  exit(EXIT_FAILURE);
  20.  } else if (pid < 0) {
  21.    // Error al hacer forking
  22.    perror("sh");
  23.  } else {
  24.    // Proceso padre
  25.    do
  26. {wpid = waitpid(pid, &status, WUNTRACED);
  27.    } while (!WIFEXITED(status) && !WIFSIGNALED(status));
  28.  }
  29.  
  30.  return 1;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement