Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/utils.c @ 2135:361603828d9e
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.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 06 Jul 2014 10:20:30 +0200 |
parents | fc7a758ebbde |
children | 87244845fd9c |
comparison
equal
deleted
inserted
replaced
2134:fc7a758ebbde | 2135:361603828d9e |
---|---|
185 int err; | 185 int err; |
186 char *v; | 186 char *v; |
187 | 187 |
188 fp = fopen(FName, "a"); | 188 fp = fopen(FName, "a"); |
189 if (!fp) { | 189 if (!fp) { |
190 scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot open tracelog file: %s!", | 190 scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot open tracelog file: %s", |
191 strerror(errno)); | 191 strerror(errno)); |
192 return FALSE; | 192 return FALSE; |
193 } | 193 } |
194 | 194 |
195 err = fstat(fileno(fp), &buf); | 195 err = fstat(fileno(fp), &buf); |
196 if (err || buf.st_uid != geteuid()) { | 196 if (err || buf.st_uid != geteuid()) { |
197 fclose(fp); | 197 fclose(fp); |
198 if (err) | 198 if (err) |
199 scr_LogPrint(LPRINT_NORMAL, "ERROR: cannot stat the tracelog file: %s!", | 199 scr_LogPrint(LPRINT_NORMAL, "ERROR: cannot stat the tracelog file: %s", |
200 strerror(errno)); | 200 strerror(errno)); |
201 else | 201 else |
202 scr_LogPrint(LPRINT_NORMAL, "ERROR: tracelog file does not belong to you!"); | 202 scr_LogPrint(LPRINT_NORMAL, "ERROR: tracelog file does not belong to you!"); |
203 return FALSE; | 203 return FALSE; |
204 } | 204 } |
205 fchmod(fileno(fp), S_IRUSR|S_IWUSR); | 205 |
206 if (fchmod(fileno(fp), S_IRUSR|S_IWUSR)) { | |
207 scr_LogPrint(LPRINT_NORMAL, "WARNING: Cannot set tracelog file permissions: %s", | |
208 strerror(errno)); | |
209 } | |
206 | 210 |
207 v = mcabber_version(); | 211 v = mcabber_version(); |
208 fprintf(fp, "New trace log started. MCabber version %s\n" | 212 fprintf(fp, "New trace log started. MCabber version %s\n" |
209 "----------------------\n", v); | 213 "----------------------\n", v); |
210 g_free(v); | 214 g_free(v); |
266 if (!fp) { | 270 if (!fp) { |
267 scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot open tracelog file: %s.", | 271 scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot open tracelog file: %s.", |
268 strerror(errno)); | 272 strerror(errno)); |
269 return; | 273 return; |
270 } | 274 } |
275 | |
276 // Check file permissions again (it could be a new file) | |
277 fchmod(fileno(fp), S_IRUSR|S_IWUSR); | |
278 | |
271 if (fputs(data, fp) == EOF) | 279 if (fputs(data, fp) == EOF) |
272 scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot write to tracelog file."); | 280 scr_LogPrint(LPRINT_NORMAL, "ERROR: Cannot write to tracelog file."); |
273 fclose(fp); | 281 fclose(fp); |
274 } | 282 } |
275 } | 283 } |