]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: user_instance: report error due to open system call
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sat, 14 Nov 2020 08:28:09 +0000 (17:28 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sat, 14 Nov 2020 08:28:09 +0000 (17:28 +0900)
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 <o-takashi@sakamocchi.jp>
src/timer/user-instance.c

index bd7c851b3e5b7f140654428a4fe05466734fc11a..580a1039da184d787f11b145e50b2c3dc8d746ae 100644 (file)
@@ -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) {