mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-09 20:58:10 -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
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -197,21 +198,43 @@ void
|
|||||||
logger_reinit(void)
|
logger_reinit(void)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
uid_t uid;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (!logfile)
|
||||||
|
return;
|
||||||
|
|
||||||
pthread_mutex_lock(&logger_lck);
|
pthread_mutex_lock(&logger_lck);
|
||||||
|
|
||||||
if (logfile)
|
uid = geteuid();
|
||||||
{
|
|
||||||
fp = fopen(logfilename, "a");
|
|
||||||
if (!fp)
|
|
||||||
{
|
|
||||||
fprintf(logfile, "WARNING: Could not reopen logfile, logging will stop now\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(logfile);
|
if (uid != 0)
|
||||||
logfile = fp;
|
{
|
||||||
|
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);
|
pthread_mutex_unlock(&logger_lck);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user