-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #326 from dciabrin/tracefd-cloexec
Issue #325: bash-engine: new option to not leak trace fd to children
- Loading branch information
Showing
7 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
void __attribute__((constructor)) tracefd_cloexec(void) | ||
{ | ||
int xtraceFd; | ||
const char* fdStr; | ||
char* endStr; | ||
|
||
if (getenv("KCOV_BASH_USE_DEBUG_TRAP")) | ||
fdStr = getenv("KCOV_BASH_XTRACEFD"); | ||
else | ||
fdStr = getenv("BASH_XTRACEFD"); | ||
|
||
if (fdStr) | ||
{ | ||
xtraceFd = (int)strtol(fdStr, &endStr, 10); | ||
if (endStr != NULL && *endStr == '\0') | ||
{ | ||
int flags = fcntl(xtraceFd, F_GETFD); | ||
if (flags != -1) | ||
fcntl(xtraceFd, F_SETFD, flags | FD_CLOEXEC); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#! /usr/bin/env bash | ||
|
||
nohup sleep 6 &>/dev/null & | ||
echo leave child running |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters