From fd11af6976670ab307bc0d41a1edceabf004e6f8 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Fri, 13 Nov 2020 16:26:26 +0900 Subject: [PATCH] ctl: card: report open error The call of open system call can return several types of error from VFS. It's hard to dispatch all of the error in local error domain. This commit uses GFileError to dispatch the most of the error. At failure of conversion to GFileError, local error domain is used. Signed-off-by: Takashi Sakamoto --- src/ctl/card.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ctl/card.c b/src/ctl/card.c index ea1f1f4..19c47f7 100644 --- a/src/ctl/card.c +++ b/src/ctl/card.c @@ -43,6 +43,9 @@ G_DEFINE_QUARK(alsactl-card-error-quark, alsactl_card_error) g_set_error(exception, ALSACTL_CARD_ERROR, ALSACTL_CARD_ERROR_FAILED, \ fmt" %d(%s)", arg, errno, strerror(errno)) +#define generate_file_error(exception, code, format, arg) \ + g_set_error(exception, G_FILE_ERROR, code, format, arg) + typedef struct { GSource src; ALSACtlCard *self; @@ -207,7 +210,13 @@ void alsactl_card_open(ALSACtlCard *self, guint card_id, gint open_flag, open_flag |= O_RDONLY; priv->fd = open(devnode, open_flag); if (priv->fd < 0) { - generate_error(error, errno); + GFileError code = g_file_error_from_errno(errno); + + if (code != G_FILE_ERROR_FAILED) + generate_file_error(error, code, "open(%s)", devnode); + else + generate_syscall_error(error, errno, "open(%s)", devnode); + g_free(devnode); return; } -- 2.47.3