Commit bc33539b authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

files: upgrade the locking errors, so they will not be overwritten

Make the failures to read or write a lock file into important messages,
so they will not be overwritten by the number of lines read.
No related merge requests found
Showing with 12 additions and 11 deletions
+12 -11
...@@ -145,7 +145,7 @@ void set_modified(void) ...@@ -145,7 +145,7 @@ void set_modified(void)
if (openfile->lock_filename == NULL) { if (openfile->lock_filename == NULL) {
/* TRANSLATORS: Keep the next two messages at most 76 characters. */ /* TRANSLATORS: Keep the next two messages at most 76 characters. */
statusbar(_("Warning: Modifying a file which is not locked," statusline(ALERT, _("Warning: Modifying a file which is not locked,"
" check directory permission?")); " check directory permission?"));
} else { } else {
char *fullname = get_full_path(openfile->filename); char *fullname = get_full_path(openfile->filename);
...@@ -184,7 +184,8 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi ...@@ -184,7 +184,8 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
* old state. */ * old state. */
myuid = geteuid(); myuid = geteuid();
if ((mypwuid = getpwuid(myuid)) == NULL) { if ((mypwuid = getpwuid(myuid)) == NULL) {
statusbar(_("Couldn't determine my identity for lock file (getpwuid() failed)")); statusline(ALERT, _("Couldn't determine my identity for lock file "
"(getpwuid() failed)"));
goto free_and_fail; goto free_and_fail;
} }
mypid = getpid(); mypid = getpid();
...@@ -193,7 +194,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi ...@@ -193,7 +194,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
if (errno == ENAMETOOLONG) if (errno == ENAMETOOLONG)
myhostname[31] = '\0'; myhostname[31] = '\0';
else { else {
statusline(HUSH, _("Couldn't determine hostname for lock file: %s"), statusline(ALERT, _("Couldn't determine hostname for lock file: %s"),
strerror(errno)); strerror(errno));
goto free_and_fail; goto free_and_fail;
} }
...@@ -215,7 +216,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi ...@@ -215,7 +216,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
/* Maybe we just don't have write access. Print an error message /* Maybe we just don't have write access. Print an error message
* and continue. */ * and continue. */
if (fd < 0) { if (fd < 0) {
statusline(HUSH, _("Error writing lock file %s: %s"), statusline(ALERT, _("Error writing lock file %s: %s"),
lockfilename, strerror(errno)); lockfilename, strerror(errno));
free(lockdata); free(lockdata);
return 0; return 0;
...@@ -226,8 +227,8 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi ...@@ -226,8 +227,8 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
filestream = fdopen(fd, "wb"); filestream = fdopen(fd, "wb");
if (fd < 0 || filestream == NULL) { if (fd < 0 || filestream == NULL) {
statusline(HUSH, _("Error writing lock file %s: %s"), lockfilename, statusline(ALERT, _("Error writing lock file %s: %s"), lockfilename,
strerror(errno)); strerror(errno));
goto free_and_fail; goto free_and_fail;
} }
...@@ -263,7 +264,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi ...@@ -263,7 +264,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
wroteamt = fwrite(lockdata, sizeof(char), lockdatalen, filestream); wroteamt = fwrite(lockdata, sizeof(char), lockdatalen, filestream);
if (wroteamt < lockdatalen) { if (wroteamt < lockdatalen) {
statusline(HUSH, _("Error writing lock file %s: %s"), statusline(ALERT, _("Error writing lock file %s: %s"),
lockfilename, ferror(filestream)); lockfilename, ferror(filestream));
goto free_and_fail; goto free_and_fail;
} }
...@@ -273,7 +274,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi ...@@ -273,7 +274,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
#endif #endif
if (fclose(filestream) == EOF) { if (fclose(filestream) == EOF) {
statusline(HUSH, _("Error writing lock file %s: %s"), statusline(ALERT, _("Error writing lock file %s: %s"),
lockfilename, strerror(errno)); lockfilename, strerror(errno));
goto free_and_fail; goto free_and_fail;
} }
...@@ -293,7 +294,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi ...@@ -293,7 +294,7 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
int delete_lockfile(const char *lockfilename) int delete_lockfile(const char *lockfilename)
{ {
if (unlink(lockfilename) < 0 && errno != ENOENT) { if (unlink(lockfilename) < 0 && errno != ENOENT) {
statusline(HUSH, _("Error deleting lock file %s: %s"), lockfilename, statusline(ALERT, _("Error deleting lock file %s: %s"), lockfilename,
strerror(errno)); strerror(errno));
return -1; return -1;
} }
...@@ -328,7 +329,7 @@ int do_lockfile(const char *filename) ...@@ -328,7 +329,7 @@ int do_lockfile(const char *filename)
int room, ans; int room, ans;
if ((lockfd = open(lockfilename, O_RDONLY)) < 0) { if ((lockfd = open(lockfilename, O_RDONLY)) < 0) {
statusline(HUSH, _("Error opening lock file %s: %s"), statusline(ALERT, _("Error opening lock file %s: %s"),
lockfilename, strerror(errno)); lockfilename, strerror(errno));
goto free_the_name; goto free_the_name;
} }
...@@ -340,7 +341,7 @@ int do_lockfile(const char *filename) ...@@ -340,7 +341,7 @@ int do_lockfile(const char *filename)
} while (readamt > 0 && readtot < LOCKBUFSIZE); } while (readamt > 0 && readtot < LOCKBUFSIZE);
if (readtot < 48) { if (readtot < 48) {
statusline(HUSH, _("Error reading lock file %s: " statusline(ALERT, _("Error reading lock file %s: "
"Not enough data read"), lockfilename); "Not enough data read"), lockfilename);
free(lockbuf); free(lockbuf);
goto free_the_name; goto free_the_name;
......
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