Add -u option to ipcs(1) and document it in ipcs.1
It allows you to list IPC facilities owned by username/uid. Submitted by: Christian S.J. Peron <maneo@bsdpro.com> PR: bin/63463
This commit is contained in:
parent
a832f947f3
commit
4d2e8e5fb8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=127348
@ -131,6 +131,11 @@ using
|
|||||||
.Xr kvm 3
|
.Xr kvm 3
|
||||||
will require read privileges to
|
will require read privileges to
|
||||||
.Pa /dev/kmem .
|
.Pa /dev/kmem .
|
||||||
|
.It Fl u Ar user
|
||||||
|
Display information about IPC mechanisms owned by
|
||||||
|
.Pa user .
|
||||||
|
User specification can be in the form of a numeric UID or
|
||||||
|
a login name.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
If none of the
|
If none of the
|
||||||
|
@ -74,6 +74,7 @@ void cvt_time(time_t, char *);
|
|||||||
void sysctlgatherstruct(void *addr, size_t size, struct scgs_vector *vec);
|
void sysctlgatherstruct(void *addr, size_t size, struct scgs_vector *vec);
|
||||||
void kget(int idx, void *addr, size_t size);
|
void kget(int idx, void *addr, size_t size);
|
||||||
void usage(void);
|
void usage(void);
|
||||||
|
uid_t user2uid(char *username);
|
||||||
|
|
||||||
static struct nlist symbols[] = {
|
static struct nlist symbols[] = {
|
||||||
{"sema"},
|
{"sema"},
|
||||||
@ -188,11 +189,12 @@ main(argc, argv)
|
|||||||
{
|
{
|
||||||
int display = SHMINFO | MSGINFO | SEMINFO;
|
int display = SHMINFO | MSGINFO | SEMINFO;
|
||||||
int option = 0;
|
int option = 0;
|
||||||
char *core = NULL, *namelist = NULL;
|
char *core = NULL, *user = NULL, *namelist = NULL;
|
||||||
char kvmoferr[_POSIX2_LINE_MAX]; /* Error buf for kvm_openfiles. */
|
char kvmoferr[_POSIX2_LINE_MAX]; /* Error buf for kvm_openfiles. */
|
||||||
int i;
|
int i;
|
||||||
|
uid_t uid;
|
||||||
|
|
||||||
while ((i = getopt(argc, argv, "MmQqSsabC:cN:optTy")) != -1)
|
while ((i = getopt(argc, argv, "MmQqSsabC:cN:optTu:y")) != -1)
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 'M':
|
case 'M':
|
||||||
display = SHMTOTAL;
|
display = SHMTOTAL;
|
||||||
@ -242,6 +244,10 @@ main(argc, argv)
|
|||||||
case 'y':
|
case 'y':
|
||||||
use_sysctl = 0;
|
use_sysctl = 0;
|
||||||
break;
|
break;
|
||||||
|
case 'u':
|
||||||
|
user = optarg;
|
||||||
|
uid = user2uid(user);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
@ -320,6 +326,9 @@ main(argc, argv)
|
|||||||
ctime_buf[100];
|
ctime_buf[100];
|
||||||
struct msqid_ds *msqptr = &xmsqids[i];
|
struct msqid_ds *msqptr = &xmsqids[i];
|
||||||
|
|
||||||
|
if (user)
|
||||||
|
if (uid != msqptr->msg_perm.uid)
|
||||||
|
continue;
|
||||||
cvt_time(msqptr->msg_stime, stime_buf);
|
cvt_time(msqptr->msg_stime, stime_buf);
|
||||||
cvt_time(msqptr->msg_rtime, rtime_buf);
|
cvt_time(msqptr->msg_rtime, rtime_buf);
|
||||||
cvt_time(msqptr->msg_ctime, ctime_buf);
|
cvt_time(msqptr->msg_ctime, ctime_buf);
|
||||||
@ -409,6 +418,9 @@ main(argc, argv)
|
|||||||
ctime_buf[100];
|
ctime_buf[100];
|
||||||
struct shmid_ds *shmptr = &xshmids[i];
|
struct shmid_ds *shmptr = &xshmids[i];
|
||||||
|
|
||||||
|
if (user)
|
||||||
|
if (uid != shmptr->shm_perm.uid)
|
||||||
|
continue;
|
||||||
cvt_time(shmptr->shm_atime, atime_buf);
|
cvt_time(shmptr->shm_atime, atime_buf);
|
||||||
cvt_time(shmptr->shm_dtime, dtime_buf);
|
cvt_time(shmptr->shm_dtime, dtime_buf);
|
||||||
cvt_time(shmptr->shm_ctime, ctime_buf);
|
cvt_time(shmptr->shm_ctime, ctime_buf);
|
||||||
@ -502,6 +514,9 @@ main(argc, argv)
|
|||||||
char ctime_buf[100], otime_buf[100];
|
char ctime_buf[100], otime_buf[100];
|
||||||
struct semid_ds *semaptr = &xsema[i];
|
struct semid_ds *semaptr = &xsema[i];
|
||||||
|
|
||||||
|
if (user)
|
||||||
|
if (uid != semaptr->sem_perm.uid)
|
||||||
|
continue;
|
||||||
cvt_time(semaptr->sem_otime, otime_buf);
|
cvt_time(semaptr->sem_otime, otime_buf);
|
||||||
cvt_time(semaptr->sem_ctime, ctime_buf);
|
cvt_time(semaptr->sem_ctime, ctime_buf);
|
||||||
|
|
||||||
@ -649,11 +664,27 @@ kget(idx, addr, size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"usage: ipcs [-abcmopqstyMQST] [-C corefile] [-N namelist]\n");
|
"usage: ipcs [-abcmopqstyMQST] [-C corefile] [-N namelist] [-u user]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user