From nobody Sat May 11 19:39:18 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VcGKL5Q0yz5KfyC; Sat, 11 May 2024 19:39:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VcGKL3N0mz4Tf4; Sat, 11 May 2024 19:39:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715456358; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pQOjtCOdlBCKUcxcZmMcyUmiwlc7DwPuatskWT3KuMM=; b=IponVeotLgrktjJRChVeK73mntO41NSxdTeaOhH8ANdoWNwKhcZ1CEdYSSs+IWDVs5am4S CVtmqQ9zIou2hsWLbuWZ/vXREQRu3vhNFXOqU2gNkwFg9y3ScaWF3pAIC3v4KCYmDsHDwd Jdz7Mp9RoIrFQDij31fqDSHIeudH2cDPPws3PBq/7+tL5G1zDrLNjVfNl1RnRkWxo4fbXz 5Tv9Aqwuzz+wgmmXJ3rl2QfhHQsA+x7v9au4FVdT7G6FXw7U0GldTTNqT7YfSCHbkqGo62 owhNTHToKu86qFp4bbTM9zVUSx5eEqISgjlQoKCzj71wYNnYJCnDELQ7lxHOCQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715456358; a=rsa-sha256; cv=none; b=kYtsLl96TgowROgdPB4s03QHfPtygJ4/4fP/xrqrqfvdC8KFqXgJwkEw0apZ+1LBaSP8EF 6Ak8mnLXqyAPxsze5XG310kEGZwfsITzEXBi4LIj8nKJs3wBc+KCGHCUIotpEIdfR/lCdL rQiEyI2jMEd7RKb53jnm8DLoOsQHO1ZeyWgNOYqhGcopXcnkX0FQXQ92KynRcpByEywqGe iNhF6Ri0X2LpTG+HYg/9tN1nINjDgklNxJ94KYPqP2QomeqlCVyjTBXfNi0wqydDzqo+YC 91PCmh2Vn/EEAB+oxHSBja66X6V7j5AGiWPCBL83KxjmUkZhdx7yZkgGMXb6hw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715456358; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pQOjtCOdlBCKUcxcZmMcyUmiwlc7DwPuatskWT3KuMM=; b=ZV4iE9EcYcN4xlbxDsvfnD5rZ8UyQ0gQfBRBKczqhpIEIzw4uaipanc4ELQbOYEiI5KuUx F/t3eF7vElL0hmkYQEBP7f4xY6/eeU19d2t0FYCcPrtrToIGo8JxiIyXp2V7Ica/HZJm0i K3KRpmCyddNe69J3o2DQzhim9PKteZalcCbGHguEUqQ1Sz8oMyB8mZRGPchKjdFEcVtSx0 AakiDjOXcWQmSekXGBC704U7H4eAP7/etw/QEfHTA9ri5ZHnjx8RWrRId5q8BRNYZd6VH0 Oly+DL4P0i4dKn4iSHvuc8Er5TVF7nwT3xcS9YBqKymbl+6oZI+rsm/hA6VbvA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VcGKL3034zZMN; Sat, 11 May 2024 19:39:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44BJdIaR045796; Sat, 11 May 2024 19:39:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44BJdIE5045793; Sat, 11 May 2024 19:39:18 GMT (envelope-from git) Date: Sat, 11 May 2024 19:39:18 GMT Message-Id: <202405111939.44BJdIE5045793@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 099a81a4173b - main - linprocfs: Add support for proc/sysvipc/{msg,sem,shm} List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 099a81a4173bc5b121e50d4e27ea5fafdda8475b Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=099a81a4173bc5b121e50d4e27ea5fafdda8475b commit 099a81a4173bc5b121e50d4e27ea5fafdda8475b Author: Ricardo Branco AuthorDate: 2024-05-04 13:38:20 +0000 Commit: Warner Losh CommitDate: 2024-05-11 19:37:47 +0000 linprocfs: Add support for proc/sysvipc/{msg,sem,shm} Signed-off-by: Ricardo Branco Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1218 --- sys/compat/linprocfs/linprocfs.c | 182 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c index 391d5f679ee5..a877d4065c18 100644 --- a/sys/compat/linprocfs/linprocfs.c +++ b/sys/compat/linprocfs/linprocfs.c @@ -126,6 +126,9 @@ #define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */ #define TV2J(x) ((x)->tv_sec * 100UL + (x)->tv_usec / 10000) +/* Value defined in sys/kern/sysv_shm.c */ +#define SHMSEG_ALLOCATED 0x0800 + /** * @brief Mapping of ki_stat in struct kinfo_proc to the linux state * @@ -2092,6 +2095,176 @@ linprocfs_domax_map_cnt(PFS_FILL_ARGS) return (0); } +/* + * Filler function for proc/sysvipc/msg + */ +static int +linprocfs_dosysvipc_msg(PFS_FILL_ARGS) +{ + struct msqid_kernel *msqids; + u_long id, msgmni; + size_t sz; + int error; + + sbuf_printf(sb, + "%10s %10s %4s %10s %10s %5s %5s %5s %5s %5s %5s %10s %10s %10s\n", + "key", "msqid", "perms", "cbytes", "qnum", "lspid", "lrpid", + "uid", "gid", "cuid", "cgid", "stime", "rtime", "ctime"); + +again: + msgmni = msginfo.msgmni; + sz = sizeof(struct msqid_kernel) * msgmni; + msqids = malloc(sz, M_TEMP, M_NOWAIT); + if (msqids == NULL) + return (ENOMEM); + if (msgmni != msginfo.msgmni) { + free(msqids, M_TEMP); + goto again; + } + + error = kernel_sysctlbyname(curthread, "kern.ipc.msqids", msqids, &sz, + NULL, 0, 0, 0); + if (error != 0) { + free(msqids, M_TEMP); + return (error); + } + msgmni = sz / sizeof(struct msqid_kernel); + + for (id = 0; id < msgmni; id++) + if (msqids[id].u.msg_qbytes != 0) + sbuf_printf(sb, + "%10d %10lu %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10ld %10ld %10ld\n", + (int) msqids[id].u.msg_perm.key, + IXSEQ_TO_IPCID(id, msqids[id].u.msg_perm), + msqids[id].u.msg_perm.mode, + msqids[id].u.msg_cbytes, + msqids[id].u.msg_qnum, + msqids[id].u.msg_lspid, + msqids[id].u.msg_lrpid, + msqids[id].u.msg_perm.uid, + msqids[id].u.msg_perm.gid, + msqids[id].u.msg_perm.cuid, + msqids[id].u.msg_perm.cgid, + msqids[id].u.msg_stime, + msqids[id].u.msg_rtime, + msqids[id].u.msg_ctime); + + free(msqids, M_TEMP); + return (0); +} + +/* + * Filler function for proc/sysvipc/sem + */ +static int +linprocfs_dosysvipc_sem(PFS_FILL_ARGS) +{ + struct semid_kernel *semids; + u_long id, semmni; + size_t sz; + int error; + + sbuf_printf(sb, "%10s %10s %4s %10s %5s %5s %5s %5s %10s %10s\n", + "key", "semid", "perms", "nsems", "uid", "gid", "cuid", "cgid", + "otime", "ctime"); + +again: + semmni = seminfo.semmni; + sz = sizeof(struct semid_kernel) * semmni; + semids = malloc(sz, M_TEMP, M_NOWAIT); + if (semids == NULL) + return (ENOMEM); + if (semmni != seminfo.semmni) { + free(semids, M_TEMP); + goto again; + } + + error = kernel_sysctlbyname(curthread, "kern.ipc.sema", semids, &sz, + NULL, 0, 0, 0); + if (error != 0) { + free(semids, M_TEMP); + return (error); + } + semmni = sz / sizeof(struct semid_kernel); + + for (id = 0; id < semmni; id++) + if ((semids[id].u.sem_perm.mode & SEM_ALLOC) != 0) + sbuf_printf(sb, + "%10d %10lu %4o %10u %5u %5u %5u %5u %10ld %10ld\n", + (int) semids[id].u.sem_perm.key, + IXSEQ_TO_IPCID(id, semids[id].u.sem_perm), + semids[id].u.sem_perm.mode, + semids[id].u.sem_nsems, + semids[id].u.sem_perm.uid, + semids[id].u.sem_perm.gid, + semids[id].u.sem_perm.cuid, + semids[id].u.sem_perm.cgid, + semids[id].u.sem_otime, + semids[id].u.sem_ctime); + + free(semids, M_TEMP); + return (0); +} + +/* + * Filler function for proc/sysvipc/shm + */ +static int +linprocfs_dosysvipc_shm(PFS_FILL_ARGS) +{ + struct shmid_kernel *shmids; + u_long id, shmmni; + size_t sz; + int error; + + sbuf_printf(sb, + "%10s %10s %s %21s %5s %5s %5s %5s %5s %5s %5s %10s %10s %10s %21s %21s\n", + "key", "shmid", "perms", "size", "cpid", "lpid", "nattch", "uid", + "gid", "cuid", "cgid", "atime", "dtime", "ctime", "rss", "swap"); + +again: + shmmni = shminfo.shmmni; + sz = sizeof(struct shmid_kernel) * shmmni; + shmids = malloc(sz, M_TEMP, M_NOWAIT); + if (shmids == NULL) + return (ENOMEM); + if (shmmni != shminfo.shmmni) { + free(shmids, M_TEMP); + goto again; + } + + error = kernel_sysctlbyname(curthread, "kern.ipc.shmsegs", shmids, &sz, + NULL, 0, 0, 0); + if (error != 0) { + free(shmids, M_TEMP); + return (error); + } + shmmni = sz / sizeof(struct shmid_kernel); + + for (id = 0; id < shmmni; id++) + if ((shmids[id].u.shm_perm.mode & SHMSEG_ALLOCATED) != 0) + sbuf_printf(sb, + "%10d %10lu %4o %21lu %5u %5u %5u %5u %5u %5u %5u %10ld %10ld %10ld %21d %21d\n", + (int) shmids[id].u.shm_perm.key, + IXSEQ_TO_IPCID(id, shmids[id].u.shm_perm), + shmids[id].u.shm_perm.mode, + shmids[id].u.shm_segsz, + shmids[id].u.shm_cpid, + shmids[id].u.shm_lpid, + shmids[id].u.shm_nattch, + shmids[id].u.shm_perm.uid, + shmids[id].u.shm_perm.gid, + shmids[id].u.shm_perm.cuid, + shmids[id].u.shm_perm.cgid, + shmids[id].u.shm_atime, + shmids[id].u.shm_dtime, + shmids[id].u.shm_ctime, + 0, 0); /* XXX rss & swp are not supported */ + + free(shmids, M_TEMP); + return (0); +} + /* * Constructor */ @@ -2241,6 +2414,15 @@ linprocfs_init(PFS_INIT_ARGS) pfs_create_file(dir, "max_map_count", &linprocfs_domax_map_cnt, NULL, NULL, NULL, PFS_RD); + /* /proc/sysvipc/... */ + dir = pfs_create_dir(root, "sysvipc", NULL, NULL, NULL, 0); + pfs_create_file(dir, "msg", &linprocfs_dosysvipc_msg, + NULL, NULL, NULL, PFS_RD); + pfs_create_file(dir, "sem", &linprocfs_dosysvipc_sem, + NULL, NULL, NULL, PFS_RD); + pfs_create_file(dir, "shm", &linprocfs_dosysvipc_shm, + NULL, NULL, NULL, PFS_RD); + return (0); }