Commit 70743157 authored by Paul Eggert's avatar Paul Eggert

FILE's lock is now always .#FILE and may be a regular file.

* etc/NEWS: Document this.
* nt/inc/unistd.h (O_NOFOLLOW): New macro.
* src/filelock.c: Include <c-ctype.h>.
(MAX_LFINFO): New top-level constant.
(lock_info_type): Remove members pid, boot_time.  Add members at,
dot, colon.  Change user member to be the entire buffer, not a
pointer.  This allows us to handle the case where a foreign
pid or boot time exceeds the local range.  All uses changed.
(LINKS_MIGHT_NOT_WORK): New constant.
(FREE_LOCK_INFO): Remove, as the pieces no longer need freeing.
(defined_WINDOWSNT): Remove.
(MAKE_LOCK_NAME, file_in_lock_file_name):
Always use .#FILE (not .#-FILE) for the file lock,
even if it is a regular file.
(rename_lock_file): New function.
(create_lock_file): Use it.
(create_lock_file, read_lock_data):
Prefer a symbolic link for the lock file, falling back on a
regular file if symlinks don't work.  Do not try to create
symlinks on MS-Windows, due to security hassles.  Stick with
POSIXish functions (open, read, write, close, fchmod, readlink, symlink,
link, rename, unlink, mkstemp) when creating locks, as a GNUish
host may be using a Windowsish file system, and cannot use
MS-Windows-only system calls.  Fall back on mktemp if mkstemp
doesn't work.  Don't fail merely because of a symlink-contents
length limit in the current file system; fall back on regular
files.  Increase the symlink contents length limit to 8 KiB, this
should be big enough for any real use and doesn't crunch the
stack.
(create_lock_file, lock_file_1, read_lock_data):
Simplify allocation of lock file buffers now that they fit in 8 KiB.
(lock_file_1): Return error number, not bool.  All callers changed.
(ELOOP): New macro, if not already defined.
(read_lock_data): Return size of lock file contents, not Lisp object.
All callers changed.  Handle a race condition if some other process
replaces a regular-file lock with a symlink lock or vice versa,
while we're trying to read the lock.
(current_lock_owner): Parse contents more carefully, to help avoid
confusing a regular-file lock with some other application's use
of the file.  Check for lock file contents being too long, or
not parsing correctly.
(current_lock_owner, lock_file):
Allow foreign pid and boot times that exceed the local range.
(current_lock_owner, lock_if_free, lock_file):
Simplify allocation of lock file contents.
* src/w32.c (sys_rename_replace): New function, containing most of
the contents of the old sys_rename.
(sys_rename): Use it.
(fchmod): New dummy function.
* src/w32.h (sys_rename_replace, fchmod): New decls.

Fixes: debbugs:13807
parent 05e193f1
......@@ -594,7 +594,8 @@ else
test "x$NON_GCC_TEST_OPTIONS" != x && CC="$CC $NON_GCC_TEST_OPTIONS"
fi
# Avoid gnulib's tests for O_NOATIME and O_NOFOLLOW, as we don't use them.
# Avoid gnulib's tests for HAVE_WORKING_O_NOATIME and HAVE_WORKING_O_NOFOLLOW,
# as we don't use them.
AC_DEFUN([gl_FCNTL_O_FLAGS])
# Avoid gnulib's threadlib module, as we do threads our own way.
AC_DEFUN([gl_THREADLIB])
......
2013-03-05 Paul Eggert <eggert@cs.ucla.edu>
FILE's lock is now always .#FILE and may be a regular file (Bug#13807).
* NEWS: Document this.
2013-03-02 Bill Wohler <wohler@newt.com>
Release MH-E version 8.5.
......
......@@ -320,7 +320,7 @@ text-property on the first char.
** The `defalias-fset-function' property lets you catch calls to defalias
and redirect them to your own function instead of `fset'.
** The lock for 'DIR/FILE' is now 'DIR/.#FILE' or 'DIR/.#-FILE'.
** The lock for 'DIR/FILE' is now 'DIR/.#FILE' and may be a regular file.
When you edit DIR/FILE, Emacs normally creates a symbolic link
DIR/.#FILE as a lock that warns other instances of Emacs that DIR/FILE
is being edited. Formerly, if there was already a non-symlink file
......@@ -328,9 +328,8 @@ named DIR/.#FILE, Emacs fell back on the lock names DIR/.#FILE.0
through DIR/.#FILE.9. These fallbacks have been removed, so that
Emacs now no longer locks DIR/FILE in that case.
On MS-Windows the lock is a regular file DIR/.#-FILE, not a symlink.
MS-Windows and non-MS-Windows implementations of Emacs ignore each
other's locks.
On file systems that do not support symbolic links, the lock is now a
regular file with contents being what would have been in the symlink.
** The 9th element returned by `file-attributes' is now unspecified.
Formerly, it was t if the file's gid would change if file were deleted
......
2013-03-05 Paul Eggert <eggert@cs.ucla.edu>
FILE's lock is now always .#FILE and may be a regular file (Bug#13807).
* inc/unistd.h (O_NOFOLLOW): New macro.
2013-03-04 Juanma Barranquero <lekktu@gmail.com>
* config.nt: Sync with autogen/config.in.
......
......@@ -27,8 +27,9 @@ extern int faccessat (int, char const *, int, int);
#define AT_EACCESS 4
#define AT_SYMLINK_NOFOLLOW 4096
#define O_NOCTTY 0
#define O_IGNORE_CTTY 0
#define O_NOCTTY 0
#define O_NOFOLLOW 0
/* This is normally on stdlib.h, but we don't override that header. */
extern int unsetenv (const char *);
......
2013-03-05 Paul Eggert <eggert@cs.ucla.edu>
FILE's lock is now always .#FILE and may be a regular file (Bug#13807).
* filelock.c: Include <c-ctype.h>.
(MAX_LFINFO): New top-level constant.
(lock_info_type): Remove members pid, boot_time. Add members at,
dot, colon. Change user member to be the entire buffer, not a
pointer. This allows us to handle the case where a foreign
pid or boot time exceeds the local range. All uses changed.
(LINKS_MIGHT_NOT_WORK): New constant.
(FREE_LOCK_INFO): Remove, as the pieces no longer need freeing.
(defined_WINDOWSNT): Remove.
(MAKE_LOCK_NAME, file_in_lock_file_name):
Always use .#FILE (not .#-FILE) for the file lock,
even if it is a regular file.
(rename_lock_file): New function.
(create_lock_file): Use it.
(create_lock_file, read_lock_data):
Prefer a symbolic link for the lock file, falling back on a
regular file if symlinks don't work. Do not try to create
symlinks on MS-Windows, due to security hassles. Stick with
POSIXish functions (open, read, write, close, fchmod, readlink, symlink,
link, rename, unlink, mkstemp) when creating locks, as a GNUish
host may be using a Windowsish file system, and cannot use
MS-Windows-only system calls. Fall back on mktemp if mkstemp
doesn't work. Don't fail merely because of a symlink-contents
length limit in the current file system; fall back on regular
files. Increase the symlink contents length limit to 8 KiB, this
should be big enough for any real use and doesn't crunch the
stack.
(create_lock_file, lock_file_1, read_lock_data):
Simplify allocation of lock file buffers now that they fit in 8 KiB.
(lock_file_1): Return error number, not bool. All callers changed.
(ELOOP): New macro, if not already defined.
(read_lock_data): Return size of lock file contents, not Lisp object.
All callers changed. Handle a race condition if some other process
replaces a regular-file lock with a symlink lock or vice versa,
while we're trying to read the lock.
(current_lock_owner): Parse contents more carefully, to help avoid
confusing a regular-file lock with some other application's use
of the file. Check for lock file contents being too long, or
not parsing correctly.
(current_lock_owner, lock_file):
Allow foreign pid and boot times that exceed the local range.
(current_lock_owner, lock_if_free, lock_file):
Simplify allocation of lock file contents.
* w32.c (sys_rename_replace): New function, containing most of
the contents of the old sys_rename.
(sys_rename): Use it.
(fchmod): New dummy function.
* w32.h (sys_rename_replace, fchmod): New decls.
2013-03-05 Eli Zaretskii <eliz@gnu.org>
* bidi.c (bidi_resolve_explicit_1): Don't call CHAR_TO_BYTE or
......
This diff is collapsed.
......@@ -3416,7 +3416,13 @@ sys_open (const char * path, int oflag, int mode)
}
int
sys_rename (const char * oldname, const char * newname)
fchmod (int fd, mode_t mode)
{
return 0;
}
int
sys_rename_replace (const char *oldname, const char *newname, BOOL force)
{
BOOL result;
char temp[MAX_PATH];
......@@ -3472,7 +3478,7 @@ sys_rename (const char * oldname, const char * newname)
return -1;
}
/* Emulate Unix behavior - newname is deleted if it already exists
/* If FORCE, emulate Unix behavior - newname is deleted if it already exists
(at least if it is a file; don't do this for directories).
Since we mustn't do this if we are just changing the case of the
......@@ -3490,7 +3496,7 @@ sys_rename (const char * oldname, const char * newname)
result = rename (temp, newname);
if (result < 0)
if (result < 0 && force)
{
DWORD w32err = GetLastError ();
......@@ -3529,6 +3535,12 @@ sys_rename (const char * oldname, const char * newname)
return result;
}
int
sys_rename (char const *old, char const *new)
{
return sys_rename_replace (old, new, TRUE);
}
int
sys_rmdir (const char * path)
{
......
......@@ -186,6 +186,8 @@ extern BOOL init_winsock (int load_now);
extern void srandom (int);
extern int random (void);
extern int fchmod (int, mode_t);
extern int sys_rename_replace (char const *, char const *, BOOL);
extern int sys_pipe (int *);
extern void set_process_dir (char *);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment