Re: [dev] [st][PATCH] better plumbing on linux: find child shell cwd without shell gymnastics
On Thu, Nov 01, 2018 at 04:12:40PM +0100, John Soros wrote:
> Yes! This is much, much better! Thanks. Pity that it still doesn't work
> on OpenBSD.
If the info I gathered over the course of the last hour is correct, then
the way to query CWD in OpenBSD is
#include <sys/sysctl.h>
char cwd[PATH_MAX];
size_t sz = sizeof cwd;
int name[3] = {CTL_KERN, KERN_PROC_CWD, pid};
sysctl(name, 3, cwd, &sz, 0, 0);
Also, if my understanding of Linux /proc is correct, then realpath()
might be overkill, and readlink() would already suffice. The links in
/proc aren't really symlinks. For instance, dietlibc's realpath() will
actually use readlink() on /proc/self/cwd to do its job... though, it
could just use readlink() on /proc/self/fd/XX, then it wouldn't need to
chdir()... I digress.
The question is how to incorporate such code. Do we create OS specific
source files and compile in the ones needed, or do we go for conditional
compilation? The former is more complicated, as it involves mapping out
an interface that each OS source file has to follow. And in the long
run, it might start sucking, as the OSes aren't as orthogonal as
originally thought, and we end up copying some functions, and then
having to copy bugfixes... sucks a bit. Conditionals also suck a bit, as
we end up seeing a lot of what amounts to commented-out code. Giving up
on unportable features also sucks, as it precludes useful features like
the one in this submission. So, which option sucks least?
Ciao,
Markus
Received on Thu Nov 01 2018 - 17:54:37 CET
This archive was generated by hypermail 2.3.0
: Thu Nov 01 2018 - 18:00:08 CET