[uClibc] Re: shm funkiness

David Wuertele dave-gnus at bfnet.com
Fri Aug 1 01:22:25 UTC 2003


To test why my shm apps are funky, I wrote the following test program:

  #include <stdio.h>
  #include <sys/types.h>
  #include <sys/ipc.h>
  #include <sys/shm.h>
  #include <stdlib.h>
  #include <time.h>

  int
  main(int ac, char **av)
  {
    key_t key = atoi(av[1]);
    int id = shmget (key, 0x1000, IPC_CREAT);
    fprintf (stderr, "id = %d\n", id);
    getc(stdin);

    struct shmid_ds shmid_ds;
    register int retval = shmctl(id, IPC_STAT, &shmid_ds);
    if (retval == -1) {
      perror ("shmctl: shmctl failed");
      return 1;
    } else {
      fprintf (stderr, "\tshm_perm.uid = %d\n", shmid_ds.shm_perm.uid);
      fprintf (stderr, "\tshm_perm.gid = %d\n", shmid_ds.shm_perm.gid);
      fprintf (stderr, "\tshm_perm.cuid = %d\n", shmid_ds.shm_perm.cuid);
      fprintf (stderr, "\tshm_perm.cgid = %d\n", shmid_ds.shm_perm.cgid);
      fprintf (stderr, "\tshm_perm.mode = %#o\n", shmid_ds.shm_perm.mode);
      fprintf (stderr, "\tshm_segsz = %d\n", shmid_ds.shm_segsz);
      fprintf (stderr, "\tshm_lpid = %d\n", shmid_ds.shm_lpid);
      fprintf (stderr, "\tshm_cpid = %d\n", shmid_ds.shm_cpid);
      fprintf (stderr, "\tshm_nattch = %d\n", shmid_ds.shm_nattch);
      fprintf (stderr, "\tshm_atime = %s", shmid_ds.shm_atime ? ctime(&shmid_ds.shm_atime) : "Not Set\n");
      fprintf (stderr, "\tshm_dtime = %s", shmid_ds.shm_dtime ? ctime(&shmid_ds.shm_dtime) : "Not Set\n");
      fprintf (stderr, "\tshm_ctime = %s", ctime(&shmid_ds.shm_ctime)); 
    }

    return 0;
  }

I then logged into my embedded uClibc system using two different
telnet sessions so that I could run the program (called "dave") and
then run ipcs simultaneously:

  (telnet session 1)
  sh-2.05b# dave 1234
  id = 131072

---

  (telnet session 2)
  sh-2.05b# ipcs

  ------ Shared Memory Segments --------
  key        shmid      owner      perms      bytes      nattch     status
  0x000004d2 131072     root      0          0          0

  ------ Semaphore Arrays --------
  key        semid      owner      perms      nsems

  ------ Message Queues --------
  key        msqid      owner      perms      used-bytes   messages

  sh-2.05b#

Strange... Why is the bytes field zero?  It should read 4096.  Next I
try running the same program in a third session in an attempt to
increase the nattch value, then run ipcs again:

  (telnet session 3)
  sh-2.05b# dave 1234
  id = 131072

---

  (back to telnet session 2)
  sh-2.05b# ipcs

  ------ Shared Memory Segments --------
  key        shmid      owner      perms      bytes      nattch     status
  0x000004d2 131072     root      0          0          1702132066

  ------ Semaphore Arrays --------
  key        semid      owner      perms      nsems

  ------ Message Queues --------
  key        msqid      owner      perms      used-bytes   messages

  sh-2.05b#

Hmm... Now not only is the bytes field wrong, but the nattch field is
WAY wrong!  What is going on here?

Relevant info:
Arch:       mipsel
Linux:      linux-2.4.18+many patches
uClibc:     0.9.20
buildroot:  CVS snapshot from July 1
util-linux: 2.11z

Thanks,
Dave




More information about the uClibc mailing list