From nobody  Sat Jan 11 06:43:44 1997
Received: (from nobody@localhost)
          by freefall.freebsd.org (8.8.4/8.8.4) id GAA19356;
          Sat, 11 Jan 1997 06:43:44 -0800 (PST)
Message-Id: <199701111443.GAA19356@freefall.freebsd.org>
Date: Sat, 11 Jan 1997 06:43:44 -0800 (PST)
From: tsingle@sunland.gsfc.nasa.gov
To: freebsd-gnats-submit@freebsd.org
Subject: semctl() not portable -- freebsd requires 4th arg; Solaris, HPUX, etc. don't.
X-Send-Pr-Version: www-1.0

>Number:         2448
>Category:       bin
>Synopsis:       [MFC] semctl() not portable -- freebsd requires 4th arg; Solaris, HPUX, etc. don't.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    steve
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jan 11 06:50:01 PST 1997
>Closed-Date:    Mon Sep 7 14:17:45 PDT 1998
>Last-Modified:  Mon Sep  7 14:18:16 PDT 1998
>Originator:     Tim Singletary
>Release:        2.2-961014-SNAP
>Organization:
August Automation, Inc.
>Environment:
>Description:
FreeBSD's semctl() requires four arguments; in Solaris, HP-UX, etc.
the fourth argument isn't needed unless the third argument is SETVAL,
GETALL, SETALL, IPC_STAT, or IPC_SET.  The SunOS manual 
_Porting_Software_to_SPARC_ states:

   Programs that call semctl() with these subcommands [those
   requiring a fourth argument] must pass the union itself, rather
   than an element of the union, or a constant such as 0 (zero).
   Programs that call semctl() with other subcommands should omit the
   fourth argument, rather than pass a constant such as 0 (zero).

In other words, there's a portability issue:  FreeBSD is not compatible
with other unixes.


>How-To-Repeat:
(not applicable)
>Fix:
Here's my suggestion for code patches; I don't have any suggestions on
how to fix the man page.

1) Change line 175(?) of /usr/include/sys/sem.h from
     int semctl __P((int, int, int, union semun));
   to
     int semctl __P((int, int, int, ...));

2) Replace /usr/src/lib/libc/gen/semctl.c with

#include <stdarg.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>

int semctl(int semid, int semnum, int cmd, ...)
{
    va_list ap;
    union semun fourth_arg;
    union semun *fourth_arg_ptr;

    va_start(ap,cmd);
    if (cmd == IPC_SET || cmd == IPC_STAT || cmd == GETALL
                                    || cmd == SETVAL || cmd == SETALL) {
        fourth_arg = va_arg(ap, union semun);
        fourth_arg_ptr = &fourth_arg;
    } else {
        fourth_arg_ptr = NULL;
    }
    va_end(ap);

    return(semsys(0, semid, semnum, cmd, fourth_arg_ptr));
}

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->steve 
Responsible-Changed-By: steve 
Responsible-Changed-When: Sat May 30 21:05:49 PDT 1998 
Responsible-Changed-Why:  
I've put this into -current and will merge to -stable in 
a week or two after the dust settles. 
State-Changed-From-To: open->closed 
State-Changed-By: steve 
State-Changed-When: Mon Sep 7 14:17:45 PDT 1998 
State-Changed-Why:  
Just merged back into stable. 
>Unformatted:
