ppc32: semctl fails

Joakim Tjernlund Joakim.Tjernlund at infinera.com
Thu Dec 7 10:53:33 AEDT 2017


On Wed, 2017-12-06 at 23:56 +0100, Andreas Schwab wrote:
> 
> On Dez 06 2017, Joakim Tjernlund <Joakim.Tjernlund at infinera.com> wrote:
> 
> >     st = semctl(sem, 0, IPC_STAT, &arg);
> 
> This is not a valid use of IPC_STAT.  The fourth argument must be a
> object of type union semun (not a pointer), with the .buf member
> pointing to the struct semid_ds object.

Ahh, so perl had it wrong (Any perl guys here?). This is what I came up with and it works:

struct semid_ds arg;
  union semun {
    int              val;    /* Value for SETVAL */
    struct semid_ds *buf;    /* Buffer for IPC_STAT, IPC_SET */
    unsigned short  *array;  /* Array for GETALL, SETALL */
    struct seminfo  *__buf;  /* Buffer for IPC_INFO                                                                                        
                                (Linux-specific) */
  } semopts = {0};
  semopts.buf = &arg;

#if defined(IPC_PRIVATE) && defined(S_IRWXU) && defined(S_IRWXG) &&  defined(S_IRWXO) && defined(IPC_CREAT)
  sem = semget(IPC_PRIVATE, 1, S_IRWXU|S_IRWXG|S_IRWXO|IPC_CREAT);
  if (sem > -1) {
    #ifdef IPC_STAT
    st = semctl(sem, 0, IPC_STAT, semopts);
    if (st == 0)
      printf("semid_ds\n");
    else
#endif /* IPC_STAT */
      printf("semctl IPC_STAT failed: errno = %s\n", strerror(errno));
    #ifdef IPC_RMID
    if (semctl(sem, 0, IPC_RMID, semopts) != 0)
#endif /* IPC_RMID */
      printf("semctl IPC_RMID failed: errno = %d\n", errno);
  } else
#endif /* IPC_PRIVATE && ... */
    printf("semget failed: errno = %d\n", errno);
  return 0;

 Jocke


More information about the Linuxppc-dev mailing list