From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 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 dcvr.yhbt.net (Postfix) with ESMTPS id 5EEFE1F66E for ; Sun, 23 Aug 2020 17:38:56 +0000 (UTC) Received: from localhost ([::1]:45426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k9txH-0003WL-9h for normalperson@yhbt.net; Sun, 23 Aug 2020 13:38:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9txA-0003W6-0V for bug-gnulib@gnu.org; Sun, 23 Aug 2020 13:38:48 -0400 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.219]:34900) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k9tx7-000160-LO for bug-gnulib@gnu.org; Sun, 23 Aug 2020 13:38:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1598204322; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=WxOOm+AwrR6sql3aEuDc6QGD01ii3MbWQ1qR7ikypN8=; b=hSjkUQaa7fHfiY7rl0q9tMxtpCQkckBDLc7eXM5PZx3IiBy6Hd9acp9tLZAqdj/vbL kRkX654BFdj9nGAxOQPLCiwSUZHkWKpFk0NQ/VQZn/3Dbp95y/HLLUGvXJ+ifGQ6ghNW 1qMe+94Ikr7cYTNHKz2KdcPxXpkaa4QbmpEtHihhKN8zbdojjGZAaUijkcf1NWpyaBDd tBrxW3fxeBbg0/8EIYXkk1zX174F1/M43xAhg75VGgpodDtw1Cv8S9VpgnRlGRE2ye+7 Ot+xjxjm7mFqIJjzaEN7agNdxAOi5ff0bt6HseedYUIAaIMeWKpfcaqNaQJ9RSHApxZn ZKwg== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOHqfyyPs=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 46.10.7 DYNA|AUTH) with ESMTPSA id z05f0fw7NHcbFQq (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Sun, 23 Aug 2020 19:38:37 +0200 (CEST) From: Bruno Haible To: bug-gnulib@gnu.org Subject: supersede: Avoid a failure when writing to /dev/null in Solaris zones Date: Sun, 23 Aug 2020 19:38:36 +0200 Message-ID: <1852871.mQFH9W2BVG@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-186-generic; KDE/5.18.0; x86_64; ; ) MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Received-SPF: none client-ip=81.169.146.219; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/23 13:38:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?ISO-8859-1?Q?J=F6rg?= Sonnenberger , Thomas Klausner Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" J=F6rg Sonnenberger noticed that the new gnulib module 'supersede', when writing to /dev/null in Solaris/Illumos zones, fails [1][2]. Per POSIX [3], open ("/dev/null", O_TRUNC | O_WRONLY) and open ("/dev/null", O_CREAT | O_TRUNC | O_WRONLY) should be equivalent. But in Solaris/Illumos zones, the second form is need= ed because the first one fails with EINVAL. Should we extend the 'open' module to cover this bug? Probably overkill, especially since I can't see how we could test for it in an autoconf test. Here's a workaround, specifically in the 'supersede' module. [1] https://www.illumos.org/issues/13035 [2] https://pkgsrc.se/files.php?messageId=3D20200812233110.30230FB28@cvs.Ne= tBSD.org [3] https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/= open.html 2020-08-23 Bruno Haible supersede: Avoid a failure when writing to /dev/null in Solaris zones. Reported by J=F6rg Sonnenberger via Thomas Klausner in . * lib/supersede.c (open_supersede): When opening an existing non-regular file on Solaris, use O_CREAT although it should not be necessary. diff --git a/lib/supersede.c b/lib/supersede.c index 92317f2..a03cc6d 100644 =2D-- a/lib/supersede.c +++ b/lib/supersede.c @@ -78,6 +78,16 @@ open_supersede (const char *filename, int flags, mode_t = mode, struct supersede_final_action *action) { int fd; + /* Extra flags for existing devices. */ + int extra_flags =3D + #if defined __sun + /* open ("/dev/null", O_TRUNC | O_WRONLY) fails with error EINVAL on S= olaris + zones. See . As a workaroun= d, add + the O_CREAT flag, although it ought not to be necessary. */ + O_CREAT; + #else + 0; + #endif =20 if (supersede_if_exists) { @@ -89,7 +99,7 @@ open_supersede (const char *filename, int flags, mode_t m= ode, && ! S_ISREG (statbuf.st_mode) /* The file exists and is possibly a character device, socke= t, or something like that. */ =2D && ((fd =3D open (filename, flags, mode)) >=3D 0 + && ((fd =3D open (filename, flags | extra_flags, mode)) >=3D= 0 || errno !=3D ENOENT)) { if (fd >=3D 0) @@ -167,7 +177,7 @@ open_supersede (const char *filename, int flags, mode_t= mode, { /* It is possibly a character device, socket, or something like that. */ =2D fd =3D open (canon_filename, flags, mode); + fd =3D open (canon_filename, flags | extra_flags= , mode); if (fd >=3D 0) { free (canon_filename); @@ -197,6 +207,28 @@ open_supersede (const char *filename, int flags, mode_= t mode, action->final_rename_temp =3D NULL; action->final_rename_dest =3D NULL; } + #if defined __sun + /* Work around . */ + else if (errno =3D=3D EINVAL) + { + struct stat statbuf; + + if (stat (filename, &statbuf) >=3D 0 + && ! S_ISREG (statbuf.st_mode)) + { + /* The file exists and is possibly a character device, s= ocket, + or something like that. As a workaround, add the O_C= REAT + flag, although it ought not to be necessary.*/ + fd =3D open (filename, flags | extra_flags, mode); + if (fd >=3D 0) + { + /* The file exists. */ + action->final_rename_temp =3D NULL; + action->final_rename_dest =3D NULL; + } + } + } + #endif else if (errno =3D=3D ENOENT) { /* The file does not exist. Use a temporary file. */