From d65c3950d00c4f7c6f2724d2157cdf6f177c3d75 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Fri, 13 Nov 2020 16:26:26 +0900 Subject: [PATCH] ctl: card: report error due to existent control element The operation to add user-defined control elements returns EBUSY when sound card has any control element which has the same identifier. This commit handles the error in local error domain. Signed-off-by: Takashi Sakamoto --- src/ctl/alsactl-enum-types.h | 2 ++ src/ctl/card.c | 3 +++ tests/alsactl-enums | 1 + 3 files changed, 6 insertions(+) diff --git a/src/ctl/alsactl-enum-types.h b/src/ctl/alsactl-enum-types.h index 01a8c90..794bd74 100644 --- a/src/ctl/alsactl-enum-types.h +++ b/src/ctl/alsactl-enum-types.h @@ -116,6 +116,7 @@ typedef enum /*< flags >*/ * @ALSACTL_CARD_ERROR_ELEM_NOT_FOUND: The control element not found in the card. * @ALSACTL_CARD_ERROR_ELEM_NOT_SUPPORTED: The operation is not supported by the control element. * @ALSACTL_CARD_ERROR_ELEM_OWNED: The control element is owned by the other process. + * @ALSACTL_CARD_ERROR_ELEM_EXIST: The control element already exists. * * A set of error code for GError with domain which equals to #alsactl_card_error_quark() */ @@ -125,6 +126,7 @@ typedef enum { ALSACTL_CARD_ERROR_ELEM_NOT_FOUND, ALSACTL_CARD_ERROR_ELEM_NOT_SUPPORTED, ALSACTL_CARD_ERROR_ELEM_OWNED, + ALSACTL_CARD_ERROR_ELEM_EXIST, } ALSACtlCardError; #endif diff --git a/src/ctl/card.c b/src/ctl/card.c index a325800..183af20 100644 --- a/src/ctl/card.c +++ b/src/ctl/card.c @@ -44,6 +44,7 @@ static const char *const err_msgs[] = { [ALSACTL_CARD_ERROR_ELEM_NOT_FOUND] = "The control element not found in the card", [ALSACTL_CARD_ERROR_ELEM_NOT_SUPPORTED] = "The operation is not supported by the control element.", [ALSACTL_CARD_ERROR_ELEM_OWNED] = "The control element is owned by the other process.", + [ALSACTL_CARD_ERROR_ELEM_EXIST] = "The control element already exists.", }; #define generate_local_error(exception, code) \ @@ -809,6 +810,8 @@ static void add_or_replace_elems(int fd, const ALSACtlElemId *elem_id, } else if (errno == EBUSY) { if (replace) generate_local_error(error, ALSACTL_CARD_ERROR_ELEM_OWNED); + else + generate_local_error(error, ALSACTL_CARD_ERROR_ELEM_EXIST); } else { generate_syscall_error(error, errno, "ioctl(%s)", req_name); } diff --git a/tests/alsactl-enums b/tests/alsactl-enums index 7524b1e..01cf41c 100644 --- a/tests/alsactl-enums +++ b/tests/alsactl-enums @@ -57,6 +57,7 @@ card_error_types = ( 'ELEM_NOT_FOUND', 'ELEM_NOT_SUPPORTED', 'ELEM_OWNED', + 'ELEM_EXIST', ) types = { -- 2.47.3