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

ksql_open() failure in split-process mode #7

cornett opened this issue Apr 2, 2018 · 1 comment

ksql_open() failure in split-process mode #7

cornett opened this issue Apr 2, 2018 · 1 comment


Copy link

cornett commented Apr 2, 2018

I recently encountered a situation where ksql_open() failed in
split-process mode, but worked fine otherwise. This is not really a bug
in ksql, but I'm reporting it for the benefit of anyone else who runs
into the same issue.

The problem occurs if you run ksql in split-process mode in a chroot
environment that doesn't include a functioning /dev/null device. It is
worth noting that this is what you get by default on OpenBSD if you just
enable slowcgi and drop a statically linked cgi script into

If you check the code of sqlite's robust_open() function (src/os_unix.c),
you will see that it wants to return a file descriptor > 2,
and may call open(2) on /dev/null to accomplish this.
If the latter fails, robust_open() returns an error. This behaviour
interacts badly with the code in the child path of ksql_alloc_child(),
which closes stdin and stdout. Without a functioning /dev/null, sqlite
can't fill in those empty descriptor slots and therefore won't open a database.

Once I debugged the problem, fixing it with mknod(8) was
straightforward, but it did require loosening the mount options on
/var, which is not great.

If you wish to work around this in ksql, not closing stdin and stdout in
the child should do it. Otherwise, perhaps a note in the documentation
would help others avoid the problem.

Copy link

This is a great find---it was also identified by schwarze@ in a code audit. Thank you to both of you! This'll be in the next release.

kristapsdz pushed a commit that referenced this issue Apr 26, 2018

This solve several mysteries, namely the one noted in
#7.  Noted and patched by schwarze@,
thank you!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants