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.
master
Benno Schulenberg 2020-05-20 16:53:19 +02:00
parent 10800ee410
commit 747ce3b5da
1 changed files with 4 additions and 6 deletions

View File

@ -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)