[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to write a proper fork hook code?

From: Svante Signell
Subject: How to write a proper fork hook code?
Date: Sat, 28 Feb 2015 15:32:47 +0100


One remaining problem with the file record lock patches are that the
child after fork inherits the parent's locks. (YES; tdbtorture works
when this code is OK, tried ot differently for now). I've tried
different versions of the lock code and the code below works for some
client code, but not for other. 

* how come?
- code calling fcntl() works.
- code calling the (RPC) file_record_lock() does not!
- tdbtorture does not trigger the code either, even if locks are taken
with fcntl calls??

* the code below iterates over the file descriptor table entries. I
would like to iterate over open file descriptors in the chile. How to do

(indentation edited)

static void
fork_child_rlock (void)
 * Called in the child process after a fork() to clear all locks.
  error_t err;
  int i;
  struct flock64 fl64;

  /* FIXME: locks are taken in HURD_FD_PORT_USE */

  fl64.l_type = F_UNLCK;
  fl64.l_whence = SEEK_SET;
  fl64.l_start = 0;
  fl64.l_len = 0;
  fl64.l_pid = 0;
  err = 0;

for (i = 0; i < _hurd_dtablesize; ++i)
{      struct hurd_fd *d = _hurd_dtable[i];
  if (d == NULL)
    /* Nothing to do for an unused descriptor cell.  */

  /* Check if the FD is open */
  // Not working??
  //if (d->flags == O_RDONLY ||d->flags == O_WRONLY)
err = HURD_FD_PORT_USE (d, __file_record_lock (port, F_SETLK64, &fl64));

(void) &fork_child_rlock; /* Avoid "defined but not used" warning.  */

No difference when using _hurd_fork_child_hook or
//text_set_element (_hurd_fork_child_hook,fork_child_rlock);
text_set_element (_hurd_atfork_child_hook, fork_child_rlock);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]