From 9dc1e2f9b675fd5c49bffda4cb658fb3ed554668 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Mon, 16 Nov 2020 11:45:41 +0900 Subject: [PATCH] rawmidi: stream_pair: report error about write-only file descriptor In design of ALSA rawmidi interface, one character device can handle operations for both capture and playback. Applications can indicate usage of both or either by flags of open system call. The libalsarawmidi library checks the flag by fcntl(2) system call to create GSource for capture. When the file descriptor is not configured for read, the call returns error. This commit handles the error for local error reporting. Signed-off-by: Takashi Sakamoto --- src/rawmidi/alsarawmidi-enum-types.h | 2 ++ src/rawmidi/stream-pair.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rawmidi/alsarawmidi-enum-types.h b/src/rawmidi/alsarawmidi-enum-types.h index 6da9cb2..7c385b1 100644 --- a/src/rawmidi/alsarawmidi-enum-types.h +++ b/src/rawmidi/alsarawmidi-enum-types.h @@ -35,12 +35,14 @@ typedef enum /*< flags >*/ * ALSARawmidiStreamPairError: * @ALSARAWMIDI_STREAM_PAIR_ERROR_FAILED: The system call failed. * @ALSARAWMIDI_STREAM_PAIR_ERROR_DISCONNECTED: The card associated to the instance is in disconnect state. + * @ALSARAWMIDI_STREAM_PAIR_ERROR_UNREADABLE: The instance is not for read operation. * * A set of error code for GError with domain which equals to #alsarawmidi_stream_pair_error_quark() */ typedef enum { ALSARAWMIDI_STREAM_PAIR_ERROR_FAILED, ALSARAWMIDI_STREAM_PAIR_ERROR_DISCONNECTED, + ALSARAWMIDI_STREAM_PAIR_ERROR_UNREADABLE, } ALSARawmidiStreamPairError; #endif diff --git a/src/rawmidi/stream-pair.c b/src/rawmidi/stream-pair.c index 9c4b034..3e62dc1 100644 --- a/src/rawmidi/stream-pair.c +++ b/src/rawmidi/stream-pair.c @@ -52,6 +52,7 @@ G_DEFINE_QUARK(alsarawmidi-stream-pair-error-quark, alsarawmidi_stream_pair_erro static const char *const err_msgs[] = { [ALSARAWMIDI_STREAM_PAIR_ERROR_DISCONNECTED] = "The card is in disconnect state", + [ALSARAWMIDI_STREAM_PAIR_ERROR_UNREADABLE] = "The instance is not for read operation", }; #define generate_local_error(error, code) \ @@ -662,7 +663,7 @@ void alsarawmidi_stream_pair_create_source(ALSARawmidiStreamPair *self, } if (!(access_modes & O_RDWR) && !(access_modes & O_WRONLY)) { - generate_error(error, ENOTSUP); + generate_local_error(error, ALSARAWMIDI_STREAM_PAIR_ERROR_UNREADABLE); return; } -- 2.47.3