I am trying to LD_PRELOAD the linux's clone function. In my LD_PRELOADed version I need to log the input paramters before calling the original clone function. However, the problem is that clone takes variable number of arguments. It is declared like this.
int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...
/* pid_t *pid, struct user_desc *tls, pid_t *ctid */ );
Now to pass these arguments to the original clone function, I must know the number of arguments that were passed in. How can I do that?
Use the va_* functions, these are the way to go when working with variable argument lists.
Here's the man page which also contains an example at the end.
If there is a NULL terminator, you can call va_arg while it doesn't return NULL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With