Possible error in Beejs guide to IPC document



Hi,

My query is for Unix IPC. In the document "Beej's guide to Unix Inter
Process Communication",
( http://beej.us/guide/bgipc/output/html/singlepage/bgipc.html#flockset
) , section 6.1 - "Setting a lock", 4th paragraph, Beej says:

" The next step is to open() the file, since flock() needs a file
descriptor of the file that's being locked. Note that when you open
the file, you need to open it in the same mode as you have specified
in the lock, as shown in the table, below. If you open the file in the
wrong mode for a given lock type, open() will return EBADF."

I think he meant to say fcntl() will return EBADF. Because open()
accept the path and returns a file descriptor which we input to fcntl
(), and if the mode of opening down's match, fcntl() should return
error EBADF. How can open() return EBADF.

Also open is a call which returns file descriptor and fcntl() is a
call which accept a file descriptor. There is no error called EBADF in
open() man page,, but it is in fcntl().

I tried mailing Beej about this error, but didn't get any reply, nor
the error was corrected

Please comment on it or let me know if I'm wrong.

Cheers,
Guru
.



Relevant Pages

  • Re: Possible error in Beejs guide to IPC document
    ... Guru wrote: ... accept the path and returns a file descriptor which we input to fcntl ... How can openreturn EBADF. ...
    (comp.unix.programmer)
  • Re: Solaris 10 - catman weird error
    ... DTrace can absolutely help in this situation. ... returns EIO or EBADF: ... probably want to know _how_ exactly the file descriptor was closed. ... that you know the process ID of the problematic process, here is a D script ...
    (comp.unix.solaris)
  • Re: close() on a closed file descriptor in Visual Studio 8
    ... returns EBADF and everybody goes on with their lives. ... In Visual Studio ... just goes through the file descriptor table and closes them all (pretty ... as described in Parameter Validation. ...
    (microsoft.public.vc.language)
  • Re: [RFC/PATCH] revoke/frevoke system calls V2
    ... As a bonus, ... it works for regular files and even goes as far as destroying ... "EBADF" is not something that applications are taught to expect. ... Someone correct me if I'm wrong, but I can think of no situation under which a file descriptor currently gets yanked out from under your feet -- you should always have to formally abandon it with close. ...
    (Linux-Kernel)
  • Re: Bad file descriptor error
    ... It may mean that google has summarily hung up on you. ... EBADF occurs, if the file descriptor is invalid. ...
    (comp.lang.ruby)