--- src/text.c.orig 2018-05-10 13:18:29.000000000 +0200 +++ src/text.c 2018-06-05 16:31:38.067251455 +0200 @@ -29,6 +29,7 @@ #include #include #include +#include #ifndef NANO_TINY static pid_t pid = -1; @@ -1089,6 +1090,8 @@ /* Original and temporary handlers for SIGINT. */ bool setup_failed = FALSE; /* Whether setting up the temporary SIGINT handler failed. */ + posix_spawn_file_actions_t fa; + char* shellargv[4]; /* Create a pipe to read the command's output from. */ if (pipe(fd) == -1) { @@ -1101,6 +1104,29 @@ if (shellenv == NULL) shellenv = (char *) "/bin/sh"; + if(0!=posix_spawn_file_actions_init(&fa)) { + statusbar(_("POSIX spawn failed")); + close(fd[0]); + close(fd[1]); + return FALSE; + } + + shellargv[0] = (char*)tail(shellenv); + shellargv[1] = "-c"; + shellargv[2] = (char*)command; + shellargv[3] = NULL; + + if(0!=posix_spawn_file_actions_addclose(&fa, fd[0]) || + 0!=posix_spawn_file_actions_adddup2(&fa, fd[1], fileno(stdout)) || + 0!=posix_spawn_file_actions_adddup2(&fa, fd[1], fileno(stderr)) || + 0!=posix_spawn_file_actions_addclose(&fa, fd[1]) || + 0!=posix_spawn(&pid, shellenv, &fa, NULL, shellargv, NULL)) { + pid = -1; + } + + posix_spawn_file_actions_destroy(&fa); + +#if 0 /* Fork a child process to run the command in. */ if ((pid = fork()) == 0) { /* Child: close the unused read end of the pipe. */ @@ -1116,12 +1142,16 @@ /* If the exec call returns, there was an error. */ exit(1); } +#endif /* Parent: close the unused write end of the pipe. */ close(fd[1]); if (pid == -1) { + statusbar(_("POSIX spawn failed")); +#if 0 statusbar(_("Could not fork")); +#endif close(fd[0]); return FALSE; } @@ -3010,6 +3040,7 @@ pid_t pid_lint; static char **lintargs = NULL; lintstruct *lints = NULL, *tmplint = NULL, *curlint = NULL; + posix_spawn_file_actions_t fa; if (ISSET(RESTRICTED)) { show_restricted_warning(); @@ -3047,6 +3078,24 @@ construct_argument_list(&lintargs, openfile->syntax->linter, openfile->filename); + if(0!=posix_spawn_file_actions_init(&fa)) { + statusbar(_("POSIX spawn failed")); + close(lint_fd[0]); + close(lint_fd[1]); + return; + } + + if(0!=posix_spawn_file_actions_addclose(&fa, lint_fd[0]) || + 0!=posix_spawn_file_actions_adddup2(&fa, lint_fd[1], STDOUT_FILENO) || + 0!=posix_spawn_file_actions_adddup2(&fa, lint_fd[1], STDERR_FILENO) || + 0!=posix_spawn_file_actions_addclose(&fa, lint_fd[1]) || + 0!=posix_spawnp(&pid_lint, lintargs[0], &fa, NULL, lintargs, NULL)) { + pid_lint = -1; + } + + posix_spawn_file_actions_destroy(&fa); + +#if 0 /* Start a new process to run the linter in. */ if ((pid_lint = fork()) == 0) { @@ -3067,6 +3116,7 @@ /* This is only reached when the linter is not found. */ exit(9); } +#endif /* Parent continues here. */ close(lint_fd[1]); @@ -3074,7 +3124,10 @@ /* If the child process was not forked successfully... */ if (pid_lint < 0) { close(lint_fd[0]); +#if 0 statusbar(_("Could not fork")); +#endif + statusbar(_("POSIX spawn failed")); return; }