I'm trying to wrap a variadic function to validate the input beforehand. To be precise i need to call sd_notifyf(int unset_environment, const char *format, ...).
https://www.freedesktop.org/software/systemd/man/sd_notify.html
But before calling sd_notifyf I want to validate the input for the format and then call sd_notify() in the wrapped function.
Currently I've tried the following:
void wrapperFunc(int unset_environment, const char *format, ...) {
va_list list;
va_start(list, format);
//validation of va_args
sd_notifyf(unset_environment, format, list);
va_end(list);
}
int main(int argc, char *argv[]) {
wrapperFunc(0, "STATUS=args: '%s' : '%s'", "arg1", "arg2");
}
In the real code, wrapperFunc() will be called when starting a service, so you can understand why I'm trying to call sd_notifyf().
With my current implementation the following is returned when checking the status of the service: STATUS=args: '^P' : 'arg2'
Why does it only show the second argument properly? And how can I achieve to wrap sd_notifyf() properly?