Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close more FDs because XRootd plays games in library init #4178

Merged
merged 3 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion source/adios2/toolkit/remote/EVPathRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ EVPathRemote::GetHandle EVPathRemote::Get(char *VarName, size_t Step, size_t Blo
GetMsg.Start = Start.data();
GetMsg.Dest = dest;
CMwrite(m_conn, ev_state.GetRequestFormat, &GetMsg);
CMCondition_wait(ev_state.cm, GetMsg.GetResponseCondition);
anagainaru marked this conversation as resolved.
Show resolved Hide resolved
return (Remote::GetHandle)(intptr_t)GetMsg.GetResponseCondition;
}

Expand Down
25 changes: 22 additions & 3 deletions source/adios2/toolkit/remote/remote_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <sys/types.h> // open
#ifndef _MSC_VER
#include <unistd.h> // write, close, ftruncate

static int fd_is_valid(int fd) { return fcntl(fd, F_GETFD) != -1 || errno != EBADF; }

#else
#include <io.h>
#define strdup _strdup
Expand Down Expand Up @@ -619,9 +622,25 @@ int main(int argc, char **argv)
}
/* I'm the child, close IO FDs so that ctest continues. No verbosity here */
verbose = 0;
close(0);
close(1);
close(2);

// Why close a bunch of FDs here? Well, if we've linked with XRootD, stderr might have
// been dup()'d in library initialization. We don't need those FDs and we have to close
// them to make sure we disassociate from the CTest parent (or else fixture startup hangs).
// It doesn't seem to work to close them before the fork, so we close them afterwards.
for (int fd = 0; fd <= 16; fd++)
{
if (fd_is_valid(fd))
{
// OK, fd is valid, should we close it?
if ((lseek(fd, 0, SEEK_CUR) == -1) && (errno == ESPIPE))
{
// In the circumstances we care about (running under CTest), we want to close
// FDs that are pipes. The condition above tests for that and we should get
// here only if it's a pipe.
close(fd);
}
}
}
#endif
}

Expand Down
Loading