aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ssh-agent-filter.C12
1 files changed, 7 insertions, 5 deletions
diff --git a/ssh-agent-filter.C b/ssh-agent-filter.C
index 252e017..b806a85 100644
--- a/ssh-agent-filter.C
+++ b/ssh-agent-filter.C
@@ -602,11 +602,13 @@ int main (int const argc, char const * const * const argv) {
// the following stuff is optional, so we don't do error checking
setsid();
static_cast<void>(chdir("/"));
- int devnull = open("/dev/null", O_RDWR);
- dup2(devnull, 0);
- dup2(devnull, 1);
- dup2(devnull, 2);
- close(devnull);
+ if (int devnull = open("/dev/null", O_RDWR); devnull != -1) {
+ dup2(devnull, 0);
+ dup2(devnull, 1);
+ dup2(devnull, 2);
+ if (devnull > 2)
+ close(devnull);
+ }
} else {
cout << "copy this to another terminal:" << endl;
cout << "SSH_AUTH_SOCK='" << path.native() << "'; export SSH_AUTH_SOCK;" << endl;