Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int sh_launch(char **args){
- pid_t pid, wpid;
- int status;
- char *argv[] = {NULL, "-c", "env", 0};
- char *envp[] = {
- "USER=me",
- "HOME=/"
- "PATH=/bin:/usr/bin",
- 0,
- };
- argv[0] = concat("/bin/", *args);
- pid = fork();
- if (pid == 0) {
- // Proceso hijo
- if (execve(argv[0], args, envp) == -1 ) {
- perror("sh");
- }
- exit(EXIT_FAILURE);
- } else if (pid < 0) {
- // Error al hacer forking
- perror("sh");
- } else {
- // Proceso padre
- do
- {wpid = waitpid(pid, &status, WUNTRACED);
- } while (!WIFEXITED(status) && !WIFSIGNALED(status));
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement