1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-27 02:56:18 -04:00

Merge pull request #108 from sgerwk/master

close stdin before calling a background program
This commit is contained in:
rkd77 2021-03-20 10:22:28 +01:00 committed by GitHub
commit c82a820e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 1 deletions

View File

@ -356,6 +356,30 @@ exe(char *path)
#endif
int
exe_no_stdin(char *path) {
int ret;
#if defined(F_GETFD) && defined(FD_CLOEXEC)
int flags;
flags = fcntl(STDIN_FILENO, F_GETFD, &flags);
fcntl(STDIN_FILENO, F_SETFD, flags | FD_CLOEXEC);
ret = exe(path);
fcntl(STDIN_FILENO, F_SETFD, flags);
#else
pid_t pid;
pid = fork();
if (pid == 0) {
close(STDIN_FILENO);
exit(exe(path));
}
else if (pid > 0)
waitpid(pid, &ret, 0);
#endif
return ret;
}
static char *clipboard;
char *

View File

@ -47,6 +47,7 @@ char *get_window_title(int codepage);
void block_stdin(void);
void unblock_stdin(void);
int exe(char *);
int exe_no_stdin(char *);
int resize_window(int, int, int, int);
int can_resize_window(int);
int can_open_os_shell(int);

View File

@ -226,11 +226,16 @@ void
exec_thread(char *path, int p)
{
int plen = strlen(path + 1) + 2;
pid_t pid;
int flags;
#if defined(HAVE_SETPGID) && !defined(CONFIG_OS_BEOS) && !defined(HAVE_BEGINTHREAD)
if (path[0] == TERM_EXEC_NEWWIN) setpgid(0, 0);
#endif
exe(path + 1);
if (path[0] == TERM_EXEC_BG)
exe_no_stdin(path + 1);
else
exe(path + 1);
if (path[plen]) unlink(path + plen);
}