xref: /illumos-gate/usr/src/man/man3proc/Pcwd.3proc (revision 9b9d39d2a32ff806d2431dbcc50968ef1e6d46b2)
1.\"
2.\" This file and its contents are supplied under the terms of the
3.\" Common Development and Distribution License ("CDDL"), version 1.0.
4.\" You may only use this file in accordance with the terms of version
5.\" 1.0 of the CDDL.
6.\"
7.\" A full copy of the text of the CDDL should have accompanied this
8.\" source.  A copy of the CDDL is also available via the Internet at
9.\" http://www.illumos.org/license/CDDL.
10.\"
11.\"
12.\" Copyright 2024 Oxide Computer Company
13.\"
14.Dd May 10, 2024
15.Dt Pcwd 3PROC
16.Os
17.Sh NAME
18.Nm Pcwd ,
19.Nm Pcwd_free
20.Nd get process current working directory information
21.Sh LIBRARY
22.Lb libproc
23.Sh SYNOPSIS
24.In libproc.h
25.Ft int
26.Fo Pcwd
27.Fa "struct ps_prochandle *P"
28.Fa "prcwd_t **cwdp"
29.Fc
30.Ft void
31.Fo Pcwd_free
32.Fa "prcwd_t *cwd"
33.Fc
34.Sh DESCRIPTION
35The
36.Fn Pcwd
37function obtains the current working directory and related information
38about the file system it is contained upon of the process handle
39.Fa P .
40This information is synthesized for live processes and is obtained from
41the
42.Dv NT_CWD
43elf note for core files.
44It is not supported on handles that refer to idle
45.Pq Dv PS_IDLE
46processes.
47.Pp
48The library will allocate the memory needed for a
49.Ft prcwd_t
50structure.
51A pointer to this data will be stored in
52.Fa cwdp .
53It is the callers responsibility to release it by calling the
54.Fn Pcwd_free
55function and passing it back in the
56.Fa cwd
57argument.
58The allocated data stored in
59.Fa cwdp
60has a lifetime independent of the process handle,
61.Fa P .
62In other words, the data in
63.Fa cwdp
64may be used after someone has called
65.Xr Prelease 3PROC
66or
67.Xr Pfree 3PROC
68on
69.Fa P .
70.Pp
71The
72.Ft prcwd_t
73structure is defined in
74.In sys/procfs.h
75and discussed in more detail in
76.Xr core 5 .
77The various path related strings are NUL-terminated character strings that may
78not be valid in the calling process's locale.
79.Sh RETURN VALUES
80Upon successful completion, the
81.Fn Pwcd
82function returns
83.Sy 0
84and stores the allocated
85.Vt prcwd_t
86structure in
87.Fa cwdp .
88Otherwise
89.Sy -1
90is returned and
91.Va errno
92is set to indicate the error.
93.Sh ERRORS
94The
95.Fn Pcwd
96functions will fail if:
97.Bl  -tag -width Er
98.It Er EAGAIN, ENOMEM
99An underlying memory allocation failed.
100.It Er ENODATA
101The process handle,
102.Fa P ,
103refers to a core file which does not contain the
104.Dv NT_CWD
105ELF note.
106.It Er ENOTSUP
107The process handle
108.Fa P ,
109does not support obtaining the current working directory.
110This would happen because the process handle does not refer to a core
111file or live process.
112.El
113.Pp
114Additional errors may be generated based on the type of process handle
115that is present.
116.Sh INTERFACE STABILITY
117.Sy Uncommitted
118.Sh MT-LEVEL
119See
120.Sy LOCKING
121in
122.Xr libproc 3LIB .
123.Sh SEE ALSO
124.Xr pwdx 1 ,
125.Xr libproc 3LIB ,
126.Xr core 5 ,
127.Xr proc 5
128