From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E41CFC00144 for ; Fri, 29 Jul 2022 21:22:00 +0000 (UTC) Received: from localhost ([::1]:40940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHXQl-00067I-Mt for qemu-devel@archiver.kernel.org; Fri, 29 Jul 2022 17:21:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHXOI-00059q-HG for qemu-devel@nongnu.org; Fri, 29 Jul 2022 17:19:26 -0400 Received: from donkey.codingfarm.de ([2a01:4f8:190:12cf::d:1]:39994) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHXOE-0004P7-Hh for qemu-devel@nongnu.org; Fri, 29 Jul 2022 17:19:24 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by donkey.codingfarm.de (Postfix) with ESMTPSA id C7C4C8F267; Fri, 29 Jul 2022 23:19:17 +0200 (CEST) Message-ID: Date: Fri, 29 Jul 2022 23:19:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.23) Gecko/20090925 Thunderbird/2.0.0.23 Mnenhy/0.7.5.0 Subject: Re: [PATCH v2] linux-user: Use memfd for open syscall emulation Content-Language: en-US To: Richard Henderson , qemu-devel@nongnu.org Cc: Laurent Vivier References: <20220725162811.87985-1-raimue@codingfarm.de> <20220729154951.76268-1-raimue@codingfarm.de> From: =?UTF-8?Q?Rainer_M=c3=bcller?= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a01:4f8:190:12cf::d:1; envelope-from=raimue@codingfarm.de; helo=donkey.codingfarm.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 29/07/2022 18.01, Richard Henderson wrote: > On 7/29/22 08:49, Rainer Müller wrote: >> +            /* create temporary file to map stat to */ >> +            tmpdir = getenv("TMPDIR"); >> +            if (!tmpdir) >> +                tmpdir = "/tmp"; >> +            snprintf(filename, sizeof(filename), >> "%s/qemu-open.XXXXXX", tmpdir); >> +            fd = mkstemp(filename); >> +            if (fd < 0) { >> +                return fd; >> +            } > > We've been using g_file_open_tmp elsewhere; probably good to follow suit > here. That seemed reasonable at first, but with regards to error handling it gets a bit complicated. The suggested g_file_open_tmp() would leave us with a GError only, but to return something meaningful to the caller we must set errno in this context. As far as I can see, there is no way to convert back to an errno from GError. With g_file_open_tmp() we could always set the same generic errno, but that would hide the real cause completely. I debugged this problem with this message that was confusing, but at least it gave away a hint: cat: can't open '/proc/self/stat': Read-only file system The other option would be to g_assert_true(fd >= 0) and kill the process in case opening the temporary file failed. This also feels wrong, as the caller could still recover from this state and continue. Rainer