From a400f241e9ef72f7383c4d7a1556266898dd9faa Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sat, 14 Nov 2020 17:28:09 +0900 Subject: [PATCH] timer: user_instance: report error due to open system call 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/timer/user-instance.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/timer/user-instance.c b/src/timer/user-instance.c index bd7c851..580a103 100644 --- a/src/timer/user-instance.c +++ b/src/timer/user-instance.c @@ -43,6 +43,9 @@ G_DEFINE_QUARK(alsatimer-user-instance-error-quark, alsatimer_user_instance_erro g_set_error(exception, ALSATIMER_USER_INSTANCE_ERROR, ALSATIMER_USER_INSTANCE_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; ALSATimerUserInstance *self; @@ -148,11 +151,18 @@ void alsatimer_user_instance_open(ALSATimerUserInstance *self, gint open_flag, open_flag |= O_RDONLY; priv->fd = open(devnode, open_flag); - g_free(devnode); 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, errno, "open(%s)", devnode); + else + generate_syscall_error(error, errno, "open(%s)", devnode); + + g_free(devnode); return; } + g_free(devnode); // Remember the version of protocol currently used. if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_PVERSION, &proto_ver) < 0) { -- 2.47.3