Set the trace log file permissions again when we write to it
If the log file is recreated (e.g. log rotation) the new file will have
correct permissions.
--- a/mcabber/mcabber/utils.c Sun Jul 06 10:00:20 2014 +0200
+++ b/mcabber/mcabber/utils.c Sun Jul 06 10:20:30 2014 +0200
@@ -187,7 +187,7 @@
fp = fopen(FName, "a");
if (!fp) {
- scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot open tracelog file: %s!",
+ scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot open tracelog file: %s",
strerror(errno));
return FALSE;
}
@@ -196,13 +196,17 @@
if (err || buf.st_uid != geteuid()) {
fclose(fp);
if (err)
- scr_LogPrint(LPRINT_NORMAL, "ERROR: cannot stat the tracelog file: %s!",
+ scr_LogPrint(LPRINT_NORMAL, "ERROR: cannot stat the tracelog file: %s",
strerror(errno));
else
scr_LogPrint(LPRINT_NORMAL, "ERROR: tracelog file does not belong to you!");
return FALSE;
}
- fchmod(fileno(fp), S_IRUSR|S_IWUSR);
+
+ if (fchmod(fileno(fp), S_IRUSR|S_IWUSR)) {
+ scr_LogPrint(LPRINT_NORMAL, "WARNING: Cannot set tracelog file permissions: %s",
+ strerror(errno));
+ }
v = mcabber_version();
fprintf(fp, "New trace log started. MCabber version %s\n"
@@ -268,6 +272,10 @@
strerror(errno));
return;
}
+
+ // Check file permissions again (it could be a new file)
+ fchmod(fileno(fp), S_IRUSR|S_IWUSR);
+
if (fputs(data, fp) == EOF)
scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot write to tracelog file.");
fclose(fp);