# HG changeset patch # User Mikael Berthe # Date 1404634830 -7200 # Node ID 361603828d9ef1afee7016a75538d00d520ffd26 # Parent fc7a758ebbde19834eae7660e387958cca439836 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. diff -r fc7a758ebbde -r 361603828d9e mcabber/mcabber/utils.c --- 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);