nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 747ce3b5dad2a8bdd4f763d7827f307aadbed2b6
parent 10800ee410286c3f19ffa7fd563fe0cf08e3a68a
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Wed, 20 May 2020 16:53:19 +0200

tweaks: don't bother statting the lock file before unlinking it

If unlinking would fail because the parent directory is unwritable,
then a check in has_valid_path() would have prevented do_lockfile()
from being called at all.

Diffstat:
Msrc/files.c | 10++++------
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/files.c b/src/files.c @@ -128,7 +128,6 @@ bool write_lockfile(const char *lockfilename, const char *filename, bool modifie uid_t myuid = geteuid(); struct passwd *mypwuid = getpwuid(myuid); char myhostname[32]; - struct stat fileinfo; int fd; FILE *filestream; char *lockdata; @@ -146,12 +145,11 @@ bool write_lockfile(const char *lockfilename, const char *filename, bool modifie } else myhostname[31] = '\0'; - /* If the lockfile exists, try to delete it. */ - if (stat(lockfilename, &fileinfo) != -1) - if (!delete_lockfile(lockfilename)) - return FALSE; + /* First make sure to remove an existing lock file. */ + if (!delete_lockfile(lockfilename)) + return FALSE; - /* Create the lockfile -- do not accept an existing one. */ + /* Create the lock file -- do not accept an existing one. */ fd = open(lockfilename, O_WRONLY|O_CREAT|O_EXCL, RW_FOR_ALL); if (fd > 0)