[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to write a proper fork hook code?
From: |
Svante Signell |
Subject: |
Re: How to write a proper fork hook code? |
Date: |
Sun, 01 Mar 2015 19:13:16 +0100 |
On Sat, 2015-02-28 at 23:39 +0100, Samuel Thibault wrote:
> Svante Signell, le Sat 28 Feb 2015 15:32:47 +0100, a écrit :
> > * how come?
> > - code calling fcntl() works.
> > - code calling the (RPC) file_record_lock() does not!
>
> Which code? Without showing what you are doing, it's difficult for us to
> understand what you mean.
The code is attached. Compile with RPC_CALLS and FCNTL_CALLS
defined/undefined to get the two versions. with fcntl calls the hook is
triggered and unlocking works as expected, with rpc_calls it does not.
I've put print statements in sysdeps/mach/hurd/fork.c and RUN_HOOK()
is run. However, as there are more than one hook using
_hurd_atfork_child_hook. Is there any way to find out which ones is
called? Using_hurd_fork_child_hook printing does not work, due to??
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?
> > * 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
> > that?
>
> It looks almost right.
> 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? Main problem remains, whatever version is
used.
> I don't think you need to test for that, d == NULL should be enough.
OK!
> > err = HURD_FD_PORT_USE (d, __file_record_lock (port, F_SETLK64, &fl64));
>
> You can probably use _hurd_port_get directly instead, see ctty_new_pgrp
> for instance.
Works for the test code attached, not with tdbtorture.
db open failed: Interrupted system call
child 3411 exited with signal 11
child 3412 exited with signal 15
tdbtorture behaves (wrongly) as the rpc version with:
err = HURD_FD_PORT_USE (d, __file_record_lock (port, F_SETLK64, &fl64));
but does not get any interrupt signals.
>> //text_set_element (_hurd_fork_child_hook,fork_child_rlock);
>> text_set_element (_hurd_atfork_child_hook, fork_child_rlock);
> As I told you, the difference is that the former is run inside the
> critical section (and various locks), while the latter is run outside of
> it.
Got it, see above. I've tried both versions, same main problem as above.
Regarding file_record_lock etc functions, the code that can be used for
testing is the patches I already submitted some time ago.
test_fork.c
Description: Text Data
- Re: How to write a proper fork hook code?,
Svante Signell <=
- Re: How to write a proper fork hook code?, Samuel Thibault, 2015/03/01
- Re: How to write a proper fork hook code?, Svante Signell, 2015/03/01
- Re: How to write a proper fork hook code?, Svante Signell, 2015/03/01
- Re: How to write a proper fork hook code?, Samuel Thibault, 2015/03/01
- Re: How to write a proper fork hook code?, Svante Signell, 2015/03/02
- Re: How to write a proper fork hook code?, Svante Signell, 2015/03/02
- Re: How to write a proper fork hook code?, Samuel Thibault, 2015/03/02
- Re: How to write a proper fork hook code?, Samuel Thibault, 2015/03/02
- Re: How to write a proper fork hook code?, Svante Signell, 2015/03/02
- Re: How to write a proper fork hook code?, Samuel Thibault, 2015/03/02