[Libguestfs] [libnbd PATCH v4 2/3] lib/utils: add async-signal-safe assert()

Eric Blake eblake at redhat.com
Wed Mar 15 17:18:47 UTC 2023


On Wed, Mar 15, 2023 at 12:01:56PM +0100, Laszlo Ersek wrote:
> Add an assert() variant that we may call between fork() and exec*().
> 
> Signed-off-by: Laszlo Ersek <lersek at redhat.com>
> ---
> 

> +void
> +nbd_internal_fork_safe_assert (int result, const char *file, long line,
> +                               const char *func, const char *assertion)
> +{
> +  const char *line_out;
> +  char line_buf[32];
> +
> +  if (result)
> +    return;
> +
> +  line_out = nbd_internal_fork_safe_itoa (line, line_buf, sizeof line_buf);
> +  xwritel (STDERR_FILENO, file, ":", line_out, ": ", func, ": Assertion `",
> +           assertion, "' failed.\n", (char *)NULL);

xwritel() makes this so much shorter ;)

Reviewed-by: Eric Blake <eblake at redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


More information about the Libguestfs mailing list