diff options
author | Florian Weimer <fweimer@redhat.com> | 2021-06-25 10:42:52 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2021-06-25 12:20:47 +0200 |
commit | 2da5f22fff639e891b9f516724683d9d7ad1511c (patch) | |
tree | 89ef1ccd5f2d6d3363704cd03a797f94a9ba9da3 /sysdeps/unix/sysv/linux/mq_notify.c | |
parent | f66d9abca7ecc4ee4c7afcc1d1496411bfc70911 (diff) | |
download | glibc-2da5f22fff639e891b9f516724683d9d7ad1511c.tar glibc-2da5f22fff639e891b9f516724683d9d7ad1511c.tar.gz glibc-2da5f22fff639e891b9f516724683d9d7ad1511c.tar.bz2 glibc-2da5f22fff639e891b9f516724683d9d7ad1511c.zip |
Linux: Move mq_notify from librt to libc
The symbol was moved using scripts/move-symbol-to-libc.py.
An explicit call from fork into the mq_notify implementation replaces
the previous use of pthread_atfork.
Reviewed-by: Adhemerva Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps/unix/sysv/linux/mq_notify.c')
-rw-r--r-- | sysdeps/unix/sysv/linux/mq_notify.c | 59 |
1 files changed, 23 insertions, 36 deletions
diff --git a/sysdeps/unix/sysv/linux/mq_notify.c b/sysdeps/unix/sysv/linux/mq_notify.c index e22850a910..9799dcdaa4 100644 --- a/sysdeps/unix/sysv/linux/mq_notify.c +++ b/sysdeps/unix/sysv/linux/mq_notify.c @@ -29,7 +29,7 @@ #include <sys/socket.h> #include <not-cancel.h> #include <pthreadP.h> - +#include <shlib-compat.h> /* Defined in the kernel headers: */ #define NOTIFY_COOKIE_LEN 32 /* Length of the cookie used. */ @@ -75,7 +75,7 @@ change_sigmask (int how, sigset_t *oss) { sigset_t ss; sigfillset (&ss); - return pthread_sigmask (how, &ss, oss); + return __pthread_sigmask (how, &ss, oss); } @@ -93,7 +93,7 @@ notification_function (void *arg) (void) __pthread_barrier_wait (¬ify_barrier); /* Make the thread detached. */ - (void) pthread_detach (pthread_self ()); + __pthread_detach (__pthread_self ()); /* The parent thread has all signals blocked. This is probably a bit surprising for this thread. So we unblock all of them. */ @@ -125,9 +125,8 @@ helper_thread (void *arg) /* Just create the thread as instructed. There is no way to report a problem with creating a thread. */ pthread_t th; - if (__builtin_expect (pthread_create (&th, data.attr, - notification_function, &data) - == 0, 0)) + if (__pthread_create (&th, data.attr, notification_function, &data) + == 0) /* Since we passed a pointer to DATA to the new thread we have to wait until it is done with it. */ (void) __pthread_barrier_wait (¬ify_barrier); @@ -135,7 +134,7 @@ helper_thread (void *arg) else if (data.raw[NOTIFY_COOKIE_LEN - 1] == NOTIFY_REMOVED) { /* The only state we keep is the copy of the thread attributes. */ - pthread_attr_destroy (data.attr); + __pthread_attr_destroy (data.attr); free (data.attr); } } @@ -143,8 +142,8 @@ helper_thread (void *arg) } -static void -reset_once (void) +void +__mq_notify_fork_subprocess (void) { once = PTHREAD_ONCE_INIT; } @@ -167,15 +166,14 @@ init_mq_netlink (void) int err = 1; /* Initialize the barrier. */ - if (__builtin_expect (__pthread_barrier_init (¬ify_barrier, NULL, 2) == 0, - 0)) + if (__pthread_barrier_init (¬ify_barrier, NULL, 2) == 0) { /* Create the helper thread. */ pthread_attr_t attr; - (void) pthread_attr_init (&attr); - (void) pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); + __pthread_attr_init (&attr); + __pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); /* We do not need much stack space, the bare minimum will be enough. */ - (void) pthread_attr_setstacksize (&attr, __pthread_get_minstack (&attr)); + __pthread_attr_setstacksize (&attr, __pthread_get_minstack (&attr)); /* Temporarily block all signals so that the newly created thread inherits the mask. */ @@ -183,29 +181,13 @@ init_mq_netlink (void) int have_no_oss = change_sigmask (SIG_BLOCK, &oss); pthread_t th; - err = pthread_create (&th, &attr, helper_thread, NULL); + err = __pthread_create (&th, &attr, helper_thread, NULL); /* Reset the signal mask. */ if (!have_no_oss) - pthread_sigmask (SIG_SETMASK, &oss, NULL); - - (void) pthread_attr_destroy (&attr); + __pthread_sigmask (SIG_SETMASK, &oss, NULL); - if (err == 0) - { - static int added_atfork; - - if (added_atfork == 0 - && pthread_atfork (NULL, NULL, reset_once) != 0) - { - /* The child thread will call recv() which is a - cancellation point. */ - (void) pthread_cancel (th); - err = 1; - } - else - added_atfork = 1; - } + __pthread_attr_destroy (&attr); } if (err != 0) @@ -219,7 +201,7 @@ init_mq_netlink (void) /* Register notification upon message arrival to an empty message queue MQDES. */ int -mq_notify (mqd_t mqdes, const struct sigevent *notification) +__mq_notify (mqd_t mqdes, const struct sigevent *notification) { /* Make sure the type is correctly defined. */ assert (sizeof (union notify_data) == NOTIFY_COOKIE_LEN); @@ -235,7 +217,7 @@ mq_notify (mqd_t mqdes, const struct sigevent *notification) response. */ /* Initialize only once. */ - pthread_once (&once, init_mq_netlink); + __pthread_once (&once, init_mq_netlink); /* If we cannot create the netlink socket we cannot provide SIGEV_THREAD support. */ @@ -280,9 +262,14 @@ mq_notify (mqd_t mqdes, const struct sigevent *notification) /* If it failed, free the allocated memory. */ if (retval != 0 && data.attr != NULL) { - pthread_attr_destroy (data.attr); + __pthread_attr_destroy (data.attr); free (data.attr); } return retval; } +versioned_symbol (libc, __mq_notify, mq_notify, GLIBC_2_34); +libc_hidden_ver (__mq_notify, mq_notify) +#if OTHER_SHLIB_COMPAT (librt, GLIBC_2_3_4, GLIBC_2_34) +compat_symbol (librt, __mq_notify, mq_notify, GLIBC_2_3_4); +#endif |