From: Takashi Sakamoto Date: Mon, 10 Feb 2020 08:02:03 +0000 (+0900) Subject: ctl: card: add an argument for open(2) flag into API to open ALSA control character... X-Git-Tag: v0.1.0~318 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=b911ef0b2f27427b7c1aafd982adfc411ebbe57e;p=alsa-gobject.git ctl: card: add an argument for open(2) flag into API to open ALSA control 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 --- diff --git a/src/ctl/card.c b/src/ctl/card.c index 0a53a7c..953920f 100644 --- a/src/ctl/card.c +++ b/src/ctl/card.c @@ -161,11 +161,13 @@ ALSACtlCard *alsactl_card_new() * alsactl_card_open: * @self: A #ALSACtlCard. * @card_id: The numerical ID of sound card. + * @open_flag: The flag of open(2) system call. O_RDONLY is forced to fulfil internally. * @error: A #GError. * * Open ALSA control character device for the sound card. */ -void alsactl_card_open(ALSACtlCard *self, guint card_id, GError **error) +void alsactl_card_open(ALSACtlCard *self, guint card_id, gint open_flag, + GError **error) { ALSACtlCardPrivate *priv; char *devnode; @@ -177,7 +179,8 @@ void alsactl_card_open(ALSACtlCard *self, guint card_id, GError **error) if (*error != NULL) return; - priv->fd = open(devnode, O_RDONLY | O_NONBLOCK); + open_flag |= O_RDONLY; + priv->fd = open(devnode, open_flag); if (priv->fd < 0) { generate_error(error, errno); g_free(devnode); diff --git a/src/ctl/card.h b/src/ctl/card.h index c932d00..c2247b2 100644 --- a/src/ctl/card.h +++ b/src/ctl/card.h @@ -76,7 +76,8 @@ GType alsactl_card_get_type() G_GNUC_CONST; ALSACtlCard *alsactl_card_new(); -void alsactl_card_open(ALSACtlCard *self, guint card_id, GError **error); +void alsactl_card_open(ALSACtlCard *self, guint card_id, gint open_flag, + GError **error); void alsactl_card_get_info(ALSACtlCard *self, ALSACtlCardInfo **card_info, GError **error);