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

LD_PRELOAD-based unbuffering #243

Closed
Xyene opened this issue Mar 2, 2017 · 2 comments
Closed

LD_PRELOAD-based unbuffering #243

Xyene opened this issue Mar 2, 2017 · 2 comments

Comments

@Xyene
Copy link
Member

Xyene commented Mar 2, 2017

A simple solution to the fact that pseudo-ttys are both a headache and don't currently work.

nobuffer.cpp:

#include <stdio.h>

void unbuffer() __attribute__((constructor));

void unbuffer()
{
    setvbuf(stdout, NULL, _IONBF, 0);
}

Compile with gcc -shared -fPIC -o nobuffer.so nobuffer.cpp, and pass in LD_PRELOAD=nobuffer.so to user submissions. The compilation step can be done in setup.py.

This will force an unbuffered mode for all languages depending on libc for IO. This excludes languages like Python, which handles their own (Python buffering is already handled separately by the judge), but includes all languages compiled with GCC. It also does not include Pascal, which does not link libc, but who uses Pascal?

image

With this change implemented, we could easily support unbuffered IO for ~97% of the languages used by volume. The current pty-based implementation can be gutted.

@Xyene
Copy link
Member Author

Xyene commented Dec 4, 2017

This is functional and passes all unit tests.

@Xyene Xyene closed this as completed Dec 4, 2017
@quantum5
Copy link
Member

quantum5 commented Dec 4, 2017

I hesitate to conclude this will not break any non-libc languages.

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

No branches or pull requests

2 participants