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

Avoid pipe2 in support/interactive #148

Closed
thorehusfeldt opened this issue Nov 11, 2019 · 6 comments
Closed

Avoid pipe2 in support/interactive #148

thorehusfeldt opened this issue Nov 11, 2019 · 6 comments

Comments

@thorehusfeldt
Copy link
Contributor

thorehusfeldt commented Nov 11, 2019

pipe2 is linux-specific, so that make fails on BSD-based unixes such as OS X.

My (limited) understanding is that the flag in the 2nd argument pipe2(fd, O_CLOEXEC) in makepipe ensures that the pipes are closed upon exit, which can be achieved with fcntl in a platform-independent way.

if(pipe2(fd, O_CLOEXEC)) {

Linux man page: http://man7.org/linux/man-pages/man2/pipe.2.html

An easy fix is to revert that part of the code to the state before 0d38a8b

@simonlindholm
Copy link
Member

The changes in that commit should really be made conditional on Linux, yeah. Some previous discussion in #122.

@thorehusfeldt
Copy link
Contributor Author

thorehusfeldt commented Nov 11, 2019

Like this:

#ifdef _GNU_SOURCE
const int PIPE_SIZE = 1<<20; // 1 MiB (the default max value for an unprivileged user)
#endif 
...
#ifdef _GNU_SOURCE
	if(pipe2(fd, O_CLOEXEC)) {
		perror("pipe failed");
		exit(EXIT_FAILURE);
	}
	if (fcntl(fd[0], F_SETPIPE_SZ, PIPE_SIZE) == -1) {
		perror("failed to set pipe size");
	}
 #else
	if(pipe(fd)) {
		perror("pipe failed");
		exit(EXIT_FAILURE);
	}
	for(int i = 0; i < 2; i++) {		
 		set_cloexec(fd[i], 1);		
 	}
 #endif

Not sure which variable to ifdef on. With the above changes, I can cleanly compile this part at least on OS X. (The other issue, apparently also known, is with libchecktestdata.)

@thorehusfeldt
Copy link
Contributor Author

Re “the other issue”: the one-line patch at DOMjudge/checktestdata@470b9e5 does indeed fix libchecktestdata, and with those two changes the whole problemtools suite seems to compile on OS X. (Well, there are some warnings about unused variables in libchecktestdata.)

@thorehusfeldt
Copy link
Contributor Author

@simonlindholm : What’s the preferred way to test for “are we on Linux?”

@simonlindholm
Copy link
Member

Not certain, I guess #ifdef __linux__?

@thorehusfeldt
Copy link
Contributor Author

Closed in 9d85d66

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants