From patchwork Sat Mar 31 17:10:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10319003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 88D5960247 for ; Sat, 31 Mar 2018 17:12:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C8332932E for ; Sat, 31 Mar 2018 17:12:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 610E329336; Sat, 31 Mar 2018 17:12:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, HK_RANDOM_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 87D832932E for ; Sat, 31 Mar 2018 17:12:09 +0000 (UTC) Received: from localhost ([::1]:38121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f2K2y-0008Vp-9x for patchwork-qemu-devel@patchwork.kernel.org; Sat, 31 Mar 2018 13:12:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f2K2A-00080q-QF for qemu-devel@nongnu.org; Sat, 31 Mar 2018 13:11:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f2K29-0001Zh-Pn for qemu-devel@nongnu.org; Sat, 31 Mar 2018 13:11:18 -0400 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]:34868) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f2K29-0001Xp-IU for qemu-devel@nongnu.org; Sat, 31 Mar 2018 13:11:17 -0400 Received: by mail-lf0-x244.google.com with SMTP id t132-v6so15962773lfe.2 for ; Sat, 31 Mar 2018 10:11:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=/5bI4bddQ5DzilKgcpe91LHINM8eIguwvmF95dzqUZw=; b=K8mAv0Q6sk0NU3amOHaj91F+ppITHLt5pDhgdhw1qGqA3szIEdO1cOZsRBEhglHaq6 fZdruOJMZRJDvTOqViaeGWQEBYHMHGc45Xob3s7tGPnSRPlhi84oXXSkwus8lgmRbq8e eXdX5LchaQE4w8Y3fKagxCDeb/ZeTBeP8EU8k5HOVfQBklpGsPvPyBTpByFKC531yhHL ACaHaBvQeS7sY6o57MykUg6/RnS+PzLMqx29hk3nvwH5+o7N4xLJHmC+7DE+o8bVWw+B TRSw2EWMjoTbmiAtotKrPbV+ZU3pEkcVMR///dW4rzQbiVWAbSWavfbnYQKXCEhs06OZ ptpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/5bI4bddQ5DzilKgcpe91LHINM8eIguwvmF95dzqUZw=; b=fxpDlMnCZpNNkPdO9oXG7Xe+zUfwJ0CLWZyZVko+sLi0dR8teHLUBKI2NJ/Gq49RkG s9OgrPSMIY3MIUSWY6kUKD1pf87Tw2khCa7bqyVgGQHf0lC7IMm3oU5oCyaflti9EaLI uRyYTpX6cVXnihnKY8lIIHwKZd3vUjh5jkC3UAYRy/5XTwEDa/mexmVjKW9abYWZuIoi mEwFR5STVdnIjrdY9ZXqrwRcNihmvBNr7q0mUs/OLj/ratnAy6GzBUBMgklvjPnraq6g Umfvd93qC+wUHw8oGQ8ZK6KUT0PiMFGsct0nK4r6VLkZ/ze4sUzIb9b9vK3uOR8fr1vK b6JA== X-Gm-Message-State: AElRT7GcXhWXoziTOMZkkKkLQghS3jK9YfnMACgawTJ8okEtGnhia13u 47G8t4HLbvCdTOfCD+EDoK545A== X-Google-Smtp-Source: AIpwx4+A+qC/QM9lfxK/4CCJdV0O+JmBirxdnjPqtjPzHTxY9IFUIAEBvMfAXPIG9dCIynQkc50QRA== X-Received: by 10.46.154.71 with SMTP id k7mr2057092ljj.42.1522516276086; Sat, 31 Mar 2018 10:11:16 -0700 (PDT) Received: from octofox.hsd1.ca.comcast.net. (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id t76sm1910752lje.16.2018.03.31.10.11.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Mar 2018 10:11:15 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Sat, 31 Mar 2018 10:10:54 -0700 Message-Id: <20180331171054.20473-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::244 Subject: [Qemu-devel] [PATCH v2] linux-user: fix mq_getsetattr implementation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lionel Landwerlin , Riku Voipio , Laurent Vivier , Max Filippov , "Kirill A . Shutemov" , Aurelien Jarno Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP mq_getsetattr implementation does not set errno correctly in case of error. Also in the presence of both 2nd and 3rd arguments it calls both mq_getattr and mq_setattr, whereas only the latter call would suffice. Don't call mq_getattr in the presence of the 2nd argument. Don't copy output back to user in case of error. Use get_errno to set errno value. This fixes test rt/tst-mqueue2 from the glibc testsuite. Cc: Lionel Landwerlin Cc: Kirill A. Shutemov Cc: Riku Voipio Cc: Aurelien Jarno Cc: Laurent Vivier Signed-off-by: Max Filippov --- Changes v1->v2: - don't copy output back to user in case of error; - fix changelog. linux-user/syscall.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 18ea79140f16..3ff00cc6c098 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -12092,15 +12092,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, { struct mq_attr posix_mq_attr_in, posix_mq_attr_out; ret = 0; - if (arg3 != 0) { - ret = mq_getattr(arg1, &posix_mq_attr_out); - copy_to_user_mq_attr(arg3, &posix_mq_attr_out); - } if (arg2 != 0) { copy_from_user_mq_attr(&posix_mq_attr_in, arg2); - ret |= mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out); + ret = mq_setattr(arg1, &posix_mq_attr_in, &posix_mq_attr_out); + } else if (arg3 != 0) { + ret = mq_getattr(arg1, &posix_mq_attr_out); } - + if (ret == 0 && arg3 != 0) { + copy_to_user_mq_attr(arg3, &posix_mq_attr_out); + } + ret = get_errno(ret); } break; #endif