<?xml version="1.0" encoding="UTF-8" ?>

<bugzilla version="5.2"
          urlbase="https://bugzilla.altlinux.org/"
          
          maintainer="jenya@basealt.ru"
>

    <bug>
          <bug_id>6053</bug_id>
          
          <creation_ts>2005-02-07 13:55:46 +0300</creation_ts>
          <short_desc>A simple program that uses shared memory doesn&apos;t work</short_desc>
          <delta_ts>2005-09-04 23:37:16 +0400</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>5</classification_id>
          <classification>Archive</classification>
          <product>ALT Linux 2.4</product>
          <component>glibc</component>
          <version>2.4</version>
          <rep_platform>all</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>NOTABUG</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Andrey Fomichev">fomichev</reporter>
          <assigned_to name="Dmitry V. Levin">ldv</assigned_to>
          <cc>fomichev</cc>
          
          <qa_contact name="Andrey Cherepanov">cas</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>21714</commentid>
    <comment_count>0</comment_count>
    <who name="Andrey Fomichev">fomichev</who>
    <bug_when>2005-02-07 13:55:47 +0300</bug_when>
    <thetext>The simple C/C++ program doesn&apos;t work. But it must. I have no problem running 
this program on Red Hat 9.0. 
The program just calls 4 system calls sequentially: shmget, shmat, shmdt and 
shmctl. Another words, I create shared memory, attach to it, detach from it 
and, finally, destroy it. The text of the program is below

//================================================================
#include &lt;stdio.h&gt;
#include &lt;sys/shm.h&gt;

typedef int UShMem;

#define RIGHTS		0666

int main()
{
	UShMem id;

	id = shmget(1590, 8, IPC_CREAT | IPC_EXCL | RIGHTS);

	if(id == -1)
	{
		perror(&quot;shmget&quot;);
		return 1;
	}

	void *res = NULL;
	if ((int)(res = shmat(id, NULL, 0)) == -1)
	{
            perror(&quot;shmat&quot;);
    	    return 1;
	}

	if(shmdt(res) &lt; 0)
	{
		perror(&quot;shmdt&quot;);
		return 1;
	}

	if(shmctl(id, IPC_RMID, NULL) &lt; 0)
	{
		perror(&quot;shmctl&quot;);
		return 1;
	}

	printf(&quot;All done\n&quot;);

	return 0;
}
//================================================================

The call to shmctl produces error. If you comment call to shmdt, then shmctl 
works fine. The program works fine on Red Hat 9.0 and it _must_ work on any 
POSIX platform as far as I understand...

Best regards,
Andrey Fomichev

Steps to Reproduce:
1. Cut out the program code from the message and place it to main.cpp
2. Type &quot;g++ main.cpp&quot;
3. Run &quot;./a.out&quot;. See the result.
Actual Results:  
shmctl: Invalid argument

Expected Results:  
All done</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>21716</commentid>
    <comment_count>1</comment_count>
    <who name="Dmitry V. Levin">ldv</who>
    <bug_when>2005-02-07 14:49:30 +0300</bug_when>
    <thetext>This happens due to kernel configuration parameter, CONFIG_HARDEN_SHM=y
You can control it (systemwide) via /proc/sys/kernel/shm_destroy_unused.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>