13d91be41SRobert Watson /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni *
43d91be41SRobert Watson * Copyright (c) 2007 Robert N. M. Watson
5474b62b8SAllan Jude * Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
63d91be41SRobert Watson * All rights reserved.
73d91be41SRobert Watson *
83d91be41SRobert Watson * Redistribution and use in source and binary forms, with or without
93d91be41SRobert Watson * modification, are permitted provided that the following conditions
103d91be41SRobert Watson * are met:
113d91be41SRobert Watson * 1. Redistributions of source code must retain the above copyright
123d91be41SRobert Watson * notice, this list of conditions and the following disclaimer.
133d91be41SRobert Watson * 2. Redistributions in binary form must reproduce the above copyright
143d91be41SRobert Watson * notice, this list of conditions and the following disclaimer in the
153d91be41SRobert Watson * documentation and/or other materials provided with the distribution.
163d91be41SRobert Watson *
173d91be41SRobert Watson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
183d91be41SRobert Watson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
193d91be41SRobert Watson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
203d91be41SRobert Watson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
213d91be41SRobert Watson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
223d91be41SRobert Watson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
233d91be41SRobert Watson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
243d91be41SRobert Watson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
253d91be41SRobert Watson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
263d91be41SRobert Watson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
273d91be41SRobert Watson * SUCH DAMAGE.
283d91be41SRobert Watson */
293d91be41SRobert Watson
30e1f323f3SRobert Watson #include <sys/param.h>
313d91be41SRobert Watson #include <sys/sysctl.h>
325a246d29SRobert Watson #include <sys/user.h>
333d91be41SRobert Watson
343d91be41SRobert Watson #include <err.h>
353d91be41SRobert Watson #include <errno.h>
360daf62d9SStanislav Sedov #include <libprocstat.h>
373d91be41SRobert Watson #include <limits.h>
383d91be41SRobert Watson #include <stdio.h>
393d91be41SRobert Watson #include <string.h>
403d91be41SRobert Watson
413d91be41SRobert Watson #include "procstat.h"
423d91be41SRobert Watson
433d91be41SRobert Watson void
procstat_bin(struct procstat * prstat,struct kinfo_proc * kipp)4466e2f999SMikolaj Golub procstat_bin(struct procstat *prstat, struct kinfo_proc *kipp)
453d91be41SRobert Watson {
4666e2f999SMikolaj Golub int osrel;
4766e2f999SMikolaj Golub static char pathname[PATH_MAX];
483d91be41SRobert Watson
492a243b95SBrooks Davis if ((procstat_opts & PS_OPT_NOHEADER) == 0)
50474b62b8SAllan Jude xo_emit("{T:/%5s %-16s %8s %s}\n", "PID", "COMM", "OSREL",
51474b62b8SAllan Jude "PATH");
523d91be41SRobert Watson
5366e2f999SMikolaj Golub if (procstat_getpathname(prstat, kipp, pathname, sizeof(pathname)) != 0)
543d91be41SRobert Watson return;
5566e2f999SMikolaj Golub if (strlen(pathname) == 0)
563d91be41SRobert Watson strcpy(pathname, "-");
5766e2f999SMikolaj Golub if (procstat_getosrel(prstat, kipp, &osrel) != 0)
58ca263e00SMikolaj Golub return;
59ca263e00SMikolaj Golub
60474b62b8SAllan Jude xo_emit("{k:process_id/%5d/%d} ", kipp->ki_pid);
61474b62b8SAllan Jude xo_emit("{:command/%-16s/%s} ", kipp->ki_comm);
62474b62b8SAllan Jude xo_emit("{:osrel/%8d/%d} ", osrel);
63474b62b8SAllan Jude xo_emit("{:pathname/%s}\n", pathname);
643d91be41SRobert Watson }
65