Avoid dead locks at login after reboot

OBS-URL: https://build.opensuse.org/package/show/shells/tcsh?expand=0&rev=97
This commit is contained in:
Dr. Werner Fink 2020-02-17 11:23:13 +00:00 committed by Git OBS Bridge
parent ed3166724e
commit 3777c45560
3 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,82 @@
Avoid left over dot lock file after reboot
---
dotlock.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
--- dotlock.c
+++ dotlock.c 2020-02-17 11:16:22.785018224 +0000
@@ -30,8 +30,38 @@
#define O_SYNC 0
#endif
+#if defined(__linux__)
+# include <sys/statfs.h>
+# include <unistd.h>
+# ifndef TMPFS_MAGIC
+# define TMPFS_MAGIC 0x01021994
+# endif
+#endif
+
#include "dotlock.h"
+#if defined(__linux__)
+static char *sys_tmpdir;
+static int
+dosys_tmpdir ()
+{
+ static char *shm = "/dev/shm";
+ struct statfs fs;
+ static int doshm;
+
+ if (doshm)
+ return (sys_tmpdir != NULL);
+
+ doshm++;
+
+ if (statfs(shm, &fs) < 0 || fs.f_type != TMPFS_MAGIC || eaccess(shm, W_OK|X_OK))
+ return 0;
+
+ sys_tmpdir = shm;
+ return 1;
+}
+#endif
+
static int create_exclusive(const char *);
/*
* Create a unique file. O_EXCL does not really work over NFS so we follow
@@ -140,7 +170,17 @@ dot_lock(const char *fname, int pollinte
(void)sigaddset(&nset, SIGTSTP);
(void)sigaddset(&nset, SIGCHLD);
+#if defined(__linux__)
+ const char *ptr;
+ if ((ptr = strrchr(fname, '/')) && dosys_tmpdir()) {
+ ptr++;
+ fname = ptr;
+ (void)snprintf(path, sizeof(path), "%s/%s.lock", sys_tmpdir, fname);
+ } else
+ (void)snprintf(path, sizeof(path), "%s.lock", fname);
+#else
(void)snprintf(path, sizeof(path), "%s.lock", fname);
+#endif
retval = -1;
for (;;) {
@@ -174,6 +214,16 @@ dot_unlock(const char *fname)
{
char path[MAXPATHLEN];
+#if defined(__linux__)
+ const char *ptr;
+ if ((ptr = strrchr(fname, '/')) && dosys_tmpdir()) {
+ ptr++;
+ fname = ptr;
+ (void)snprintf(path, sizeof(path), "%s/%s.lock", sys_tmpdir, fname);
+ } else
+ (void)snprintf(path, sizeof(path), "%s.lock", fname);
+#else
(void)snprintf(path, sizeof(path), "%s.lock", fname);
+#endif
(void)unlink(path);
}

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Mon Feb 17 11:19:42 UTC 2020 - Dr. Werner Fink <werner@suse.de>
- Add temporary patch tcsh-6.22.02-local-dotlock.dif to avoid
dead locks at login after a reboot to left dof locking files
-------------------------------------------------------------------
Wed Jan 8 12:06:46 UTC 2020 - Dr. Werner Fink <werner@suse.de>

View File

@ -33,6 +33,7 @@ Patch4: tcsh-6.18.03-colorls.dif
Patch5: tcsh-6.17.06-dspmbyte.dif
Patch6: tcsh-6.18.03-catalogs.dif
Patch7: tcsh-6.22.02-workaround-common.patch
Patch8: tcsh-6.22.02-local-dotlock.dif
BuildRequires: autoconf
BuildRequires: fdupes
BuildRequires: ncurses-devel
@ -59,6 +60,7 @@ correction, a history mechanism, job control, and a C-like syntax.
%patch5 -b .dspmbyte
%patch6 -b .catalogs
%patch7 -p 1 -b .workaround
%patch8 -p 0 -b .dotlock
%patch0 -b .0
%build