Skip to content
Snippets Groups Projects
Commit b5d925ac authored by Simon McVittie's avatar Simon McVittie
Browse files

utils: Add pv_async_signal_safe_error()


This gives us a way to report failure in a signal handler, or between
fork() and exec(), both of which are contexts where only a restricted
set of async-signal-safe functions are allowed. See signal-safety(7),
signal(7) and fork(2) for details.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent c309cd18
No related branches found
No related tags found
No related merge requests found
......@@ -523,3 +523,24 @@ pv_divert_stdout_to_stderr (GError **error)
return g_steal_pointer (&original_stdout);
}
/**
* pv_async_signal_safe_error:
* @message: A human-readable message
* @exit_status: Call `_exit` with this status
*
* Exit with a fatal error, like g_error(), but async-signal-safe
* (see signal-safety(7)).
*/
void
pv_async_signal_safe_error (const char *message,
int exit_status)
{
if (write (2, message, strlen (message)) < 0)
{
/* Ignore - there's nothing we can do about it anyway - but
* suppress -Wunused-result. */
}
_exit (exit_status);
}
......@@ -55,3 +55,6 @@ gboolean pv_boolean_environment (const gchar *name,
gboolean def);
FILE *pv_divert_stdout_to_stderr (GError **error);
void pv_async_signal_safe_error (const char *message,
int exit_status) G_GNUC_NORETURN;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment