All of lore.kernel.org
 help / color / mirror / Atom feed
* SysV IPC: shmctl/msgctl/semctl returns EIDRM instead of EINVAL
@ 2007-08-03 17:59 Anton Arapov
  2007-08-05 21:37 ` Anton Arapov
  0 siblings, 1 reply; 2+ messages in thread
From: Anton Arapov @ 2007-08-03 17:59 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 912 bytes --]

Hi!

  SysV code returns EIDRM for collision of IDs. I sure it should return EINVAL.

  Steps to reproduce: (this for shared memory code, for msg/sem it is the same)
   1. Create then drop 2 shmem segments, then create a third.
   2. Try to shmctl(IPC_STAT) the two now-invalid shm IDs.
   3. Note error codes returned.

   One call gives EINVAL, one gives EIDRM due to collision with the third shmem segment.
   Should both give EINVAL, this is what I've got on every other Unix I've tried it on. 

  IPC code is good, EIDRM is justification of EINVAL. But neither SVr4 nor SVID documents EIDRM. 
  Single Unix Specification mentions EINVAL but not EIDRM as a possible failure for shmctl(), so the current kernel behavior is not merely self-inconsistent but a flat violation of the spec. 

  Can somebody explain why do we have EIDRM?

Anton.
SUS: http://www.opengroup.org/onlinepubs/007908799/xsh/shmctl.html


[-- Attachment #2: shmctl-bug.c --]
[-- Type: bug_reproducer, Size: 2110 bytes --]

#include <sys/ipc.h>
#include <sys/shm.h>

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main(int argc, char *argv[])
{
    int              shmid1;
    int              shmid2;
    int              shmid3;
    struct shmid_ds  buf;

    /* make and stat 2 shmem segments */
    shmid1 = shmget(0x12345678, 1024 * 1024, IPC_CREAT | IPC_EXCL | 0600);
    if (shmid1 < 0)
    {
	perror("shmget 1 failed");
	exit(1);
    }
    printf("id1 = %d / %#x\n", shmid1, shmid1);

    shmid2 = shmget(0x12345679, 1024 * 1024, IPC_CREAT | IPC_EXCL | 0600);
    if (shmid2 < 0)
    {
	perror("shmget 2 failed");
	exit(1);
    }
    printf("id2 = %d / %#x\n", shmid2, shmid2);

    if (shmctl(shmid1, IPC_STAT, &buf) < 0)
    {
	printf("shmctl(%d / %#x, IPC_STAT): ERROR: %s\n", shmid1, shmid1,
	       strerror(errno));
    }

    if (shmctl(shmid2, IPC_STAT, &buf) < 0)
    {
	printf("shmctl(%d / %#x, IPC_STAT): ERROR: %s\n", shmid2, shmid2,
	       strerror(errno));
    }

    /* remove both */
    if (shmctl(shmid1, IPC_RMID, NULL) < 0)
    {
	printf("shmctl(%d / %#x, IPC_RMID): ERROR: %s\n", shmid1, shmid1,
	       strerror(errno));
    }
    if (shmctl(shmid2, IPC_RMID, NULL) < 0)
    {
	printf("shmctl(%d / %#x, IPC_RMID): ERROR: %s\n", shmid2, shmid2,
	       strerror(errno));
    }

    /* make a third one */
    shmid3 = shmget(0x1234567A, 1024 * 1024, IPC_CREAT | IPC_EXCL | 0600);
    if (shmid3 < 0)
    {
	perror("shmget 3 failed");
	exit(1);
    }
    printf("id3 = %d / %#x\n", shmid3, shmid3);

    /* now observe stat behavior for the two old IDs */

    if (shmctl(shmid1, IPC_STAT, &buf) < 0)
    {
	printf("shmctl(%d / %#x, IPC_STAT): ERROR: %s\n", shmid1, shmid1,
	       strerror(errno));
    }

    if (shmctl(shmid2, IPC_STAT, &buf) < 0)
    {
	printf("shmctl(%d / %#x, IPC_STAT): ERROR: %s\n", shmid2, shmid2,
	       strerror(errno));
    }

    /* clean up by removing third segment */
    if (shmctl(shmid3, IPC_RMID, NULL) < 0)
    {
	printf("shmctl(%d / %#x, IPC_RMID): ERROR: %s\n", shmid3, shmid3,
	       strerror(errno));
    }

    return 0;
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: SysV IPC: shmctl/msgctl/semctl returns EIDRM instead of EINVAL
  2007-08-03 17:59 SysV IPC: shmctl/msgctl/semctl returns EIDRM instead of EINVAL Anton Arapov
@ 2007-08-05 21:37 ` Anton Arapov
  0 siblings, 0 replies; 2+ messages in thread
From: Anton Arapov @ 2007-08-05 21:37 UTC (permalink / raw)
  To: linux-kernel


  Please, fellas, take a look on my post!

Thanks in advance.

Anton Arapov <aarapov@redhat.com> writes:
> Hi!
>
>   SysV code returns EIDRM for collision of IDs. I sure it should return EINVAL.
>
>   Steps to reproduce: (this for shared memory code, for msg/sem it is the same)
>    1. Create then drop 2 shmem segments, then create a third.
>    2. Try to shmctl(IPC_STAT) the two now-invalid shm IDs.
>    3. Note error codes returned.
>
>    One call gives EINVAL, one gives EIDRM due to collision with the third shmem segment.
>    Should both give EINVAL, this is what I've got on every other Unix I've tried it on. 
>
>   IPC code is good, EIDRM is justification of EINVAL. But neither SVr4 nor SVID documents EIDRM. 
>   Single Unix Specification mentions EINVAL but not EIDRM as a possible failure for shmctl(), so the current kernel behavior is not merely self-inconsistent but a flat violation of the spec. 
>
>   Can somebody explain why do we have EIDRM?
>
> Anton.
> SUS: http://www.opengroup.org/onlinepubs/007908799/xsh/shmctl.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-08-05 21:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-03 17:59 SysV IPC: shmctl/msgctl/semctl returns EIDRM instead of EINVAL Anton Arapov
2007-08-05 21:37 ` Anton Arapov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.