Index: stable/11/sys/sys/ipc.h =================================================================== --- stable/11/sys/sys/ipc.h (revision 347994) +++ stable/11/sys/sys/ipc.h (revision 347995) @@ -1,148 +1,150 @@ /*- * Copyright (c) 1988 University of Utah. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph * Co. or Unix System Laboratories, Inc. and are reproduced herein with * the permission of UNIX System Laboratories, Inc. * * This code is derived from software contributed to Berkeley by * the Systems Programming Group of the University of Utah Computer * Science Department. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)ipc.h 8.4 (Berkeley) 2/19/95 * $FreeBSD$ */ /* * SVID compatible ipc.h file */ #ifndef _SYS_IPC_H_ #define _SYS_IPC_H_ #include #include #ifndef _GID_T_DECLARED typedef __gid_t gid_t; #define _GID_T_DECLARED #endif #ifndef _KEY_T_DECLARED typedef __key_t key_t; #define _KEY_T_DECLARED #endif #ifndef _MODE_T_DECLARED typedef __mode_t mode_t; #define _MODE_T_DECLARED #endif #ifndef _UID_T_DECLARED typedef __uid_t uid_t; #define _UID_T_DECLARED #endif #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) || \ defined(COMPAT_43) struct ipc_perm_old { unsigned short cuid; /* creator user id */ unsigned short cgid; /* creator group id */ unsigned short uid; /* user id */ unsigned short gid; /* group id */ unsigned short mode; /* r/w permission */ unsigned short seq; /* sequence # (to generate unique ipcid) */ key_t key; /* user specified msg/sem/shm key */ }; #endif struct ipc_perm { uid_t cuid; /* creator user id */ gid_t cgid; /* creator group id */ uid_t uid; /* user id */ gid_t gid; /* group id */ mode_t mode; /* r/w permission */ unsigned short seq; /* sequence # (to generate unique ipcid) */ key_t key; /* user specified msg/sem/shm key */ }; #if __BSD_VISIBLE /* common mode bits */ #define IPC_R 000400 /* read permission */ #define IPC_W 000200 /* write/alter permission */ #define IPC_M 010000 /* permission to change control info */ #endif /* SVID required constants (same values as system 5) */ #define IPC_CREAT 001000 /* create entry if key does not exist */ #define IPC_EXCL 002000 /* fail if key exists */ #define IPC_NOWAIT 004000 /* error if request must wait */ #define IPC_PRIVATE (key_t)0 /* private key */ #define IPC_RMID 0 /* remove identifier */ #define IPC_SET 1 /* set options */ #define IPC_STAT 2 /* get options */ #if __BSD_VISIBLE /* * For Linux compatibility. */ #define IPC_INFO 3 /* get info */ #endif -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_WANT_SYSVIPC_INTERNALS) /* Macros to convert between ipc ids and array indices or sequence ids */ #define IPCID_TO_IX(id) ((id) & 0xffff) #define IPCID_TO_SEQ(id) (((id) >> 16) & 0xffff) #define IXSEQ_TO_IPCID(ix,perm) (((perm.seq) << 16) | (ix & 0xffff)) +#endif +#ifdef _KERNEL struct thread; struct proc; struct vmspace; #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) void ipcperm_old2new(struct ipc_perm_old *, struct ipc_perm *); void ipcperm_new2old(struct ipc_perm *, struct ipc_perm_old *); #endif int ipcperm(struct thread *, struct ipc_perm *, int); extern void (*shmfork_hook)(struct proc *, struct proc *); extern void (*shmexit_hook)(struct vmspace *); #else /* ! _KERNEL */ __BEGIN_DECLS key_t ftok(const char *, int); __END_DECLS #endif /* _KERNEL */ #endif /* !_SYS_IPC_H_ */ Index: stable/11/sys/sys/msg.h =================================================================== --- stable/11/sys/sys/msg.h (revision 347994) +++ stable/11/sys/sys/msg.h (revision 347995) @@ -1,182 +1,187 @@ /* $FreeBSD$ */ /* $NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $ */ /*- * SVID compatible msg.h file * * Author: Daniel Boulet * * Copyright 1993 Daniel Boulet and RTMX Inc. * * This system call was implemented by Daniel Boulet under contract from RTMX. * * Redistribution and use in source forms, with and without modification, * are permitted provided that this entire comment appears intact. * * Redistribution in binary form may occur without any restrictions. * Obviously, it would be nice if you gave credit where credit is due * but requiring it would be too onerous. * * This software is provided ``AS IS'' without any warranties of any kind. */ #ifndef _SYS_MSG_H_ #define _SYS_MSG_H_ #include #include +#ifdef _WANT_SYSVMSG_INTERNALS +#define _WANT_SYSVIPC_INTERNALS +#endif #include /* * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct * are as defined by the SV API Intel 386 Processor Supplement. */ #define MSG_NOERROR 010000 /* don't complain about too long msgs */ typedef unsigned long msglen_t; typedef unsigned long msgqnum_t; #ifndef _PID_T_DECLARED typedef __pid_t pid_t; #define _PID_T_DECLARED #endif #ifndef _SIZE_T_DECLARED typedef __size_t size_t; #define _SIZE_T_DECLARED #endif #ifndef _SSIZE_T_DECLARED typedef __ssize_t ssize_t; #define _SSIZE_T_DECLARED #endif #ifndef _TIME_T_DECLARED typedef __time_t time_t; #define _TIME_T_DECLARED #endif #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) struct msqid_ds_old { struct ipc_perm_old msg_perm; /* msg queue permission bits */ struct msg *msg_first; /* first message in the queue */ struct msg *msg_last; /* last message in the queue */ msglen_t msg_cbytes; /* number of bytes in use on the queue */ msgqnum_t msg_qnum; /* number of msgs in the queue */ msglen_t msg_qbytes; /* max # of bytes on the queue */ pid_t msg_lspid; /* pid of last msgsnd() */ pid_t msg_lrpid; /* pid of last msgrcv() */ time_t msg_stime; /* time of last msgsnd() */ long msg_pad1; time_t msg_rtime; /* time of last msgrcv() */ long msg_pad2; time_t msg_ctime; /* time of last msgctl() */ long msg_pad3; long msg_pad4[4]; }; #endif /* * XXX there seems to be no prefix reserved for this header, so the name * "msg" in "struct msg" and the names of all of the nonstandard members * (mainly "msg_pad*) are namespace pollution. */ struct msqid_ds { struct ipc_perm msg_perm; /* msg queue permission bits */ struct msg *msg_first; /* first message in the queue */ struct msg *msg_last; /* last message in the queue */ msglen_t msg_cbytes; /* number of bytes in use on the queue */ msgqnum_t msg_qnum; /* number of msgs in the queue */ msglen_t msg_qbytes; /* max # of bytes on the queue */ pid_t msg_lspid; /* pid of last msgsnd() */ pid_t msg_lrpid; /* pid of last msgrcv() */ time_t msg_stime; /* time of last msgsnd() */ time_t msg_rtime; /* time of last msgrcv() */ time_t msg_ctime; /* time of last msgctl() */ }; #if __BSD_VISIBLE /* * Structure describing a message. The SVID doesn't suggest any * particular name for this structure. There is a reference in the * msgop man page that reads "The structure mymsg is an example of what * this user defined buffer might look like, and includes the following * members:". This sentence is followed by two lines equivalent * to the mtype and mtext field declarations below. It isn't clear * if "mymsg" refers to the name of the structure type or the name of an * instance of the structure... */ struct mymsg { long mtype; /* message type (+ve integer) */ char mtext[1]; /* message body */ }; #endif #ifdef _KERNEL - struct msg { struct msg *msg_next; /* next msg in the chain */ long msg_type; /* type of this message */ /* >0 -> type of this message */ /* 0 -> free header */ u_short msg_ts; /* size of this message */ short msg_spot; /* location of start of msg in buffer */ struct label *label; /* MAC Framework label */ }; +#endif +#if defined(_KERNEL) || defined(_WANT_SYSVMSG_INTERNALS) /* * Based on the configuration parameters described in an SVR2 (yes, two) * config(1m) man page. * * Each message is broken up and stored in segments that are msgssz bytes * long. For efficiency reasons, this should be a power of two. Also, * it doesn't make sense if it is less than 8 or greater than about 256. * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of * two between 8 and 1024 inclusive (and panic's if it isn't). */ struct msginfo { int msgmax, /* max chars in a message */ msgmni, /* max message queue identifiers */ msgmnb, /* max chars in a queue */ msgtql, /* max messages in system */ msgssz, /* size of a message segment (see notes above) */ msgseg; /* number of message segments */ }; -extern struct msginfo msginfo; /* * Kernel wrapper for the user-level structure. */ struct msqid_kernel { /* * Data structure exposed to user space. */ struct msqid_ds u; /* * Kernel-private components of the message queue. */ struct label *label; /* MAC label */ struct ucred *cred; /* creator's credentials */ }; +#endif -#endif /* _KERNEL */ +#ifdef _KERNEL +extern struct msginfo msginfo; -#if !defined(_KERNEL) || defined(_WANT_MSG_PROTOTYPES) +#else /* _KERNEL */ + __BEGIN_DECLS int msgctl(int, int, struct msqid_ds *); int msgget(key_t, int); /* XXX return value should be ssize_t. */ int msgrcv(int, void *, size_t, long, int); int msgsnd(int, const void *, size_t, int); #if __BSD_VISIBLE int msgsys(int, ...); #endif __END_DECLS - -#endif /* !_KERNEL || _WANT_MSG_PROTOTYPES */ +#endif /* !_KERNEL */ #endif /* !_SYS_MSG_H_ */ Index: stable/11/sys/sys/sem.h =================================================================== --- stable/11/sys/sys/sem.h (revision 347994) +++ stable/11/sys/sys/sem.h (revision 347995) @@ -1,154 +1,157 @@ /* $FreeBSD$ */ /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */ /* * SVID compatible sem.h file * * Author: Daniel Boulet */ #ifndef _SYS_SEM_H_ #define _SYS_SEM_H_ +#ifdef _WANT_SYSVSEM_INTERNALS +#define _WANT_SYSVIPC_INTERNALS +#endif #include #ifndef _PID_T_DECLARED typedef __pid_t pid_t; #define _PID_T_DECLARED #endif #ifndef _SIZE_T_DECLARED typedef __size_t size_t; #define _SIZE_T_DECLARED #endif #ifndef _TIME_T_DECLARED typedef __time_t time_t; #define _TIME_T_DECLARED #endif #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) struct semid_ds_old { struct ipc_perm_old sem_perm; /* operation permission struct */ struct sem *sem_base; /* pointer to first semaphore in set */ unsigned short sem_nsems; /* number of sems in set */ time_t sem_otime; /* last operation time */ long sem_pad1; /* SVABI/386 says I need this here */ time_t sem_ctime; /* last change time */ /* Times measured in secs since */ /* 00:00:00 UTC, Jan. 1, 1970, without leap seconds */ long sem_pad2; /* SVABI/386 says I need this here */ long sem_pad3[4]; /* SVABI/386 says I need this here */ }; #endif struct semid_ds { struct ipc_perm sem_perm; /* operation permission struct */ struct sem *sem_base; /* pointer to first semaphore in set */ unsigned short sem_nsems; /* number of sems in set */ time_t sem_otime; /* last operation time */ time_t sem_ctime; /* last change time */ /* Times measured in secs since */ /* 00:00:00 UTC, Jan. 1, 1970, without leap seconds */ }; /* * semop's sops parameter structure */ struct sembuf { unsigned short sem_num; /* semaphore # */ short sem_op; /* semaphore operation */ short sem_flg; /* operation flags */ }; #define SEM_UNDO 010000 #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) || \ defined(_WANT_SEMUN_OLD) union semun_old { int val; /* value for SETVAL */ struct semid_ds_old *buf; /* buffer for IPC_STAT & IPC_SET */ unsigned short *array; /* array for GETALL & SETALL */ }; #endif /* * semctl's arg parameter structure */ union semun { int val; /* value for SETVAL */ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ unsigned short *array; /* array for GETALL & SETALL */ }; /* * commands for semctl */ #define GETNCNT 3 /* Return the value of semncnt {READ} */ #define GETPID 4 /* Return the value of sempid {READ} */ #define GETVAL 5 /* Return the value of semval {READ} */ #define GETALL 6 /* Return semvals into arg.array {READ} */ #define GETZCNT 7 /* Return the value of semzcnt {READ} */ #define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */ #define SETALL 9 /* Set semvals from arg.array {ALTER} */ #define SEM_STAT 10 /* Like IPC_STAT but treats semid as sema-index */ #define SEM_INFO 11 /* Like IPC_INFO but treats semid as sema-index */ /* * Permissions */ #define SEM_A IPC_W /* alter permission */ #define SEM_R IPC_R /* read permission */ -#ifdef _KERNEL - +#if defined(_KERNEL) || defined(_WANT_SYSVSEM_INTERNALS) /* * semaphore info struct */ struct seminfo { int semmni, /* # of semaphore identifiers */ semmns, /* # of semaphores in system */ semmnu, /* # of undo structures in system */ semmsl, /* max # of semaphores per id */ semopm, /* max # of operations per semop call */ semume, /* max # of undo entries per process */ semusz, /* size in bytes of undo structure */ semvmx, /* semaphore maximum value */ semaem; /* adjust on exit max value */ }; -extern struct seminfo seminfo; /* * Kernel wrapper for the user-level structure */ struct semid_kernel { struct semid_ds u; struct label *label; /* MAC framework label */ struct ucred *cred; /* creator's credentials */ }; /* internal "mode" bits */ #define SEM_ALLOC 01000 /* semaphore is allocated */ #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */ +#endif +#ifdef _KERNEL +extern struct seminfo seminfo; /* * Process sem_undo vectors at proc exit. */ void semexit(struct proc *p); -#endif /* _KERNEL */ +#else /* !_KERNEL */ -#if !defined(_KERNEL) || defined(_WANT_SEM_PROTOTYPES) __BEGIN_DECLS #if __BSD_VISIBLE int semsys(int, ...); #endif int semctl(int, int, int, ...); int semget(key_t, int, int); int semop(int, struct sembuf *, size_t); __END_DECLS -#endif /* !_KERNEL || _WANT_SEM_PROTOTYPES */ +#endif /* !_KERNEL */ #endif /* !_SYS_SEM_H_ */ Index: stable/11/sys/sys/shm.h =================================================================== --- stable/11/sys/sys/shm.h (revision 347994) +++ stable/11/sys/sys/shm.h (revision 347995) @@ -1,172 +1,176 @@ /* $FreeBSD$ */ /* $NetBSD: shm.h,v 1.15 1994/06/29 06:45:17 cgd Exp $ */ /*- * Copyright (c) 1994 Adam Glass * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Adam Glass. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * As defined+described in "X/Open System Interfaces and Headers" * Issue 4, p. XXX */ #ifndef _SYS_SHM_H_ #define _SYS_SHM_H_ #include +#ifdef _WANT_SYSVSHM_INTERNALS +#define _WANT_SYSVIPC_INTERNALS +#endif #include #include #include #define SHM_RDONLY 010000 /* Attach read-only (else read-write) */ #define SHM_RND 020000 /* Round attach address to SHMLBA */ #define SHM_REMAP 030000 /* Unmap before mapping */ #define SHMLBA PAGE_SIZE /* Segment low boundary address multiple */ /* "official" access mode definitions; somewhat braindead since you have to specify (SHM_* >> 3) for group and (SHM_* >> 6) for world permissions */ #define SHM_R (IPC_R) #define SHM_W (IPC_W) /* predefine tbd *LOCK shmctl commands */ #define SHM_LOCK 11 #define SHM_UNLOCK 12 /* ipcs shmctl commands for Linux compatibility */ #define SHM_STAT 13 #define SHM_INFO 14 #ifndef _PID_T_DECLARED typedef __pid_t pid_t; #define _PID_T_DECLARED #endif #ifndef _TIME_T_DECLARED typedef __time_t time_t; #define _TIME_T_DECLARED #endif #ifndef _SIZE_T_DECLARED typedef __size_t size_t; #define _SIZE_T_DECLARED #endif #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) struct shmid_ds_old { struct ipc_perm_old shm_perm; /* operation permission structure */ int shm_segsz; /* size of segment in bytes */ pid_t shm_lpid; /* process ID of last shared memory op */ pid_t shm_cpid; /* process ID of creator */ short shm_nattch; /* number of current attaches */ time_t shm_atime; /* time of last shmat() */ time_t shm_dtime; /* time of last shmdt() */ time_t shm_ctime; /* time of last change by shmctl() */ void *shm_internal; /* sysv stupidity */ }; #endif struct shmid_ds { struct ipc_perm shm_perm; /* operation permission structure */ size_t shm_segsz; /* size of segment in bytes */ pid_t shm_lpid; /* process ID of last shared memory op */ pid_t shm_cpid; /* process ID of creator */ int shm_nattch; /* number of current attaches */ time_t shm_atime; /* time of last shmat() */ time_t shm_dtime; /* time of last shmdt() */ time_t shm_ctime; /* time of last change by shmctl() */ }; -#ifdef _KERNEL -#include - +#if defined(_KERNEL) || defined(_WANT_SYSVSHM_INTERNALS) /* * System 5 style catch-all structure for shared memory constants that * might be of interest to user programs. Do we really want/need this? */ struct shminfo { u_long shmmax; /* max shared memory segment size (bytes) */ u_long shmmin; /* max shared memory segment size (bytes) */ u_long shmmni; /* max number of shared memory identifiers */ u_long shmseg; /* max shared memory segments per process */ u_long shmall; /* max amount of shared memory (pages) */ }; +struct vm_object; + /* * Add a kernel wrapper to the shmid_ds struct so that private info (like the * MAC label) can be added to it, without changing the user interface. */ struct shmid_kernel { struct shmid_ds u; - vm_object_t object; + struct vm_object *object; struct label *label; /* MAC label */ struct ucred *cred; /* creator's credendials */ }; +#endif -extern struct shminfo shminfo; - struct shm_info { int used_ids; unsigned long shm_tot; unsigned long shm_rss; unsigned long shm_swp; unsigned long swap_attempts; unsigned long swap_successes; }; -struct thread; +#ifdef _KERNEL struct proc; struct vmspace; +extern struct shminfo shminfo; + void shmexit(struct vmspace *); void shmfork(struct proc *, struct proc *); -#endif /* _KERNEL */ -#if !defined(_KERNEL) || defined(_WANT_SHM_PROTOTYPES) +#else /* !_KERNEL */ + #include #ifndef _SIZE_T_DECLARED typedef __size_t size_t; #define _SIZE_T_DECLARED #endif __BEGIN_DECLS #if __BSD_VISIBLE int shmsys(int, ...); #endif void *shmat(int, const void *, int); int shmget(key_t, size_t, int); int shmctl(int, int, struct shmid_ds *); int shmdt(const void *); __END_DECLS -#endif /* _KERNEL || _WANT_SHM_PROTOTYPES */ +#endif /* _KERNEL */ #endif /* !_SYS_SHM_H_ */ Index: stable/11/usr.bin/ipcrm/ipcrm.c =================================================================== --- stable/11/usr.bin/ipcrm/ipcrm.c (revision 347994) +++ stable/11/usr.bin/ipcrm/ipcrm.c (revision 347995) @@ -1,302 +1,300 @@ /*- * SPDX-License-Identifier: BSD-4-Clause * * Copyright (c) 1994 Adam Glass * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Adam Glass. * 4. The name of the Author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL Adam Glass BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include __FBSDID("$FreeBSD$"); #include -#define _WANT_MSG_PROTOTYPES -#define _WANT_SEM_PROTOTYPES -#define _WANT_SHM_PROTOTYPES -#define _KERNEL +#define _WANT_SYSVMSG_INTERNALS +#include +#define _WANT_SYSVSEM_INTERNALS #include +#define _WANT_SYSVSHM_INTERNALS #include -#include -#undef _KERNEL #include #include #include #include #include #include #include #include "ipc.h" static int signaled; static int errflg; static int rmverbose = 0; static void usage(void) { fprintf(stderr, "usage: ipcrm [-W] [-v[v]]\n" " [-q msqid] [-m shmid] [-s semid]\n" " [-Q msgkey] [-M shmkey] [-S semkey] ...\n"); exit(1); } static int msgrm(key_t key, int id) { if (key == -1 || id == -1) { struct msqid_kernel *kxmsqids; size_t kxmsqids_len; int num; kget(X_MSGINFO, &msginfo, sizeof(msginfo)); kxmsqids_len = sizeof(struct msqid_kernel) * msginfo.msgmni; kxmsqids = malloc(kxmsqids_len); kget(X_MSQIDS, kxmsqids, kxmsqids_len); num = msginfo.msgmni; while (num-- && !signaled) if (kxmsqids[num].u.msg_qbytes != 0) { id = IXSEQ_TO_IPCID(num, kxmsqids[num].u.msg_perm); if (msgctl(id, IPC_RMID, NULL) < 0) { if (rmverbose > 1) warn("msqid(%d): ", id); errflg++; } else if (rmverbose) printf( "Removed %s %d\n", IPC_TO_STRING('Q'), id); } return signaled ? -1 : 0; /* errors maybe handled above */ } if (key) { id = msgget(key, 0); if (id == -1) return -1; } return msgctl(id, IPC_RMID, NULL); } static int shmrm(key_t key, int id) { if (key == -1 || id == -1) { struct shmid_kernel *kxshmids; size_t kxshmids_len; int num; kget(X_SHMINFO, &shminfo, sizeof(shminfo)); kxshmids_len = sizeof(struct shmid_kernel) * shminfo.shmmni; kxshmids = malloc(kxshmids_len); kget(X_SHMSEGS, kxshmids, kxshmids_len); num = shminfo.shmmni; while (num-- && !signaled) if (kxshmids[num].u.shm_perm.mode & 0x0800) { id = IXSEQ_TO_IPCID(num, kxshmids[num].u.shm_perm); if (shmctl(id, IPC_RMID, NULL) < 0) { if (rmverbose > 1) warn("shmid(%d): ", id); errflg++; } else if (rmverbose) printf( "Removed %s %d\n", IPC_TO_STRING('M'), id); } return signaled ? -1 : 0; /* errors maybe handled above */ } if (key) { id = shmget(key, 0, 0); if (id == -1) return -1; } return shmctl(id, IPC_RMID, NULL); } static int semrm(key_t key, int id) { union semun arg; if (key == -1 || id == -1) { struct semid_kernel *kxsema; size_t kxsema_len; int num; kget(X_SEMINFO, &seminfo, sizeof(seminfo)); kxsema_len = sizeof(struct semid_kernel) * seminfo.semmni; kxsema = malloc(kxsema_len); kget(X_SEMA, kxsema, kxsema_len); num = seminfo.semmni; while (num-- && !signaled) if ((kxsema[num].u.sem_perm.mode & SEM_ALLOC) != 0) { id = IXSEQ_TO_IPCID(num, kxsema[num].u.sem_perm); if (semctl(id, 0, IPC_RMID, NULL) < 0) { if (rmverbose > 1) warn("semid(%d): ", id); errflg++; } else if (rmverbose) printf( "Removed %s %d\n", IPC_TO_STRING('S'), id); } return signaled ? -1 : 0; /* errors maybe handled above */ } if (key) { id = semget(key, 0, 0); if (id == -1) return -1; } return semctl(id, 0, IPC_RMID, arg); } static void not_configured(int signo __unused) { signaled++; } int main(int argc, char *argv[]) { int c, result, target_id; key_t target_key; while ((c = getopt(argc, argv, "q:m:s:Q:M:S:vWy")) != -1) { signaled = 0; switch (c) { case 'v': rmverbose++; break; case 'y': use_sysctl = 0; break; } } optind = 1; errflg = 0; signal(SIGSYS, not_configured); while ((c = getopt(argc, argv, "q:m:s:Q:M:S:vWy")) != -1) { signaled = 0; switch (c) { case 'q': case 'm': case 's': target_id = atoi(optarg); if (c == 'q') result = msgrm(0, target_id); else if (c == 'm') result = shmrm(0, target_id); else result = semrm(0, target_id); if (result < 0) { errflg++; if (!signaled) warn("%sid(%d): ", IPC_TO_STR(toupper(c)), target_id); else warnx( "%ss are not configured " "in the running kernel", IPC_TO_STRING(toupper(c))); } break; case 'Q': case 'M': case 'S': target_key = atol(optarg); if (target_key == IPC_PRIVATE) { warnx("can't remove private %ss", IPC_TO_STRING(c)); continue; } if (c == 'Q') result = msgrm(target_key, 0); else if (c == 'M') result = shmrm(target_key, 0); else result = semrm(target_key, 0); if (result < 0) { errflg++; if (!signaled) warn("%ss(%ld): ", IPC_TO_STR(c), target_key); else warnx("%ss are not configured " "in the running kernel", IPC_TO_STRING(c)); } break; case 'v': case 'y': /* Handled in other getopt() loop */ break; case 'W': msgrm(-1, 0); shmrm(-1, 0); semrm(-1, 0); break; case ':': fprintf(stderr, "option -%c requires an argument\n", optopt); usage(); case '?': fprintf(stderr, "unrecognized option: -%c\n", optopt); usage(); } } if (optind != argc) { fprintf(stderr, "unknown argument: %s\n", argv[optind]); usage(); } exit(errflg); } Index: stable/11/usr.bin/ipcs/ipc.c =================================================================== --- stable/11/usr.bin/ipcs/ipc.c (revision 347994) +++ stable/11/usr.bin/ipcs/ipc.c (revision 347995) @@ -1,206 +1,207 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1994 SigmaSoft, Th. Lockert * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The split of ipcs.c into ipcs.c and ipc.c to accommodate the * changes in ipcrm.c was done by Edwin Groothuis */ #include __FBSDID("$FreeBSD$"); #include #include -#define _KERNEL +#define _WANT_SYSVMSG_INTERNALS +#include +#define _WANT_SYSVSEM_INTERNALS #include +#define _WANT_SYSVSHM_INTERNALS #include -#include -#undef _KERNEL #include #include #include #include #include #include "ipc.h" int use_sysctl = 1; struct semid_kernel *sema; struct seminfo seminfo; struct msginfo msginfo; struct msqid_kernel *msqids; struct shminfo shminfo; struct shmid_kernel *shmsegs; struct nlist symbols[] = { { .n_name = "sema" }, { .n_name = "seminfo" }, { .n_name = "msginfo" }, { .n_name = "msqids" }, { .n_name = "shminfo" }, { .n_name = "shmsegs" }, { .n_name = NULL } }; #define SHMINFO_XVEC X(shmmax, sizeof(u_long)) \ X(shmmin, sizeof(u_long)) \ X(shmmni, sizeof(u_long)) \ X(shmseg, sizeof(u_long)) \ X(shmall, sizeof(u_long)) #define SEMINFO_XVEC X(semmni, sizeof(int)) \ X(semmns, sizeof(int)) \ X(semmnu, sizeof(int)) \ X(semmsl, sizeof(int)) \ X(semopm, sizeof(int)) \ X(semume, sizeof(int)) \ X(semusz, sizeof(int)) \ X(semvmx, sizeof(int)) \ X(semaem, sizeof(int)) #define MSGINFO_XVEC X(msgmax, sizeof(int)) \ X(msgmni, sizeof(int)) \ X(msgmnb, sizeof(int)) \ X(msgtql, sizeof(int)) \ X(msgssz, sizeof(int)) \ X(msgseg, sizeof(int)) #define X(a, b) { "kern.ipc." #a, offsetof(TYPEC, a), (b) }, #define TYPEC struct shminfo static struct scgs_vector shminfo_scgsv[] = { SHMINFO_XVEC { .sysctl=NULL } }; #undef TYPEC #define TYPEC struct seminfo static struct scgs_vector seminfo_scgsv[] = { SEMINFO_XVEC { .sysctl=NULL } }; #undef TYPEC #define TYPEC struct msginfo static struct scgs_vector msginfo_scgsv[] = { MSGINFO_XVEC { .sysctl=NULL } }; #undef TYPEC #undef X kvm_t *kd; void sysctlgatherstruct(void *addr, size_t size, struct scgs_vector *vecarr) { struct scgs_vector *xp; size_t tsiz; int rv; for (xp = vecarr; xp->sysctl != NULL; xp++) { assert(xp->offset <= size); tsiz = xp->size; rv = sysctlbyname(xp->sysctl, (char *)addr + xp->offset, &tsiz, NULL, 0); if (rv == -1) err(1, "sysctlbyname: %s", xp->sysctl); if (tsiz != xp->size) errx(1, "%s size mismatch (expected %zu, got %zu)", xp->sysctl, xp->size, tsiz); } } void kget(int idx, void *addr, size_t size) { const char *symn; /* symbol name */ size_t tsiz; int rv; unsigned long kaddr; const char *sym2sysctl[] = { /* symbol to sysctl name table */ "kern.ipc.sema", "kern.ipc.seminfo", "kern.ipc.msginfo", "kern.ipc.msqids", "kern.ipc.shminfo", "kern.ipc.shmsegs" }; assert((unsigned)idx <= sizeof(sym2sysctl) / sizeof(*sym2sysctl)); if (!use_sysctl) { symn = symbols[idx].n_name; if (*symn == '_') symn++; if (symbols[idx].n_type == 0 || symbols[idx].n_value == 0) errx(1, "symbol %s undefined", symn); /* * For some symbols, the value we retrieve is * actually a pointer; since we want the actual value, * we have to manually dereference it. */ switch (idx) { case X_MSQIDS: tsiz = sizeof(msqids); rv = kvm_read(kd, symbols[idx].n_value, &msqids, tsiz); kaddr = (u_long)msqids; break; case X_SHMSEGS: tsiz = sizeof(shmsegs); rv = kvm_read(kd, symbols[idx].n_value, &shmsegs, tsiz); kaddr = (u_long)shmsegs; break; case X_SEMA: tsiz = sizeof(sema); rv = kvm_read(kd, symbols[idx].n_value, &sema, tsiz); kaddr = (u_long)sema; break; default: rv = tsiz = 0; kaddr = symbols[idx].n_value; break; } if ((unsigned)rv != tsiz) errx(1, "%s: %s", symn, kvm_geterr(kd)); if ((unsigned)kvm_read(kd, kaddr, addr, size) != size) errx(1, "%s: %s", symn, kvm_geterr(kd)); } else { switch (idx) { case X_SHMINFO: sysctlgatherstruct(addr, size, shminfo_scgsv); break; case X_SEMINFO: sysctlgatherstruct(addr, size, seminfo_scgsv); break; case X_MSGINFO: sysctlgatherstruct(addr, size, msginfo_scgsv); break; default: tsiz = size; rv = sysctlbyname(sym2sysctl[idx], addr, &tsiz, NULL, 0); if (rv == -1) err(1, "sysctlbyname: %s", sym2sysctl[idx]); if (tsiz != size) errx(1, "%s size mismatch " "(expected %zu, got %zu)", sym2sysctl[idx], size, tsiz); break; } } } Index: stable/11/usr.bin/ipcs/ipc.h =================================================================== --- stable/11/usr.bin/ipcs/ipc.h (revision 347994) +++ stable/11/usr.bin/ipcs/ipc.h (revision 347995) @@ -1,70 +1,73 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1994 SigmaSoft, Th. Lockert * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The split of ipcs.c into ipcs.c and ipc.c to accommodate the * changes in ipcrm.c was done by Edwin Groothuis * * $FreeBSD$ */ /* Part of struct nlist symbols[] */ #define X_SEMA 0 #define X_SEMINFO 1 #define X_MSGINFO 2 #define X_MSQIDS 3 #define X_SHMINFO 4 #define X_SHMSEGS 5 #define SHMINFO 1 #define SHMTOTAL 2 #define MSGINFO 4 #define MSGTOTAL 8 #define SEMINFO 16 #define SEMTOTAL 32 #define IPC_TO_STR(x) (x == 'Q' ? "msq" : (x == 'M' ? "shm" : "sem")) #define IPC_TO_STRING(x) (x == 'Q' ? "message queue" : \ (x == 'M' ? "shared memory segment" : "semaphore")) /* SysCtlGatherStruct structure. */ struct scgs_vector { const char *sysctl; size_t offset; size_t size; }; void kget(int idx, void *addr, size_t size); void sysctlgatherstruct(void *addr, size_t size, struct scgs_vector *vec); extern int use_sysctl; extern struct nlist symbols[]; extern kvm_t *kd; extern struct semid_kernel *sema; extern struct msqid_kernel *msqids; extern struct shmid_kernel *shmsegs; +extern struct seminfo seminfo; +extern struct msginfo msginfo; +extern struct shminfo shminfo; Index: stable/11/usr.bin/ipcs/ipcs.c =================================================================== --- stable/11/usr.bin/ipcs/ipcs.c (revision 347994) +++ stable/11/usr.bin/ipcs/ipcs.c (revision 347995) @@ -1,557 +1,558 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1994 SigmaSoft, Th. Lockert * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include -#define _KERNEL +#define _WANT_SYSVMSG_INTERNALS +#include +#define _WANT_SYSVSEM_INTERNALS #include +#define _WANT_SYSVSHM_INTERNALS #include -#include -#undef _KERNEL #include #include #include #include #include #include #include #include #include #include #include "ipc.h" char *fmt_perm(u_short); void cvt_time(time_t, char *); void usage(void); uid_t user2uid(char *username); void print_kmsqtotal(struct msginfo msginfo); void print_kmsqheader(int option); void print_kmsqptr(int i, int option, struct msqid_kernel *kmsqptr); void print_kshmtotal(struct shminfo shminfo); void print_kshmheader(int option); void print_kshmptr(int i, int option, struct shmid_kernel *kshmptr); void print_ksemtotal(struct seminfo seminfo); void print_ksemheader(int option); void print_ksemptr(int i, int option, struct semid_kernel *ksemaptr); char * fmt_perm(u_short mode) { static char buffer[100]; buffer[0] = '-'; buffer[1] = '-'; buffer[2] = ((mode & 0400) ? 'r' : '-'); buffer[3] = ((mode & 0200) ? 'w' : '-'); buffer[4] = ((mode & 0100) ? 'a' : '-'); buffer[5] = ((mode & 0040) ? 'r' : '-'); buffer[6] = ((mode & 0020) ? 'w' : '-'); buffer[7] = ((mode & 0010) ? 'a' : '-'); buffer[8] = ((mode & 0004) ? 'r' : '-'); buffer[9] = ((mode & 0002) ? 'w' : '-'); buffer[10] = ((mode & 0001) ? 'a' : '-'); buffer[11] = '\0'; return (&buffer[0]); } void cvt_time(time_t t, char *buf) { struct tm *tm; if (t == 0) { strcpy(buf, "no-entry"); } else { tm = localtime(&t); sprintf(buf, "%2d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); } } #define BIGGEST 1 #define CREATOR 2 #define OUTSTANDING 4 #define PID 8 #define TIME 16 int main(int argc, char *argv[]) { int display = SHMINFO | MSGINFO | SEMINFO; int option = 0; char *core = NULL, *user = NULL, *namelist = NULL; char kvmoferr[_POSIX2_LINE_MAX]; /* Error buf for kvm_openfiles. */ int i; u_long shmidx; uid_t uid = 0; while ((i = getopt(argc, argv, "MmQqSsabC:cN:optTu:y")) != -1) switch (i) { case 'a': option |= BIGGEST | CREATOR | OUTSTANDING | PID | TIME; break; case 'b': option |= BIGGEST; break; case 'C': core = optarg; break; case 'c': option |= CREATOR; break; case 'M': display = SHMTOTAL; break; case 'm': display = SHMINFO; break; case 'N': namelist = optarg; break; case 'o': option |= OUTSTANDING; break; case 'p': option |= PID; break; case 'Q': display = MSGTOTAL; break; case 'q': display = MSGINFO; break; case 'S': display = SEMTOTAL; break; case 's': display = SEMINFO; break; case 'T': display = SHMTOTAL | MSGTOTAL | SEMTOTAL; break; case 't': option |= TIME; break; case 'u': user = optarg; uid = user2uid(user); break; case 'y': use_sysctl = 0; break; default: usage(); } /* * If paths to the exec file or core file were specified, we * aren't operating on the running kernel, so we can't use * sysctl. */ if (namelist != NULL || core != NULL) use_sysctl = 0; if (!use_sysctl) { kd = kvm_openfiles(namelist, core, NULL, O_RDONLY, kvmoferr); if (kd == NULL) errx(1, "kvm_openfiles: %s", kvmoferr); switch (kvm_nlist(kd, symbols)) { case 0: break; case -1: errx(1, "unable to read kernel symbol table"); default: break; } } kget(X_MSGINFO, &msginfo, sizeof(msginfo)); if (display & (MSGINFO | MSGTOTAL)) { if (display & MSGTOTAL) print_kmsqtotal(msginfo); if (display & MSGINFO) { struct msqid_kernel *kxmsqids; size_t kxmsqids_len; kxmsqids_len = sizeof(struct msqid_kernel) * msginfo.msgmni; kxmsqids = malloc(kxmsqids_len); kget(X_MSQIDS, kxmsqids, kxmsqids_len); print_kmsqheader(option); for (i = 0; i < msginfo.msgmni; i += 1) { if (kxmsqids[i].u.msg_qbytes != 0) { if (user && uid != kxmsqids[i].u.msg_perm.uid) continue; print_kmsqptr(i, option, &kxmsqids[i]); } } printf("\n"); } } kget(X_SHMINFO, &shminfo, sizeof(shminfo)); if (display & (SHMINFO | SHMTOTAL)) { if (display & SHMTOTAL) print_kshmtotal(shminfo); if (display & SHMINFO) { struct shmid_kernel *kxshmids; size_t kxshmids_len; kxshmids_len = sizeof(struct shmid_kernel) * shminfo.shmmni; kxshmids = malloc(kxshmids_len); kget(X_SHMSEGS, kxshmids, kxshmids_len); print_kshmheader(option); for (shmidx = 0; shmidx < shminfo.shmmni; shmidx += 1) { if (kxshmids[shmidx].u.shm_perm.mode & 0x0800) { if (user && uid != kxshmids[shmidx].u.shm_perm.uid) continue; print_kshmptr(shmidx, option, &kxshmids[shmidx]); } } printf("\n"); } } kget(X_SEMINFO, &seminfo, sizeof(seminfo)); if (display & (SEMINFO | SEMTOTAL)) { struct semid_kernel *kxsema; size_t kxsema_len; if (display & SEMTOTAL) print_ksemtotal(seminfo); if (display & SEMINFO) { kxsema_len = sizeof(struct semid_kernel) * seminfo.semmni; kxsema = malloc(kxsema_len); kget(X_SEMA, kxsema, kxsema_len); print_ksemheader(option); for (i = 0; i < seminfo.semmni; i += 1) { if ((kxsema[i].u.sem_perm.mode & SEM_ALLOC) != 0) { if (user && uid != kxsema[i].u.sem_perm.uid) continue; print_ksemptr(i, option, &kxsema[i]); } } printf("\n"); } } if (!use_sysctl) kvm_close(kd); exit(0); } void print_kmsqtotal(struct msginfo local_msginfo) { printf("msginfo:\n"); printf("\tmsgmax: %12d\t(max characters in a message)\n", local_msginfo.msgmax); printf("\tmsgmni: %12d\t(# of message queues)\n", local_msginfo.msgmni); printf("\tmsgmnb: %12d\t(max characters in a message queue)\n", local_msginfo.msgmnb); printf("\tmsgtql: %12d\t(max # of messages in system)\n", local_msginfo.msgtql); printf("\tmsgssz: %12d\t(size of a message segment)\n", local_msginfo.msgssz); printf("\tmsgseg: %12d\t(# of message segments in system)\n\n", local_msginfo.msgseg); } void print_kmsqheader(int option) { printf("Message Queues:\n"); printf("T %12s %12s %-11s %-8s %-8s", "ID", "KEY", "MODE", "OWNER", "GROUP"); if (option & CREATOR) printf(" %-8s %-8s", "CREATOR", "CGROUP"); if (option & OUTSTANDING) printf(" %20s %20s", "CBYTES", "QNUM"); if (option & BIGGEST) printf(" %20s", "QBYTES"); if (option & PID) printf(" %12s %12s", "LSPID", "LRPID"); if (option & TIME) printf(" %-8s %-8s %-8s", "STIME", "RTIME", "CTIME"); printf("\n"); } void print_kmsqptr(int i, int option, struct msqid_kernel *kmsqptr) { char stime_buf[100], rtime_buf[100], ctime_buf[100]; cvt_time(kmsqptr->u.msg_stime, stime_buf); cvt_time(kmsqptr->u.msg_rtime, rtime_buf); cvt_time(kmsqptr->u.msg_ctime, ctime_buf); printf("q %12d %12d %s %-8s %-8s", IXSEQ_TO_IPCID(i, kmsqptr->u.msg_perm), (int)kmsqptr->u.msg_perm.key, fmt_perm(kmsqptr->u.msg_perm.mode), user_from_uid(kmsqptr->u.msg_perm.uid, 0), group_from_gid(kmsqptr->u.msg_perm.gid, 0)); if (option & CREATOR) printf(" %-8s %-8s", user_from_uid(kmsqptr->u.msg_perm.cuid, 0), group_from_gid(kmsqptr->u.msg_perm.cgid, 0)); if (option & OUTSTANDING) printf(" %12lu %12lu", kmsqptr->u.msg_cbytes, kmsqptr->u.msg_qnum); if (option & BIGGEST) printf(" %20lu", kmsqptr->u.msg_qbytes); if (option & PID) printf(" %12d %12d", kmsqptr->u.msg_lspid, kmsqptr->u.msg_lrpid); if (option & TIME) printf(" %s %s %s", stime_buf, rtime_buf, ctime_buf); printf("\n"); } void print_kshmtotal(struct shminfo local_shminfo) { printf("shminfo:\n"); printf("\tshmmax: %12lu\t(max shared memory segment size)\n", local_shminfo.shmmax); printf("\tshmmin: %12lu\t(min shared memory segment size)\n", local_shminfo.shmmin); printf("\tshmmni: %12lu\t(max number of shared memory identifiers)\n", local_shminfo.shmmni); printf("\tshmseg: %12lu\t(max shared memory segments per process)\n", local_shminfo.shmseg); printf("\tshmall: %12lu\t(max amount of shared memory in pages)\n\n", local_shminfo.shmall); } void print_kshmheader(int option) { printf("Shared Memory:\n"); printf("T %12s %12s %-11s %-8s %-8s", "ID", "KEY", "MODE", "OWNER", "GROUP"); if (option & CREATOR) printf(" %-8s %-8s", "CREATOR", "CGROUP"); if (option & OUTSTANDING) printf(" %12s", "NATTCH"); if (option & BIGGEST) printf(" %12s", "SEGSZ"); if (option & PID) printf(" %12s %12s", "CPID", "LPID"); if (option & TIME) printf(" %-8s %-8s %-8s", "ATIME", "DTIME", "CTIME"); printf("\n"); } void print_kshmptr(int i, int option, struct shmid_kernel *kshmptr) { char atime_buf[100], dtime_buf[100], ctime_buf[100]; cvt_time(kshmptr->u.shm_atime, atime_buf); cvt_time(kshmptr->u.shm_dtime, dtime_buf); cvt_time(kshmptr->u.shm_ctime, ctime_buf); printf("m %12d %12d %s %-8s %-8s", IXSEQ_TO_IPCID(i, kshmptr->u.shm_perm), (int)kshmptr->u.shm_perm.key, fmt_perm(kshmptr->u.shm_perm.mode), user_from_uid(kshmptr->u.shm_perm.uid, 0), group_from_gid(kshmptr->u.shm_perm.gid, 0)); if (option & CREATOR) printf(" %-8s %-8s", user_from_uid(kshmptr->u.shm_perm.cuid, 0), group_from_gid(kshmptr->u.shm_perm.cgid, 0)); if (option & OUTSTANDING) printf(" %12d", kshmptr->u.shm_nattch); if (option & BIGGEST) printf(" %12zu", kshmptr->u.shm_segsz); if (option & PID) printf(" %12d %12d", kshmptr->u.shm_cpid, kshmptr->u.shm_lpid); if (option & TIME) printf(" %s %s %s", atime_buf, dtime_buf, ctime_buf); printf("\n"); } void print_ksemtotal(struct seminfo local_seminfo) { printf("seminfo:\n"); printf("\tsemmni: %12d\t(# of semaphore identifiers)\n", local_seminfo.semmni); printf("\tsemmns: %12d\t(# of semaphores in system)\n", local_seminfo.semmns); printf("\tsemmnu: %12d\t(# of undo structures in system)\n", local_seminfo.semmnu); printf("\tsemmsl: %12d\t(max # of semaphores per id)\n", local_seminfo.semmsl); printf("\tsemopm: %12d\t(max # of operations per semop call)\n", local_seminfo.semopm); printf("\tsemume: %12d\t(max # of undo entries per process)\n", local_seminfo.semume); printf("\tsemusz: %12d\t(size in bytes of undo structure)\n", local_seminfo.semusz); printf("\tsemvmx: %12d\t(semaphore maximum value)\n", local_seminfo.semvmx); printf("\tsemaem: %12d\t(adjust on exit max value)\n\n", local_seminfo.semaem); } void print_ksemheader(int option) { printf("Semaphores:\n"); printf("T %12s %12s %-11s %-8s %-8s", "ID", "KEY", "MODE", "OWNER", "GROUP"); if (option & CREATOR) printf(" %-8s %-8s", "CREATOR", "CGROUP"); if (option & BIGGEST) printf(" %12s", "NSEMS"); if (option & TIME) printf(" %-8s %-8s", "OTIME", "CTIME"); printf("\n"); } void print_ksemptr(int i, int option, struct semid_kernel *ksemaptr) { char ctime_buf[100], otime_buf[100]; cvt_time(ksemaptr->u.sem_otime, otime_buf); cvt_time(ksemaptr->u.sem_ctime, ctime_buf); printf("s %12d %12d %s %-8s %-8s", IXSEQ_TO_IPCID(i, ksemaptr->u.sem_perm), (int)ksemaptr->u.sem_perm.key, fmt_perm(ksemaptr->u.sem_perm.mode), user_from_uid(ksemaptr->u.sem_perm.uid, 0), group_from_gid(ksemaptr->u.sem_perm.gid, 0)); if (option & CREATOR) printf(" %-8s %-8s", user_from_uid(ksemaptr->u.sem_perm.cuid, 0), group_from_gid(ksemaptr->u.sem_perm.cgid, 0)); if (option & BIGGEST) printf(" %12d", ksemaptr->u.sem_nsems); if (option & TIME) printf(" %s %s", otime_buf, ctime_buf); printf("\n"); } uid_t user2uid(char *username) { struct passwd *pwd; uid_t uid; char *r; uid = strtoul(username, &r, 0); if (!*r && r != username) return (uid); if ((pwd = getpwnam(username)) == NULL) errx(1, "getpwnam failed: No such user"); endpwent(); return (pwd->pw_uid); } void usage(void) { fprintf(stderr, "usage: " "ipcs [-abcmopqstyMQST] [-C corefile] [-N namelist] [-u user]\n"); exit(1); } Index: stable/11 =================================================================== --- stable/11 (revision 347994) +++ stable/11 (revision 347995) Property changes on: stable/11 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r329348,329390