Skip to content

Commit 9d85d66

Browse files
thorehusfeldtsimonlindholm
authored andcommitted
Work around pipe2 on non-linux
Use pipe instead of pipe2 on non-linux. Allows problemtools to compile on OS X.
1 parent eb7b607 commit 9d85d66

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

support/interactive/interactive.cc

+12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#define NOFD -1
1515

1616
const int EXITCODE_AC = 42;
17+
#ifdef __linux__
1718
const int PIPE_SIZE = 1<<20; // 1 MiB (the default max value for an unprivileged user)
19+
#endif
1820

1921
int report_fd, walltimelimit;
2022

@@ -191,6 +193,7 @@ int execute(char **args, int fdin, int fdout) {
191193
*/
192194

193195
void makepipe(int fd[2]) {
196+
#ifdef __linux__
194197
if(pipe2(fd, O_CLOEXEC)) {
195198
perror("pipe failed");
196199
exit(EXIT_FAILURE);
@@ -199,6 +202,15 @@ void makepipe(int fd[2]) {
199202
if (fcntl(fd[0], F_SETPIPE_SZ, PIPE_SIZE) == -1) {
200203
perror("failed to set pipe size");
201204
}
205+
#else
206+
if(pipe(fd)) {
207+
perror("pipe failed");
208+
exit(EXIT_FAILURE);
209+
}
210+
for(int i = 0; i < 2; i++) {
211+
set_cloexec(fd[i], 1);
212+
}
213+
#endif
202214
}
203215

204216

0 commit comments

Comments
 (0)