mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-04 10:26:02 -05:00
seteuid(0) for reopening the log file
This commit is contained in:
parent
c4e4db0728
commit
3cbca1dd07
41
src/logger.c
41
src/logger.c
@ -21,6 +21,7 @@
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
@ -197,21 +198,43 @@ void
|
||||
logger_reinit(void)
|
||||
{
|
||||
FILE *fp;
|
||||
uid_t uid;
|
||||
int ret;
|
||||
|
||||
if (!logfile)
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(&logger_lck);
|
||||
|
||||
if (logfile)
|
||||
{
|
||||
fp = fopen(logfilename, "a");
|
||||
if (!fp)
|
||||
{
|
||||
fprintf(logfile, "WARNING: Could not reopen logfile, logging will stop now\n");
|
||||
}
|
||||
uid = geteuid();
|
||||
|
||||
fclose(logfile);
|
||||
logfile = fp;
|
||||
if (uid != 0)
|
||||
{
|
||||
ret = seteuid(0);
|
||||
if (ret < 0)
|
||||
fprintf(logfile, "logger_reinit: seteuid(0) failed: %s\n", strerror(errno));
|
||||
}
|
||||
|
||||
fp = fopen(logfilename, "a");
|
||||
|
||||
if (uid != 0)
|
||||
{
|
||||
ret = seteuid(uid);
|
||||
if (ret < 0)
|
||||
fprintf(logfile, "logger_reinit: seteuid(%lu) failed: %s\n", (unsigned long)uid, strerror(errno));
|
||||
}
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
fprintf(logfile, "Could not reopen logfile: %s\n", strerror(errno));
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
fclose(logfile);
|
||||
logfile = fp;
|
||||
|
||||
out:
|
||||
pthread_mutex_unlock(&logger_lck);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user