tweaks: reshuffle a few declarations and assignments
Also reshuffle two fragments of code.master
parent
1d52548575
commit
3ac5432e29
30
src/files.c
30
src/files.c
|
@ -148,33 +148,28 @@ bool delete_lockfile(const char *lockfilename)
|
||||||
bool write_lockfile(const char *lockfilename, const char *filename, bool modified)
|
bool write_lockfile(const char *lockfilename, const char *filename, bool modified)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_PWD_H
|
#ifdef HAVE_PWD_H
|
||||||
|
pid_t mypid = getpid();
|
||||||
|
uid_t myuid = geteuid();
|
||||||
|
struct passwd *mypwuid = getpwuid(myuid);
|
||||||
|
char myhostname[32];
|
||||||
|
struct stat fileinfo;
|
||||||
int cflags, fd;
|
int cflags, fd;
|
||||||
FILE *filestream;
|
FILE *filestream;
|
||||||
pid_t mypid;
|
|
||||||
uid_t myuid;
|
|
||||||
struct passwd *mypwuid;
|
|
||||||
struct stat fileinfo;
|
|
||||||
char *lockdata;
|
char *lockdata;
|
||||||
char myhostname[32];
|
|
||||||
size_t wroteamt;
|
size_t wroteamt;
|
||||||
|
|
||||||
mypid = getpid();
|
if (mypwuid == NULL) {
|
||||||
myuid = geteuid();
|
|
||||||
|
|
||||||
/* First run things that might fail before blowing away the old state. */
|
|
||||||
if ((mypwuid = getpwuid(myuid)) == NULL) {
|
|
||||||
/* TRANSLATORS: Keep the next eight messages at most 76 characters. */
|
/* TRANSLATORS: Keep the next eight messages at most 76 characters. */
|
||||||
statusline(MILD, _("Couldn't determine my identity for lock file"));
|
statusline(MILD, _("Couldn't determine my identity for lock file"));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gethostname(myhostname, 31) < 0) {
|
if (gethostname(myhostname, 31) < 0) {
|
||||||
if (errno == ENAMETOOLONG)
|
if (errno != ENAMETOOLONG) {
|
||||||
myhostname[31] = '\0';
|
|
||||||
else {
|
|
||||||
statusline(MILD, _("Couldn't determine hostname: %s"), strerror(errno));
|
statusline(MILD, _("Couldn't determine hostname: %s"), strerror(errno));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
} else
|
||||||
|
myhostname[31] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the lockfile exists, try to delete it. */
|
/* If the lockfile exists, try to delete it. */
|
||||||
|
@ -190,6 +185,7 @@ bool write_lockfile(const char *lockfilename, const char *filename, bool modifie
|
||||||
/* Try to create the lockfile. */
|
/* Try to create the lockfile. */
|
||||||
fd = open(lockfilename, cflags,
|
fd = open(lockfilename, cflags,
|
||||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
statusline(MILD, _("Error writing lock file %s: %s"),
|
statusline(MILD, _("Error writing lock file %s: %s"),
|
||||||
lockfilename, strerror(errno));
|
lockfilename, strerror(errno));
|
||||||
|
@ -245,8 +241,6 @@ bool write_lockfile(const char *lockfilename, const char *filename, bool modifie
|
||||||
lockfilename, strerror(errno));
|
lockfilename, strerror(errno));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
openfile->lock_filename = (char *)lockfilename;
|
|
||||||
#endif
|
#endif
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -348,8 +342,10 @@ int do_lockfile(const char *filename, bool ask_the_user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write_lockfile(lockfilename, filename, FALSE))
|
if (write_lockfile(lockfilename, filename, FALSE)) {
|
||||||
|
openfile->lock_filename = lockfilename;
|
||||||
retval = 1;
|
retval = 1;
|
||||||
|
}
|
||||||
|
|
||||||
free_the_name:
|
free_the_name:
|
||||||
if (retval < 1)
|
if (retval < 1)
|
||||||
|
|
Loading…
Reference in New Issue