bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] retry opening startup files on EINTR


From: Grisha Levit
Subject: [PATCH] retry opening startup files on EINTR
Date: Wed, 7 Feb 2024 01:33:42 -0500

I have some dotfiles symlinked to storage backed by a macOS File
Provider extension (e.g. Dropbox):

    $ realpath ~/.bash_profile
    /Users/levit/Library/CloudStorage/Dropbox/profile/.bash_profile

This normally works fine, except when my terminal emulator (tested
both Terminal.app and iTerm) restores sessions after being restarted
-- opening the startup file fails in about half of the restored
sessions, which ends up looking like:

    [Restored Feb 7, 2024 at 00:11:37]
    Last login: Wed Feb  7 00:11:37 on ttys008
    Restored session: Wed Feb  7 00:11:27 EST 2024
    -bash: /Users/levit/.bash_profile: Interrupted system call
    mbp:~ levit$

If I remove ~/.bash_profile, and make ~/.inputrc and ~/.bash_history
similar symlinks, I see the same issue with loading them (without an
error message).

I'm not sure what the underlying cause is here, but maybe it would be
appropriate to retry open(2) calls for these files if they fail with
EINTR?

diff --git a/bashhist.c b/bashhist.c
index 9e762057..aeaa5234 100644
--- a/bashhist.c
+++ b/bashhist.c
@@ -336,7 +336,8 @@ load_history (void)

   if (hf && *hf && file_exists (hf))
     {
-      read_history (hf);
+      while (read_history (hf) == EINTR)
+       QUIT;
       /* We have read all of the lines from the history file, even if we
         read more lines than $HISTSIZE.  Remember the total number of lines
         we read so we don't count the last N lines as new over and over
diff --git a/builtins/evalfile.c b/builtins/evalfile.c
index 6a242bda..60adca34 100644
--- a/builtins/evalfile.c
+++ b/builtins/evalfile.c
@@ -106,7 +106,8 @@ _evalfile (const char *filename, int flags)
 #  endif
 #endif

-  fd = open (filename, O_RDONLY);
+  while ((fd = open (filename, O_RDONLY)) < 0 && errno == EINTR)
+    QUIT;

   if (fd < 0 || (fstat (fd, &finfo) == -1))
     {
diff --git a/lib/readline/bind.c b/lib/readline/bind.c
index 47478f08..44787cfe 100644
--- a/lib/readline/bind.c
+++ b/lib/readline/bind.c
@@ -968,8 +968,10 @@ _rl_read_file (char *filename, size_t *sizep)
   char *buffer;
   int i, file;

-  file = -1;
-  if (((file = open (filename, O_RDONLY, 0666)) < 0) || (fstat (file,
&finfo) < 0))
+  while ((file = open (filename, O_RDONLY, 0666)) < 0 && errno == EINTR)
+    RL_CHECK_SIGNALS ();
+
+  if ((file < 0) || (fstat (file, &finfo) < 0))
     {
       if (file >= 0)
        close (file);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]