Not too sure which mailing list this is applicable to so apologies if
cross posting to both the general and development list gets under
peoples skin ...

I've got a daemon which processes files from a directory, one child is
forked per pair of files (the files come in corresponding pairs).

To ensure that two children don't try to process the same set of files
(obtained via readdir) is use record locking using the following piece
of code on an already opened file

#include <sys/types.h>
#include <fcntl.h>

int locking (int, int, int, off_t, int, off_t);

int lock_file (int fd)
{
  return (locking (fd, F_SETLK, F_WRLCK, 0, 0, 0));
}
^L
int unlock_file (int fd)
{
  return (locking (fd, F_SETLK, F_UNLCK, 0, 0, 0));
}
^L
int locking (int fd, int cmd, int type, off_t offset, int whence, off_t
len
)
{
  struct flock  lock;

  lock.l_type   = type;
  lock.l_start  = offset;
  lock.l_whence = whence;
  lock.l_len    = len;

  return (fcntl (fd, cmd, &lock));
}

I've also got a daemon creation subroutine (oops - revealing my VAX-11
FORTRAN heritage there) which does the standard fork,  setsid (), chdir
("/") and umask (0) thang.

Now I don't want my children to create zombies to I also specifically
set SIGCLD to SIG_IGN and this is where the fun starts.

If I do this I always get a -1 returned from fcntl and an errno of
EAGAIN. If I remove the call to signal () - hey presto, everything locks
perfectly.

I've scoured the man pages, all the documentation available to me,
printed books, raided the man pages on Sun, Digital Unix, HP-UX,
slakware and every other *nix I can lay my grubby little mits on - even
Tandem NonStop-UX which is so non-standard it barely qualifies as a
Unix-a-like, but all to no avail.

So to paraphrase Princess Leia - "help me Redhat-ones, you are my only
hope" - groan - OK that _WAS_ corny but you get the idea.

Any ideas out there?

Gary
(who's listening to Aerosmith's Big Ones as he types and is actually
finding it quite conducive to coding)

--------------------------------------------------------
Gary Gale / G-Tech Ltd / Chiswick / London
Email: [EMAIL PROTECTED]
       [EMAIL PROTECTED]
Web: http://dspace.dial.pipex.com/town/plaza/gy90/

Project Options: On Time, Zero Defects - select one only
--------------------------------------------------------




-- 
  PLEASE read the Red Hat FAQ, Tips, Errata and the MAILING LIST ARCHIVES!
http://www.redhat.com/RedHat-FAQ /RedHat-Errata /RedHat-Tips /mailing-lists
         To unsubscribe: mail [EMAIL PROTECTED] with 
                       "unsubscribe" as the Subject.

Reply via email to