]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
seq: user_client: report error for port access permission
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 15 Nov 2020 02:54:07 +0000 (11:54 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Sun, 15 Nov 2020 13:34:07 +0000 (22:34 +0900)
Port in ALSA sequencer has capability and client has access permission
to operate the port. When unpermitted, the operation fails and return
EPERM error code.

This commit handles the code for local error.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/seq/alsaseq-enum-types.h
src/seq/user-client.c
tests/alsaseq-enums

index 975b0eaff8d41e7bdb52aa0314fa92aa4c4a9308..b741e81da68fcec3246753149c128b7f850e60c2 100644 (file)
@@ -364,12 +364,14 @@ typedef enum /*< flags >*/
 
 /**
  * ALSASeqUserClientError:
- * @ALSASEQ_USER_CLIENT_ERROR_FAILED:  The system call failed.
+ * @ALSASEQ_USER_CLIENT_ERROR_FAILED:              The system call failed.
+ * @ALSASEQ_USER_CLIENT_ERROR_PORT_PERMISSION:      The operation fails due to access permission of port.
  *
  * A set of error code for GError with domain which equals to #alsaseq_user_client_error_quark()
  */
 typedef enum {
     ALSASEQ_USER_CLIENT_ERROR_FAILED,
+    ALSASEQ_USER_CLIENT_ERROR_PORT_PERMISSION,
 } ALSASeqUserClientError;
 
 #endif
index 5c639206188321480108f9df535b8308830f5304..2f1b3ddcf17a1221e7c8b3a25ea93116b704130e 100644 (file)
@@ -43,6 +43,13 @@ G_DEFINE_TYPE_WITH_PRIVATE(ALSASeqUserClient, alsaseq_user_client, G_TYPE_OBJECT
  */
 G_DEFINE_QUARK(alsaseq-user-client-error-quark, alsaseq_user_client_error)
 
+static const char *const err_msgs[] = {
+        [ALSASEQ_USER_CLIENT_ERROR_PORT_PERMISSION] = "The operation fails due to access permission of port",
+};
+
+#define generate_local_error(exception, code) \
+        g_set_error_literal(exception, ALSASEQ_USER_CLIENT_ERROR, code, err_msgs[code])
+
 #define generate_syscall_error(exception, errno, fmt, arg) \
         g_set_error(exception, ALSASEQ_USER_CLIENT_ERROR, ALSASEQ_USER_CLIENT_ERROR_FAILED, \
                     fmt" %d(%s)", arg, errno, strerror(errno))
@@ -680,8 +687,12 @@ void alsaseq_user_client_operate_subscription(ALSASeqUserClient *self,
         label = "UNSUBSCRIBE_PORT";
     }
 
-    if (ioctl(priv->fd, request, data) < 0)
-        generate_syscall_error(error, errno, "ioctl(%s)", label);
+    if (ioctl(priv->fd, request, data) < 0) {
+        if (errno == EPERM)
+            generate_local_error(error, ALSASEQ_USER_CLIENT_ERROR_PORT_PERMISSION);
+        else
+            generate_syscall_error(error, errno, "ioctl(%s)", label);
+    }
 }
 
 /**
index 0375e2639dc32ed7184329a50d912f698591b75d..602ea8cd601e1dfd9f4e0b9c20e09aede298ff09 100644 (file)
@@ -166,6 +166,7 @@ remove_filter_flags = (
 
 user_client_error_types = (
     'FAILED',
+    'PORT_PERMISSION',
 )
 
 types = {