-/* $OpenBSD: print.c,v 1.84 2022/09/20 10:01:51 job Exp $ */
+/* $OpenBSD: print.c,v 1.85 2023/01/07 05:24:59 guenther Exp $ */
/* $NetBSD: print.c,v 1.27 1995/09/29 21:58:12 cgd Exp $ */
/*-
(void)putchar('\n');
}
+static int
+print_comm_name(const struct kinfo_proc *kp, int left, int trail)
+{
+ left -= mbswprint(kp->p_comm, left, trail);
+ if (left > 1 && kp->p_name[0] != '\0') {
+ putchar('/');
+ left--;
+ left -= mbswprint(kp->p_name, left, trail);
+ }
+ return left;
+}
+
void
command(const struct pinfo *pi, VARENT *ve)
{
}
}
if (argv == NULL || argv[0] == NULL ||
+ kp->p_name[0] != '\0' ||
strcmp(cmdpart(argv[0]), kp->p_comm)) {
if (wantspace) {
putchar(' ');
}
putchar('(');
left--;
- left -= mbswprint(kp->p_comm, left, 0);
+ left -= print_comm_name(kp, left, 0);
if (left == 0)
return;
putchar(')');
putchar(' ');
left--;
}
- left -= mbswprint(kp->p_comm, left, 0);
+ left -= print_comm_name(kp, left, 0);
}
}
if (ve->next != NULL)
-/* $OpenBSD: unistd.h,v 1.106 2018/07/13 09:25:22 beck Exp $ */
+/* $OpenBSD: unistd.h,v 1.107 2023/01/07 05:24:58 guenther Exp $ */
/* $NetBSD: unistd.h,v 1.26.4.1 1996/05/28 02:31:51 mrg Exp $ */
/*-
int getresgid(gid_t *, gid_t *, gid_t *);
int getresuid(uid_t *, uid_t *, uid_t *);
pid_t getthrid(void);
+int getthrname(pid_t, char *, size_t);
char *getusershell(void);
int initgroups(const char *, gid_t);
int issetugid(void);
int setpgrp(pid_t _pid, pid_t _pgrp); /* BSD compat version */
int setresgid(gid_t, gid_t, gid_t);
int setresuid(uid_t, uid_t, uid_t);
+int setthrname(pid_t, const char *);
void setusershell(void);
int strtofflags(char **, u_int32_t *, u_int32_t *);
int swapctl(int cmd, const void *arg, int misc);
_thread_sys_getsockname
_thread_sys_getsockopt
_thread_sys_getthrid
+_thread_sys_getthrname
_thread_sys_gettimeofday
_thread_sys_getuid
_thread_sys_ioctl
_thread_sys_setrtable
_thread_sys_setsid
_thread_sys_setsockopt
+_thread_sys_setthrname
_thread_sys_settimeofday
_thread_sys_setuid
_thread_sys_shmat
getsockname
getsockopt
getthrid
+getthrname
gettimeofday
getuid
ioctl
setrtable
setsid
setsockopt
+setthrname
settimeofday
setuid
shmat
major=96
-minor=4
+minor=5
# note: If changes were made to include/thread_private.h or if system calls
# were added/changed then librthread/shlib_version must also be updated.
-# $OpenBSD: Makefile.inc,v 1.167 2022/12/19 18:13:50 guenther Exp $
+# $OpenBSD: Makefile.inc,v 1.168 2023/01/07 05:24:58 guenther Exp $
# $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $
# @(#)Makefile.inc 8.1 (Berkeley) 6/17/93
# they just never want to set errno.
ASM_NOERR=__get_tcb.o __set_tcb.o __threxit.o __thrsleep.o __thrwakeup.o \
getdtablecount.o getegid.o geteuid.o getgid.o getlogin_r.o \
- getpgrp.o getpid.o getppid.o getrtable.o getthrid.o getuid.o \
+ getpgrp.o getpid.o getppid.o getrtable.o getthrid.o \
+ getthrname.o getuid.o \
issetugid.o \
- sched_yield.o sync.o \
+ sched_yield.o setthrname.o sync.o \
umask.o
PASM_NOERR= ${ASM_NOERR:.o=.po}
SASM_NOERR= ${ASM_NOERR:.o=.so}
-/* $OpenBSD: rthread_np.c,v 1.23 2021/09/17 15:20:21 deraadt Exp $ */
+/* $OpenBSD: rthread_np.c,v 1.24 2023/01/07 05:24:58 guenther Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* Copyright (c) 2005 Otto Moerbeek <otto@openbsd.org>
#include "rthread.h"
REDIRECT_SYSCALL(sysctl);
+REDIRECT_SYSCALL(getthrname);
+REDIRECT_SYSCALL(setthrname);
void
pthread_set_name_np(pthread_t thread, const char *name)
{
- strlcpy(thread->name, name, sizeof(thread->name));
+ pid_t tid = 0;
+
+ if (thread != pthread_self())
+ tid = thread->tib->tib_tid;
+ setthrname(tid, name);
}
void
pthread_get_name_np(pthread_t thread, char *name, size_t len)
{
- strlcpy(name, thread->name, len);
+ pid_t tid = 0;
+
+ if (thread != pthread_self())
+ tid = thread->tib->tib_tid;
+ getthrname(tid, name, len);
}
int
major=26
-minor=3
+minor=4
-/* $OpenBSD: kern_exec.c,v 1.241 2023/01/05 21:39:57 deraadt Exp $ */
+/* $OpenBSD: kern_exec.c,v 1.242 2023/01/07 05:24:58 guenther Exp $ */
/* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */
/*-
timespecclear(&p->p_tu.tu_runtime);
p->p_tu.tu_uticks = p->p_tu.tu_sticks = p->p_tu.tu_iticks = 0;
+ memset(p->p_name, 0, sizeof p->p_name);
+
km_free(argp, NCARGS, &kv_exec, &kp_pageable);
pool_put(&namei_pool, nid.ni_cnd.cn_pnbuf);
-/* $OpenBSD: kern_fork.c,v 1.244 2022/11/11 18:09:58 cheloha Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.245 2023/01/07 05:24:58 guenther Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
p = thread_new(curp, uaddr);
atomic_setbits_int(&p->p_flag, P_THREAD);
sigstkinit(&p->p_sigstk);
+ memset(p->p_name, 0, sizeof p->p_name);
/* other links */
p->p_p = pr;
-/* $OpenBSD: kern_pledge.c,v 1.301 2022/12/23 05:35:08 deraadt Exp $ */
+/* $OpenBSD: kern_pledge.c,v 1.302 2023/01/07 05:24:58 guenther Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
[SYS___thrwakeup] = PLEDGE_STDIO,
[SYS___threxit] = PLEDGE_STDIO,
[SYS___thrsigdivert] = PLEDGE_STDIO,
+ [SYS_getthrname] = PLEDGE_STDIO,
+ [SYS_setthrname] = PLEDGE_STDIO,
[SYS_fork] = PLEDGE_PROC,
[SYS_vfork] = PLEDGE_PROC,
-/* $OpenBSD: kern_prot.c,v 1.80 2022/08/14 01:58:27 jsg Exp $ */
+/* $OpenBSD: kern_prot.c,v 1.81 2023/01/07 05:24:58 guenther Exp $ */
/* $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $ */
/*
return (0);
}
+int
+sys_getthrname(struct proc *curp, void *v, register_t *retval)
+{
+ struct sys_getthrname_args /* {
+ syscallarg(pid_t) tid;
+ syscallarg(char *) name;
+ syscallarg(size_t) len;
+ } */ *uap = v;
+ struct proc *p;
+ size_t len;
+ int tid = SCARG(uap, tid);
+ int error;
+
+ p = tid ? tfind_user(tid, curp->p_p) : curp;
+ if (p == NULL)
+ return ESRCH;
+
+ len = SCARG(uap, len);
+ if (len > sizeof(p->p_name))
+ len = sizeof(p->p_name);
+ error = copyoutstr(p->p_name, SCARG(uap, name), len, NULL);
+ if (error == ENAMETOOLONG)
+ error = ERANGE;
+ *retval = error;
+ return 0;
+}
+
+int
+sys_setthrname(struct proc *curp, void *v, register_t *retval)
+{
+ struct sys_setthrname_args /* {
+ syscallarg(pid_t) tid;
+ syscallarg(const char *) name;
+ } */ *uap = v;
+ struct proc *p;
+ char buf[sizeof p->p_name];
+ int tid = SCARG(uap, tid);
+ int error;
+
+ p = tid ? tfind_user(tid, curp->p_p) : curp;
+ if (p == NULL)
+ return ESRCH;
+
+ error = copyinstr(SCARG(uap, name), buf, sizeof buf, NULL);
+ if (error == 0)
+ strlcpy(p->p_name, buf, sizeof(p->p_name));
+ *retval = error;
+ return 0;
+}
+
/*
* Refresh the thread's reference to the process's credentials
*/
-; $OpenBSD: syscalls.master,v 1.238 2022/12/17 13:42:59 kn Exp $
+; $OpenBSD: syscalls.master,v 1.239 2023/01/07 05:24:58 guenther Exp $
; $NetBSD: syscalls.master,v 1.32 1996/04/23 10:24:21 mycroft Exp $
; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
140 STD NOLOCK { int sys_adjtime(const struct timeval *delta, \
struct timeval *olddelta); }
141 STD { int sys_getlogin_r(char *namebuf, u_int namelen); }
-142 OBSOL ogethostid
-143 OBSOL osethostid
+142 STD { int sys_getthrname(pid_t tid, char *name, size_t len); }
+143 STD { int sys_setthrname(pid_t tid, const char *name); }
144 OBSOL ogetrlimit
145 OBSOL osetrlimit
146 OBSOL okillpg
-/* $OpenBSD: proc.h,v 1.337 2023/01/02 23:09:48 guenther Exp $ */
+/* $OpenBSD: proc.h,v 1.338 2023/01/07 05:24:58 guenther Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
#define p_startcopy p_sigmask
sigset_t p_sigmask; /* [a] Current signal mask */
+ char p_name[_MAXCOMLEN]; /* thread name, incl NUL */
u_char p_slppri; /* [S] Sleeping priority */
u_char p_usrpri; /* [S] Priority based on p_estcpu & ps_nice */
u_int p_estcpu; /* [S] Time averaged val of p_cpticks */
-/* $OpenBSD: sysctl.h,v 1.231 2022/11/07 14:25:44 robert Exp $ */
+/* $OpenBSD: sysctl.h,v 1.232 2023/01/07 05:24:58 guenther Exp $ */
/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
/*
u_int32_t p_rtableid; /* U_INT: Routing table identifier. */
u_int64_t p_pledge; /* U_INT64_T: Pledge flags. */
+ char p_name[KI_MAXCOMLEN]; /* thread name */
};
/*
(kp)->p_svgid = (uc)->cr_svgid; \
\
memcpy((kp)->p_groups, (uc)->cr_groups, \
- _FILL_KPROC_MIN(sizeof((kp)->p_groups), sizeof((uc)->cr_groups))); \
+ _FILL_KPROC_MIN(sizeof((kp)->p_groups), sizeof((uc)->cr_groups))); \
(kp)->p_ngroups = (uc)->cr_ngroups; \
\
(kp)->p_jobc = (pg)->pg_jobc; \
(kp)->p_uticks = (p)->p_tu.tu_uticks; \
(kp)->p_sticks = (p)->p_tu.tu_sticks; \
(kp)->p_iticks = (p)->p_tu.tu_iticks; \
+ strlcpy((kp)->p_name, (p)->p_name, sizeof((kp)->p_name)); \
} else { \
(kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec; \
(kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_nsec/1000; \
strlcpy((kp)->p_emul, "native", sizeof((kp)->p_emul)); \
strlcpy((kp)->p_comm, (pr)->ps_comm, sizeof((kp)->p_comm)); \
strlcpy((kp)->p_login, (sess)->s_login, \
- _FILL_KPROC_MIN(sizeof((kp)->p_login), sizeof((sess)->s_login))); \
+ _FILL_KPROC_MIN(sizeof((kp)->p_login), sizeof((sess)->s_login))); \
\
if ((sess)->s_ttyvp) \
(kp)->p_eflag |= EPROC_CTTY; \
-/* $OpenBSD: machine.c,v 1.112 2022/09/10 16:58:51 cheloha Exp $ */
+/* $OpenBSD: machine.c,v 1.113 2023/01/07 05:24:59 guenther Exp $ */
/*-
* Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com>
/* Filter set, process name needs to contain term */
if (strstr(proc->p_comm, term))
return 1;
+ /* If thread name set, search that too */
+ if (strstr(proc->p_name, term))
+ return 1;
/* If showing arguments, search those as well */
if (show_args) {
args = get_proc_args(proc);
char **p, **s;
extern int show_args;
- if (!show_args)
- return (kp->p_comm);
-
- s = get_proc_args(kp);
- if (s == NULL)
- return kp->p_comm;
-
- buf[0] = '\0';
- for (p = s; *p != NULL; p++) {
- if (p != s)
- strlcat(buf, " ", sizeof(buf));
- strlcat(buf, *p, sizeof(buf));
+ if (show_args && (s = get_proc_args(kp)) != NULL) {
+ buf[0] = '\0';
+ for (p = s; *p != NULL; p++) {
+ if (p != s)
+ strlcat(buf, " ", sizeof(buf));
+ strlcat(buf, *p, sizeof(buf));
+ }
+ if (buf[0] != '\0')
+ return buf;
+ }
+ if (kp->p_name[0] != '\0') {
+ snprintf(buf, sizeof buf, "%s/%s", kp->p_comm,
+ kp->p_name);
+ return buf;
}
- if (buf[0] == '\0')
- return (kp->p_comm);
- return (buf);
+ return kp->p_comm;
}
void