NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/50620: Add interface to get process' working directory



>Number:         50620
>Category:       kern
>Synopsis:       Add interface to get process' working directory
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Jan 04 12:25:00 +0000 2016
>Originator:     Thomas Klausner
>Release:        NetBSD 7.99.25
>Organization:
Curiosity is the very basis of education and if you tell me that 
curiosity killed the cat, I say only that the cat died nobly.
- Arnold Edinborough
>Environment:
	
	
Architecture: x86_64
Machine: amd64
>Description:
Please provide an interface to get a process' current working directory.

Both FreeBSD and OpenBSD provide this, and some applications want to use it
(py-psutil, tmux).

If I understood the FreeBSD code in psutil correctly, it is done this way:
    size_t size;
    mib[0] = CTL_KERN;
    mib[1] = KERN_PROC;
    mib[2] = KERN_PROC_PID;
    mib[3] = pid;

    size = sizeof(struct kinfo_proc);
    if (sysctl((int *)mib, 4, proc, &size, NULL, 0) == -1) {
...

    freep = kinfo_getfile(...)
    if (freep == NULL) {
...
    (iterate over results)
        if (kif->kf_fd == KF_FD_TYPE_CWD) {
            print("%s\n", kif->kf_path);
...


OpenBSD does it more directly:

    int name[] = { CTL_KERN, KERN_PROC_CWD, pid };
    if (sysctl(name, 3, path, &pathlen, NULL, 0) != 0) {
...

then path contains the path.


>How-To-Repeat:
	
>Fix:
Please.

>Unformatted:
 	
 	


Home | Main Index | Thread Index | Old Index