From root@nihil.plaut.de  Tue Aug 14 02:19:28 2001
Return-Path: <root@nihil.plaut.de>
Received: from ns.plaut.de (ns.plaut.de [194.99.75.166])
	by hub.freebsd.org (Postfix) with ESMTP id 466A737B407
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 14 Aug 2001 02:19:27 -0700 (PDT)
	(envelope-from root@nihil.plaut.de)
Received: (from uucp@localhost)
	by ns.plaut.de (8.9.3/8.9.3) with UUCP id LAA08501
	for FreeBSD-gnats-submit@freebsd.org; Tue, 14 Aug 2001 11:19:26 +0200 (CEST)
	(envelope-from root@nihil.plaut.de)
Received: (from root@localhost)
	by nihil.plaut.de (8.11.3/8.8.8) id f7EBIxV07015;
	Tue, 14 Aug 2001 13:18:59 +0200 (CEST)
	(envelope-from root)
Message-Id: <200108141118.f7EBIxV07015@nihil.plaut.de>
Date: Tue, 14 Aug 2001 13:18:59 +0200 (CEST)
From: Michael Reifenberger <root@nihil.plaut.de>
Reply-To: root@nihil.plaut.de
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: linux ipcs doesn'work <synopsis of the problem (one line)>
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         29698
>Category:       kern
>Synopsis:       [linux] [patch] linux ipcs doesn'work
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    linimon
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 14 02:20:01 PDT 2001
>Closed-Date:    Sat Aug 07 06:47:22 UTC 2010
>Last-Modified:  Sat Aug 07 06:47:22 UTC 2010
>Originator:     Michael Reifenberger
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD nihil 5.0-CURRENT FreeBSD 5.0-CURRENT #1: Sun Aug 12 15:01:29 CEST 2001 root@nihil:/usr/src/sys/i386/compile/nihil i386


	
>Description:
/compat/linux/usr/bin/ipcs [-s|-a] doesn't work
	
>How-To-Repeat:
/compat/linux/usr/bin/ipcs [-s|-a] 
	
>Fix:

	
It is the needed step in getting "/compat/linux/usr/bin/ipcs -s" working.
Furthermore it enhances the sysv[sem|shm] sysctl's into tunables so they
can preset to usable values on modload.

--- ./i386/linux/linux.h.orig	Wed Aug  8 00:09:28 2001
+++ ./i386/linux/linux.h	Mon Aug 13 00:41:50 2001
@@ -457,4 +457,6 @@
 #define	LINUX_SETVAL		16
 #define	LINUX_SETALL		17
+#define	LINUX_SEM_STAT		18
+#define	LINUX_SEM_INFO		19
 
 /*
--- ./kern/sysv_sem.c.orig	Sun Aug 12 13:18:34 2001
+++ ./kern/sysv_sem.c	Sun Aug 12 23:31:10 2001
@@ -171,4 +171,14 @@
 	register int i;
 
+	TUNABLE_INT_FETCH("kern.ipc.semmap", &seminfo.semmap);
+	TUNABLE_INT_FETCH("kern.ipc.semmni", &seminfo.semmni);
+	TUNABLE_INT_FETCH("kern.ipc.semmns", &seminfo.semmns);
+	TUNABLE_INT_FETCH("kern.ipc.semmnu", &seminfo.semmnu);
+	TUNABLE_INT_FETCH("kern.ipc.semmsl", &seminfo.semmsl);
+	TUNABLE_INT_FETCH("kern.ipc.semopm", &seminfo.semopm);
+	TUNABLE_INT_FETCH("kern.ipc.semume", &seminfo.semume);
+	TUNABLE_INT_FETCH("kern.ipc.semusz", &seminfo.semusz);
+	TUNABLE_INT_FETCH("kern.ipc.semvmx", &seminfo.semvmx);
+	TUNABLE_INT_FETCH("kern.ipc.semaem", &seminfo.semaem);
 	sem = malloc(sizeof(struct sem) * seminfo.semmns, M_SEM, M_WAITOK);
 	if (sem == NULL)
@@ -471,4 +481,21 @@
 		return (ENOSYS);
 
+	switch(cmd) {
+	case SEM_STAT:
+		if (semid < 0 || semid >= seminfo.semmsl)
+	 		return(EINVAL);
+		semaptr = &sema[semid];
+		if ((semaptr->sem_perm.mode & SEM_ALLOC) == 0 )
+			return(EINVAL);
+		if ((eval = ipcperm(p, &semaptr->sem_perm, IPC_R)))
+			return(eval);
+		if ((eval = copyin(arg, &real_arg, sizeof(real_arg))) != 0)
+			return(eval);
+		eval = copyout((caddr_t)semaptr, real_arg.buf,
+		    sizeof(struct semid_ds));
+		rval = IXSEQ_TO_IPCID(semid,semaptr->sem_perm);
+		goto out;
+	}
+
 	semid = IPCID_TO_IX(semid);
 	if (semid < 0 || semid >= seminfo.semmsl)
@@ -602,4 +629,6 @@
 		return(EINVAL);
 	}
+	
+out:
 
 	if (eval == 0)
--- ./kern/sysv_shm.c.orig	Sun Aug 12 13:18:43 2001
+++ ./kern/sysv_shm.c	Sun Aug 12 21:11:36 2001
@@ -716,4 +716,10 @@
 	int i;
 
+TUNABLE_INT_FETCH("kern.ipc.shmmaxpgs", &shminfo.shmall);
+shminfo.shmmax = shminfo.shmall * PAGE_SIZE;
+TUNABLE_INT_FETCH("kern.ipc.shmmin", &shminfo.shmmin);
+TUNABLE_INT_FETCH("kern.ipc.shmmni", &shminfo.shmmni);
+TUNABLE_INT_FETCH("kern.ipc.shmseg", &shminfo.shmseg);
+TUNABLE_INT_FETCH("kern.ipc.shm_use_phys", &shm_use_phys);
 	shmalloced = shminfo.shmmni;
 	shmsegs = malloc(shmalloced * sizeof(shmsegs[0]), M_SHM, M_WAITOK);
--- ./sys/sem.h.orig	Sun Aug 12 23:17:32 2001
+++ ./sys/sem.h	Mon Aug 13 00:40:50 2001
@@ -59,4 +59,6 @@
 #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 /* for future use */
 
 /*
--- ./compat/linux/linux_ipc.c.orig	Sat Aug  4 17:49:33 2001
+++ ./compat/linux/linux_ipc.c	Mon Aug 13 00:45:27 2001
@@ -41,4 +41,34 @@
 #include <compat/linux/linux_util.h>
 
+struct linux_seminfo {
+        int semmap;
+        int semmni;
+        int semmns;
+        int semmnu;
+        int semmsl;
+        int semopm;
+        int semume;
+        int semusz;
+        int semvmx;
+        int semaem;
+};
+
+struct linux_shminfo {
+        int shmmax;
+        int shmmin;
+        int shmmni;
+        int shmseg;
+        int shmall;
+};
+
+struct linux_shm_info {
+        int used_ids;
+        unsigned long shm_tot;  /* total allocated shm */
+        unsigned long shm_rss;  /* total resident shm */
+        unsigned long shm_swp;  /* total swapped shm */
+        unsigned long swap_attempts;
+        unsigned long swap_successes;
+};
+
 struct linux_ipc_perm {
     linux_key_t key;
@@ -183,4 +213,5 @@
 {
 	struct linux_semid_ds	linux_semid;
+	struct linux_seminfo linux_seminfo;
 	struct semid_ds	bsd_semid;
 	struct __semctl_args /* {
@@ -238,5 +269,9 @@
 		return __semctl(p, &bsd_args);
 	case LINUX_IPC_STAT:
-		bsd_args.cmd = IPC_STAT;
+	case LINUX_SEM_STAT:
+		if( args->arg3 == IPC_STAT )
+			bsd_args.cmd = IPC_STAT;
+		else
+			bsd_args.cmd = SEM_STAT;
 		unptr = stackgap_alloc(&sg, sizeof(union semun *));
 		dsp = stackgap_alloc(&sg, sizeof(struct semid_ds));
@@ -255,5 +290,24 @@
 		if (error)
 			return error;
+		p->p_retval[0] = IXSEQ_TO_IPCID(bsd_args.semid, bsd_semid.sem_perm);
 		return copyout((caddr_t)&linux_semid, ldsp, sizeof(linux_semid));
+	case LINUX_IPC_INFO:
+	case LINUX_SEM_INFO:
+		error = copyin(args->ptr, &ldsp, sizeof(ldsp));
+		if (error)
+			return error;
+		bcopy(&seminfo, &linux_seminfo, sizeof(linux_seminfo) );
+/* XXX 
+#define used_semids 10
+#define used_sems 10
+	        linux_seminfo.semusz = used_semids;
+   		    linux_seminfo.semaem = used_sems;
+		} */
+		error = copyout((caddr_t)&linux_seminfo, ldsp, 
+				sizeof(linux_seminfo) );
+		if (error)
+			return error;
+		p->p_retval[0] = seminfo.semmni;
+		return(0);
 	case LINUX_GETALL:
 		/* FALLTHROUGH */
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->emulation 
Responsible-Changed-By: bms 
Responsible-Changed-When: Fri Jun 18 12:09:56 GMT 2004 
Responsible-Changed-Why:  
One for the emulation team 

http://www.freebsd.org/cgi/query-pr.cgi?pr=29698 
State-Changed-From-To: open->feedback 
State-Changed-By: netchild 
State-Changed-When: Thu Dec 29 16:00:42 UTC 2005 
State-Changed-Why:  
There's no ipcs in the current default linux base... 

Is this still a problem on a recent FreeBSD? If yes, do you have 
updated patches? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=29698 
State-Changed-From-To: feedback->open 
State-Changed-By: netchild 
State-Changed-When: Mon May 1 11:52:45 UTC 2006 
State-Changed-Why:  
Back to "open", maybe an upcomming SoC student is willing to have a look 
at this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=29698 

From: Alexander Best <alexbestms@math.uni-muenster.de>
To: <bug-followup@FreeBSD.org>
Cc:  
Subject: Re: kern/29698: [linux] [patch] linux ipcs doesn'work
Date: Wed, 16 Sep 2009 03:02:25 +0200 (CEST)

 emulators/linux_dist-gentoo-stage3 comes with `ipcs` and `ipcrm`. running ipcs
 [-s|-a] works without any problems.
 
 `/usr/local/gentoo-stage3/usr/bin/ipcs -a`:
 
 ------ Shared Memory Segments --------
 key        shmid      owner      perms      bytes      nattch     status
 
 ------ Semaphore Arrays --------
 key        semid      owner      perms      nsems
 0x74738b52 65536      arundel   600        1
 
 ------ Message Queues --------
 key        msqid      owner      perms      used-bytes   messages
 
 `/usr/local/gentoo-stage3/usr/bin/ipcs -s`:
 
 ------ Semaphore Arrays --------
 key        semid      owner      perms      nsems
 0x74738b52 65536      arundel   600        1
 
 ` /usr/local/gentoo-stage3/usr/bin/ipcrm -s 65536`
 
 `/usr/local/gentoo-stage3/usr/bin/ipcs -s`:
 
 ------ Semaphore Arrays --------
 key        semid      owner      perms      nsems
 
 question is if `ipcs`/`ipcrm` is needed in emulators/linux_base-f*.
 
 cheers.
 alex
 
 p.s.: i'm running - FreeBSD otaku 9.0-CURRENT FreeBSD 9.0-CURRENT #0 r197234:
 Wed Sep 16 01:10:00 CEST 2009     root@otaku:/usr/obj/usr/src/sys/ARUNDEL
 i386
State-Changed-From-To: open->patched 
State-Changed-By: arundel 
State-Changed-When: Sun Aug 1 22:11:07 UTC 2010 
State-Changed-Why:  


http://www.freebsd.org/cgi/query-pr.cgi?pr=29698 
State-Changed-From-To: patched->open 
State-Changed-By: arundel 
State-Changed-When: Sun Aug 1 22:22:39 UTC 2010 
State-Changed-Why:  


http://www.freebsd.org/cgi/query-pr.cgi?pr=29698 

From: Alexander Best <arundel@freebsd.org>
To: bug-followup@freebsd.org
Cc: Michael Reifenberger <root@nihil.plaut.de>,
	Alexander Leidinger <netchild@freebsd.org>
Subject: Re: kern/29698: [linux] [patch] linux ipcs doesn'work
Date: Sun, 1 Aug 2010 23:29:19 +0000

 the linux related changes in this PR have been committed in r83366.
 
 the freebsd patches have also been committed. however it is unknown if this means linux ipc is fully functional now.
 
 cheers.
 alex
 
 -- 
 a13x
State-Changed-From-To: open->feedback 
State-Changed-By: linimon 
State-Changed-When: Mon Aug 2 02:31:49 UTC 2010 
State-Changed-Why:  
To submitter (if this email address is still valid): have the recent 
changes fixed the problem? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=29698 
State-Changed-From-To: feedback->closed 
State-Changed-By: linimon 
State-Changed-When: Sat Aug 7 06:46:52 UTC 2010 
State-Changed-Why:  
Submitter's email address bounces. 


Responsible-Changed-From-To: freebsd-emulation->linimon 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Aug 7 06:46:52 UTC 2010 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=29698 
>Unformatted:
