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

Re: How to write a proper fork hook code?



Hello,

Svante Signell, le Sun 01 Mar 2015 19:13:16 +0100, a écrit :
> However, as there are more than one hook using
> _hurd_atfork_child_hook. Is there any way to find out which ones is
> called?

All of them are called.

> Using_hurd_fork_child_hook printing does not work, due to??

As suggested on irc, use the mach_print system call, it should be always
working.

> BTW: All tests are made by LD_PRELOAD/LD_LIBRARY_PATH after building new
> versions of libc.so (and libmachuser.so, libhurduser.so). I assume
> testing can be done this way, not needing to install built packages?

Yes.  You can check with ldd that it's working.

> > You should enter the critical section before that, by using
> > HURD_CRITICAL_BEGIN and HURD_CRITICAL_END
> 
> Done that for _hurd_atfork_child_hook. Not needed for
> _hurd_fork_child_hook, right?

Yes.

> #ifdef FCNTL_CALLS
>       cmd = F_GETLK64;
>       err = fcntl (fd1, cmd, &lock);
>       if (err)
> 	error (1, err, "fcntl child");
>       printf ("Child lock status: '%s'\n", fcntl2str (lock.l_type));
> #endif
> 
> #ifdef FCNTL_CALLS
>       cmd = F_GETLK64;
>       err = fcntl (fd1, cmd, &lock);
>       if (err)
> 	error (1, err, "fcntl parent");
>       printf ("Parent lock status: '%s'\n", fcntl2str (lock.l_type));
> #endif

Err, but I believe there is a misunderstanding here: F_GETLK does not
return whether the caller has a lock on the file, but whether there is
an existing lock that would prevent from acquiring one.

Samuel


Reply to: