From 245222f59c6bcb9bb95272753098de0b885b14ac Mon Sep 17 00:00:00 2001 From: z3APA3A <3APA3A@3proxy.ru> Date: Fri, 30 Oct 2020 18:56:09 +0300 Subject: [PATCH] fix some warnings, add log flushing for standalone services --- src/3proxy.c | 4 ++-- src/conf.c | 11 +++++++---- src/log.c | 9 ++++++++- src/webadmin.c | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/3proxy.c b/src/3proxy.c index 9d7e4bd..fd68212 100644 --- a/src/3proxy.c +++ b/src/3proxy.c @@ -202,7 +202,7 @@ void dumpcounters(struct trafcount *tlin, int counterd){ cheader.updated = conf.time; lseek(counterd, 0, SEEK_SET); - write(counterd, &cheader, sizeof(struct counter_header)); + (void)write(counterd, &cheader, sizeof(struct counter_header)); for(tl=tlin; tl; tl = tl->next){ if(tl->number){ lseek(counterd, @@ -211,7 +211,7 @@ void dumpcounters(struct trafcount *tlin, int counterd){ crecord.traf64 = tl->traf64; crecord.cleared = tl->cleared; crecord.updated = tl->updated; - write(counterd, &crecord, sizeof(struct counter_record)); + (void)write(counterd, &crecord, sizeof(struct counter_record)); } if(tl->type!=NEVER && timechanged(tl->cleared, conf.time, tl->type)){ tl->cleared = conf.time; diff --git a/src/conf.c b/src/conf.c index f13163b..a1c227a 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1161,7 +1161,7 @@ static int h_ace(int argc, char **argv){ sizeof(struct counter_header) + (tl->number - 1) * sizeof(struct counter_record), SEEK_SET); memset(&crecord, 0, sizeof(struct counter_record)); - read(conf.counterd, &crecord, sizeof(struct counter_record)); + (void)read(conf.counterd, &crecord, sizeof(struct counter_record)); tl->traf64 = crecord.traf64; tl->cleared = crecord.cleared; tl->updated = crecord.updated; @@ -1379,15 +1379,18 @@ static int h_chroot(int argc, char **argv){ } chrootp = mystrdup((char *)argv[1]); } - if (gid && setregid(gid,gid)) { + if(gid && setregid(gid,gid)) { fprintf(stderr, "Unable to set gid %d", (int)gid); return(4); } - if (uid && setreuid(uid,uid)) { + if(uid && setreuid(uid,uid)) { fprintf(stderr, "Unable to set uid %d", (int)uid); return(5); } - chdir("/"); + if(chdir("/")){ + fprintf(stderr, "Unable to chdir to /"); + return(5); + } return 0; } #endif diff --git a/src/log.c b/src/log.c index 8302af8..b315336 100644 --- a/src/log.c +++ b/src/log.c @@ -836,9 +836,13 @@ static void stdlog(const char * buf, int len, struct LOGGER *logger) { FILE *log = ((struct stdlogdata *)logger->data)->fp; fprintf(log, "%s\n", buf); +#ifdef WITHMAIN + fflush(log); +#endif } static void stdlogrotate(struct LOGGER *logger){ +#ifndef WITHMAIN char tmpbuf[1024]; struct stdlogdata *lp = (struct stdlogdata *)logger->data; if(lp->fp) lp->fp = freopen((char *)dologname (tmpbuf, sizeof(tmpbuf) -1, logger->selector, NULL, logger->rotate, conf.time), "a", lp->fp); @@ -886,9 +890,10 @@ static void stdlogrotate(struct LOGGER *logger){ else strcat((char *)tmpbuf, (char *)conf.archiver[i]); } - system((char *)tmpbuf+1); + (void)system((char *)tmpbuf+1); } } +#endif } static void stdlogflush(struct LOGGER *logger){ @@ -913,8 +918,10 @@ static void logsyslog(const char * buf, int len, struct LOGGER *logger) { } static void syslogrotate(struct LOGGER *logger){ +#ifndef WITHMAIN closelog(); openlog(logger->selector+1, LOG_PID, LOG_DAEMON); +#endif } static void syslogclose(struct LOGGER *logger){ diff --git a/src/webadmin.c b/src/webadmin.c index 46471bd..1ad334d 100644 --- a/src/webadmin.c +++ b/src/webadmin.c @@ -557,7 +557,7 @@ void * adminchild(struct clientparam* param) { if(writable && !error){ fflush(writable); #ifndef _WINCE - ftruncate(fileno(writable), ftell(writable)); + (void)ftruncate(fileno(writable), ftell(writable)); #endif } printstr(&pp, error? "

Config file is not writable

Make sure you have \"writable\" command in configuration file":