]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
ctl: card: report open error
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Fri, 13 Nov 2020 07:26:26 +0000 (16:26 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Fri, 13 Nov 2020 07:30:44 +0000 (16:30 +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/ctl/card.c

index ea1f1f44f7f8ee3ec7bf6caebf2a4a70b92a1053..19c47f7d957651fea4c50399ddd44c06c8e3b20a 100644 (file)
@@ -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;
     }