Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 May 2024 23:59:18 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 25a04527b706 - main - linprocfs: Add support for proc/sysvipc/{msg,sem,shm}
Message-ID:  <202405212359.44LNxIYv032845@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=25a04527b706577dac781fc249e3dbe948ccae60

commit 25a04527b706577dac781fc249e3dbe948ccae60
Author:     Ricardo Branco <rbranco@suse.de>
AuthorDate: 2024-05-12 20:26:15 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-05-21 23:58:28 +0000

    linprocfs: Add support for proc/sysvipc/{msg,sem,shm}
    
    Reviewed by: imp,kib
    Pull Request: https://github.com/freebsd/freebsd-src/pull/1232
---
 sys/compat/linprocfs/linprocfs.c | 137 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 137 insertions(+)

diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index 391d5f679ee5..bfa2074a78d3 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -2092,6 +2092,134 @@ 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;
+	size_t id, size;
+	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");
+
+	error = kern_get_msqids(curthread, &msqids, &size);
+	if (error != 0)
+		return (error);
+
+	for (id = 0; id < size; id++) {
+		if (msqids[id].u.msg_qbytes == 0)
+			continue;
+		sbuf_printf(sb,
+		    "%10d %10lu  %4o  %10lu %10lu %5u %5u %5u %5u %5u %5u %jd %jd %jd\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,
+		    (intmax_t)msqids[id].u.msg_stime,
+		    (intmax_t)msqids[id].u.msg_rtime,
+		    (intmax_t)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;
+	size_t id, size;
+	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");
+
+	error = kern_get_sema(curthread, &semids, &size);
+	if (error != 0)
+		return (error);
+
+	for (id = 0; id < size; id++) {
+		if ((semids[id].u.sem_perm.mode & SEM_ALLOC) == 0)
+			continue;
+		sbuf_printf(sb,
+		    "%10d %10lu  %4o %10u %5u %5u %5u %5u %jd %jd\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,
+		    (intmax_t)semids[id].u.sem_otime,
+		    (intmax_t)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;
+	size_t id, size;
+	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");
+
+	error = kern_get_shmsegs(curthread, &shmids, &size);
+	if (error != 0)
+		return (error);
+
+	for (id = 0; id < size; id++) {
+		if ((shmids[id].u.shm_perm.mode & SHMSEG_ALLOCATED) == 0)
+			continue;
+		sbuf_printf(sb,
+		    "%10d %10lu  %4o %21zu %5u %5u  %5u %5u %5u %5u %5u %jd %jd %jd %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,
+		    (intmax_t)shmids[id].u.shm_atime,
+		    (intmax_t)shmids[id].u.shm_dtime,
+		    (intmax_t)shmids[id].u.shm_ctime,
+		    0, 0);	/* XXX rss & swp are not supported */
+	}
+
+	free(shmids, M_TEMP);
+	return (0);
+}
+
 /*
  * Constructor
  */
@@ -2241,6 +2369,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);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202405212359.44LNxIYv032845>