Skip to contentSkip to conversation

at_fork & at_exit

DISCUSSION Arun C Murthy 4 participants 5 messages Dec 21, 2004 – Dec 24, 2004

lore
Share & tools
lore
#0 lore raw

Hi,

Im looking for linux equivalent of the FreeBSD calls:

1. at_fork

    typedef void
    (*forklist_fn)(struct proc *, struct proc *, int);

    int at_fork(forklist_fn func);

    The at_fork facility allows a kernel module to ensure that it is 

notified at any process fork. The function func is called with the a pointer to the forking process's proc structure, a pointer to the child's process structure and a flag word, as used in rfork(2) to indicate the type of fork.

If the requirement for notification is removed, then the function
rm_at_fork() must be called with the exact func argument as the corresponding call to at_fork().

2. at_exit

    typedef void (exitlist_fn) (struct proc *);

    int at_exit(exitlist_fn func);

    The at_exit facility allows a kernel module to ensure that it is 

notified at any process exit. The function func is called with the a pointer to the exiting process's proc structure.

Specifically im on RHEL3... any pointers are appreciated...

thanks,
Arun

#1 lore raw
Quoted 10 lines

Hi,

Im looking for linux equivalent of the FreeBSD calls:

1. at_fork

typedef void
(*forklist_fn)(struct proc *, struct proc *, int);

   int at_fork(forklist_fn func);

I do not see such a hook in the kernel source tree, so adding your own seems to only way.

The places are in kernel/fork.c:copy_process() and kernel/exit.c:__unhash_process

Jan Engelhardt

Signature · 1 line
ENOSPC
#3 lore raw
In reply to Arun C Murthy
Quoted 6 lines · Arun C Murthy

Im looking for linux equivalent of the FreeBSD calls:

1. at_fork
2. at_exit

Specifically im on RHEL3... any pointers are appreciated...

What do you want to use them for ?

If it is for security logging, it may be an option to use the syscall auditing code ...

Signature · 3 lines
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan
#4 lore raw
In reply to Arun C Murthy
Quoted 3 lines · Arun C Murthy

Im looking for linux equivalent of the FreeBSD calls:
1. at_fork
2. at_exit

There is an ANSI C equivalent of at_exit: it's called atexit(). Use that
instead of OS-specific hacks like at_exit.

No direct analog to at_fork() that I know of, but there's a "sort of" equivalent thing you can use: pthread_atfork(). No reason why you can't use it, even if your program is not multi-threaded..

#2 lore raw
In reply to Jan Engelhardt
Quoted 12 lines · Jan Engelhardt
Quoted 8 lines

Hi,

Im looking for linux equivalent of the FreeBSD calls:

1. at_fork
2. at_exit

I do not see such a hook in the kernel source tree, so adding your own seems to only way. The places are in kernel/fork.c:copy_process() and kernel/exit.c:__unhash_process

here's patches if someone else is interested... pls let me know if
there are any improvements possible...

Arun