1085e0494SKonstantin Belousov /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3085e0494SKonstantin Belousov *
4085e0494SKonstantin Belousov * Copyright (c) 2020 Juraj Lutter <juraj@lutter.sk>
5085e0494SKonstantin Belousov * All rights reserved.
6085e0494SKonstantin Belousov *
7085e0494SKonstantin Belousov * Redistribution and use in source and binary forms, with or without
8085e0494SKonstantin Belousov * modification, are permitted provided that the following conditions
9085e0494SKonstantin Belousov * are met:
10085e0494SKonstantin Belousov * 1. Redistributions of source code must retain the above copyright
11085e0494SKonstantin Belousov * notice, this list of conditions and the following disclaimer.
12085e0494SKonstantin Belousov * 2. Redistributions in binary form must reproduce the above copyright
13085e0494SKonstantin Belousov * notice, this list of conditions and the following disclaimer in the
14085e0494SKonstantin Belousov * documentation and/or other materials provided with the distribution.
15085e0494SKonstantin Belousov *
16085e0494SKonstantin Belousov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17085e0494SKonstantin Belousov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18085e0494SKonstantin Belousov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19085e0494SKonstantin Belousov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20085e0494SKonstantin Belousov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21085e0494SKonstantin Belousov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22085e0494SKonstantin Belousov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23085e0494SKonstantin Belousov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24085e0494SKonstantin Belousov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25085e0494SKonstantin Belousov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26085e0494SKonstantin Belousov * SUCH DAMAGE.
27085e0494SKonstantin Belousov */
28085e0494SKonstantin Belousov
29085e0494SKonstantin Belousov #include <sys/param.h>
30085e0494SKonstantin Belousov #include <sys/capsicum.h>
31085e0494SKonstantin Belousov #include <sys/socket.h>
32085e0494SKonstantin Belousov #include <sys/sysctl.h>
33085e0494SKonstantin Belousov #include <sys/un.h>
34085e0494SKonstantin Belousov #include <sys/user.h>
35085e0494SKonstantin Belousov
36085e0494SKonstantin Belousov #include <netinet/in.h>
37085e0494SKonstantin Belousov
38085e0494SKonstantin Belousov #include <arpa/inet.h>
39085e0494SKonstantin Belousov
40085e0494SKonstantin Belousov #include <err.h>
41085e0494SKonstantin Belousov #include <libprocstat.h>
42085e0494SKonstantin Belousov #include <inttypes.h>
43085e0494SKonstantin Belousov #include <stdio.h>
44085e0494SKonstantin Belousov #include <stdlib.h>
45085e0494SKonstantin Belousov #include <string.h>
46085e0494SKonstantin Belousov
47085e0494SKonstantin Belousov #include "procstat.h"
48085e0494SKonstantin Belousov
49085e0494SKonstantin Belousov void
procstat_pwdx(struct procstat * procstat,struct kinfo_proc * kipp)50085e0494SKonstantin Belousov procstat_pwdx(struct procstat *procstat, struct kinfo_proc *kipp)
51085e0494SKonstantin Belousov {
52085e0494SKonstantin Belousov struct filestat_list *head;
53085e0494SKonstantin Belousov struct filestat *fst;
54085e0494SKonstantin Belousov
55085e0494SKonstantin Belousov head = procstat_getfiles(procstat, kipp, 0);
56085e0494SKonstantin Belousov if (head == NULL)
57085e0494SKonstantin Belousov return;
58085e0494SKonstantin Belousov STAILQ_FOREACH(fst, head, next) {
59085e0494SKonstantin Belousov if ((fst->fs_uflags & PS_FST_UFLAG_CDIR) &&
60085e0494SKonstantin Belousov (fst->fs_path != NULL)) {
61085e0494SKonstantin Belousov xo_emit("{k:process_id/%d}{P:: }", kipp->ki_pid);
62085e0494SKonstantin Belousov xo_emit("{:cwd/%s}", fst->fs_path);
63085e0494SKonstantin Belousov xo_emit("\n");
64085e0494SKonstantin Belousov }
65085e0494SKonstantin Belousov }
66085e0494SKonstantin Belousov procstat_freefiles(procstat, head);
67085e0494SKonstantin Belousov }
68