unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Po Lu <luangruo@yahoo.com>, 53136@debbugs.gnu.org
Subject: bug#53136: 28.0.90; segfault in lock_file
Date: Mon, 10 Jan 2022 15:11:04 -0800	[thread overview]
Message-ID: <37cd3017-38cb-fa2c-7b52-fbeb3b085744@cs.ucla.edu> (raw)
In-Reply-To: <8335lxazg6.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 997 bytes --]

On 1/9/22 04:03, Eli Zaretskii wrote:

> Paul, could you please take a look?

The problem (as Po deduced) seems to be that Haiku errno values are 
negative by default.

However, I see some problems with the recently installed fix.

1. It uses BE_USE_POSITIVE_POSIX_ERRORS but Haiku spells it 
B_USE_POSITIVE_POSIX_ERRORS.

2. There's no need to replace "if (err < 0)" with "if (err == -1 || err 
== -2)", as this replacement is not needed given the "#if !defined HAIKU 
..." stuff.

3. More importantly, I'm sure there are other places where Emacs assumes 
that errno values are positive. I doubt whether it's reasonable to 
expect Emacs developers to remember and work around this Haiku 
incompatibility, every time they call a function that sets errno or 
returns an errno value. Instead, we should arrange for Haiku builds to 
use positive errno values, they way errno behaves on GNU and other 
POSIX-compatible hosts. This should be a much more maintainable solution.

Proposed patch attached.

[-- Attachment #2: 0001-Improve-port-to-Haiku-errno-values.patch --]
[-- Type: text/x-patch, Size: 1746 bytes --]

From 026aef868ad242c3ccaf0d542ab81b621a26e0a9 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 10 Jan 2022 15:07:51 -0800
Subject: [PATCH] Improve port to Haiku errno values

* configure.ac (B_USE_POSITIVE_POSIX_ERRORS): Define on Haiku.
* src/filelock.c (lock_if_free): Revert recent changes, since
defining B_USE_POSITIVE_POSIX_ERRORS should fix the general problem.
---
 configure.ac   | 2 ++
 src/filelock.c | 9 +--------
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/configure.ac b/configure.ac
index baf8c8018e..c5d97890c7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5672,6 +5672,8 @@ AC_DEFUN
 
   haiku)
     AC_DEFINE(HAIKU, [], [Define if the system is Haiku.])
+    AC_DEFINE([B_USE_POSITIVE_POSIX_ERRORS], [],
+      [Define to cause Haiku to use POSIX-compatible errno values.])
     ;;
 esac
 
diff --git a/src/filelock.c b/src/filelock.c
index c3927f58fa..a213c2b3ca 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -608,7 +608,7 @@ lock_if_free (lock_info_type *clasher, char *lfname)
       err = current_lock_owner (clasher, lfname);
       if (err != 0)
 	{
-	  if (err == -1 || err == -2)
+	  if (err < 0)
 	    return -2 - err; /* We locked it, or someone else has it.  */
 	  break; /* current_lock_owner returned strange error.  */
 	}
@@ -616,14 +616,7 @@ lock_if_free (lock_info_type *clasher, char *lfname)
       /* We deleted a stale lock; try again to lock the file.  */
     }
 
-#if !defined HAIKU \
-  || defined BE_USE_POSITIVE_POSIX_ERRORS
   return err;
-#else
-  /* On Haiku, POSIX errno values are negative by default, but this
-     code's callers assume that all errno values are positive.  */
-  return -err;
-#endif
 }
 
 static Lisp_Object
-- 
2.32.0


  reply	other threads:[~2022-01-10 23:11 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <871r1hv40o.fsf.ref@yahoo.com>
2022-01-09  6:04 ` bug#53136: 28.0.90; segfault in lock_file Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-09  7:36   ` Eli Zaretskii
2022-01-09  8:10     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-09  8:42       ` Eli Zaretskii
2022-01-09  9:40         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-09 11:43         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-09 12:03           ` Eli Zaretskii
2022-01-10 23:11             ` Paul Eggert [this message]
2022-01-10 23:30               ` Paul Eggert
2022-01-11  0:51                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-11  0:51               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-11  1:05                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-12  2:59                   ` Paul Eggert
2022-01-12  3:04                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-12 19:22                       ` Paul Eggert
2022-01-11 12:45                 ` Eli Zaretskii
2022-01-11 13:16                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-11 17:05                     ` Paul Eggert
2022-01-12  0:35                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-11  0:58               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-11 12:30               ` Eli Zaretskii
2022-01-09 12:56           ` Eli Zaretskii
2022-01-09 13:00             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-09 13:10               ` Eli Zaretskii
2022-01-09 13:16                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-09 13:23                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-09 13:30                     ` Eli Zaretskii
2022-01-09 13:47                     ` Andreas Schwab
2022-01-10  0:29                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=37cd3017-38cb-fa2c-7b52-fbeb3b085744@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=53136@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=luangruo@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).