From 36487c5e54eb1fcf9384719b7cbabfc31cba83fd Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Mon, 10 Feb 2020 17:04:09 +0900 Subject: [PATCH] timer: user-instance: add an argument for open(2) flag into API to open ALSA timer character device As long as using the created Gsource with GMainContext, the call of poll(2) system call with infinite timeout surely returns when quit() method is called for the context. All of GMainContext implements GWakeup with eventfd and the call of quit() emits event via file descriptor of eventfd. This brings wakeup from blocking when poll(2) is called with inifinite timeout. This means that it's safe for event polling without O_NONBLOCK. On the other hand, there are many options for file descriptors; e.g. O_APPEND and O_CLOEXEC. For the case, glib framework has no support. This commit adds an argument for the open flags. Signed-off-by: Takashi Sakamoto --- src/timer/user-instance.c | 7 +++++-- src/timer/user-instance.h | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/timer/user-instance.c b/src/timer/user-instance.c index 9db4b1e..d3b0c48 100644 --- a/src/timer/user-instance.c +++ b/src/timer/user-instance.c @@ -96,11 +96,13 @@ static void alsatimer_user_instance_init(ALSATimerUserInstance *self) /** * alsatimer_user_instance_open: * @self: A #ALSATimerUserInstance. + * @open_flag: The flag of open(2) system call. O_RDONLY is forced to fulfil internally. * @error: A #GError. * * Open ALSA Timer character device to allocate queue. */ -void alsatimer_user_instance_open(ALSATimerUserInstance *self, GError **error) +void alsatimer_user_instance_open(ALSATimerUserInstance *self, gint open_flag, + GError **error) { ALSATimerUserInstancePrivate *priv; char *devnode; @@ -112,7 +114,8 @@ void alsatimer_user_instance_open(ALSATimerUserInstance *self, GError **error) if (*error != NULL) return; - priv->fd = open(devnode, O_RDONLY); + open_flag |= O_RDONLY; + priv->fd = open(devnode, open_flag); g_free(devnode); if (priv->fd < 0) { generate_error(error, errno); diff --git a/src/timer/user-instance.h b/src/timer/user-instance.h index 311b92e..76329ed 100644 --- a/src/timer/user-instance.h +++ b/src/timer/user-instance.h @@ -74,7 +74,8 @@ GType alsatimer_user_instance_get_type() G_GNUC_CONST; ALSATimerUserInstance *alsatimer_user_instance_new(); -void alsatimer_user_instance_open(ALSATimerUserInstance *self, GError **error); +void alsatimer_user_instance_open(ALSATimerUserInstance *self, gint open_flag, + GError **error); void alsatimer_user_instance_attach(ALSATimerUserInstance *self, ALSATimerDeviceId *device_id, -- 2.47.3