find the CWD of a child process

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jona Joachim
Date: Monday, January 4, 2010 - 9:38 am

Hi!
It happens to me all the time that I want to spawn a new xterm in the
same directory that I am currently in, for example when I want to open a
file with vim but keep a shell in the same directory.

xterm actually has a nice builtin function for this:
spawn-new-terminal()

you can affect that function via the xterm*VT100.translations resource.

however the implementation of this is Linux-specific and it is not
activated in the OpenBSD build process.

Here's a exerpt from HandleSpawnTerminal() in xenocara/app/xterm/misc.c:

/*
* Determine the current working directory of the child so that we can
* spawn a new terminal in the same directory.
*
* If we cannot get the CWD of the child, just use our own.
*/
if (screen->pid) {
	char child_cwd_link[sizeof(PROCFS_ROOT) + 80];
	sprintf(child_cwd_link, PROCFS_ROOT "/%lu/cwd", (unsigned long) screen->pid);
	child_cwd = Readlink(child_cwd_link);
}

So it obviously tries to access procfs to get that value. Is there a way
to access the same value via the OpenBSD API?

Best regards,
Jona

-- 
Worse is better
    Richard P. Gabriel
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
find the CWD of a child process, Jona Joachim, (Mon Jan 4, 9:38 am)
Re: find the CWD of a child process, Alexander Hall, (Fri Jan 8, 5:34 pm)