glib-aux: add nm_g_child_watch_source_new() and nm_g_child_watch_add_source() helpers

This commit is contained in:
Thomas Haller 2021-08-03 09:06:48 +02:00
parent 5d08d3a7ef
commit b7c77d51eb
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 31 additions and 0 deletions

View file

@ -5097,6 +5097,23 @@ nm_g_unix_fd_source_new(int fd,
return source;
}
GSource *
nm_g_child_watch_source_new(GPid pid,
int priority,
GChildWatchFunc handler,
gpointer user_data,
GDestroyNotify notify)
{
GSource *source;
source = g_child_watch_source_new(pid);
if (priority != G_PRIORITY_DEFAULT)
g_source_set_priority(source, priority);
g_source_set_callback(source, G_SOURCE_FUNC(handler), user_data, notify);
return source;
}
/*****************************************************************************/
#define _CTX_LOG(fmt, ...) \

View file

@ -1728,6 +1728,12 @@ GSource *nm_g_unix_signal_source_new(int signum,
gpointer user_data,
GDestroyNotify notify);
GSource *nm_g_child_watch_source_new(GPid pid,
int priority,
GChildWatchFunc handler,
gpointer user_data,
GDestroyNotify notify);
static inline GSource *
nm_g_source_attach(GSource *source, GMainContext *context)
{
@ -1824,6 +1830,14 @@ nm_g_unix_signal_add_source(int signum, GSourceFunc handler, gpointer user_data)
NULL);
}
static inline GSource *
nm_g_child_watch_add_source(GPid pid, GChildWatchFunc handler, gpointer user_data)
{
return nm_g_source_attach(
nm_g_child_watch_source_new(pid, G_PRIORITY_DEFAULT, handler, user_data, NULL),
NULL);
}
NM_AUTO_DEFINE_FCN0(GMainContext *, _nm_auto_unref_gmaincontext, g_main_context_unref);
#define nm_auto_unref_gmaincontext nm_auto(_nm_auto_unref_gmaincontext)