| simplify logging - geomyidae - A small C-based gopherd. | |
| git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfri… | |
| Log | |
| Files | |
| Refs | |
| Tags | |
| README | |
| LICENSE | |
| --- | |
| commit b9564e67ddb252ea67bae5795f38d11223702ea9 | |
| parent 307f2701a7beb18da48e209c8a6d039fdf44c353 | |
| Author: Hiltjo Posthuma <[email protected]> | |
| Date: Sun, 4 Feb 2018 13:59:54 +0100 | |
| simplify logging | |
| Signed-off-by: Christoph Lohmann <[email protected]> | |
| Diffstat: | |
| M ind.c | 15 --------------- | |
| M ind.h | 2 -- | |
| M main.c | 16 ++++++++++------ | |
| 3 files changed, 10 insertions(+), 23 deletions(-) | |
| --- | |
| diff --git a/ind.c b/ind.c | |
| @@ -239,7 +239,6 @@ getadv(char *str) | |
| char *b, *e, *o, *bo; | |
| Elems *ret; | |
| - | |
| ret = xcalloc(1, sizeof(Elems)); | |
| if (strchr(str, '\t')) { | |
| @@ -364,20 +363,6 @@ printelem(int fd, Elems *el, char *addr, char *port) | |
| return 0; | |
| } | |
| -int | |
| -initlogging(char *logf) | |
| -{ | |
| - return open(logf, O_APPEND | O_WRONLY | O_CREAT, 0644); | |
| -} | |
| - | |
| -void | |
| -stoplogging(int fd) | |
| -{ | |
| - close(fd); | |
| - | |
| - return; | |
| -} | |
| - | |
| char * | |
| smprintf(char *fmt, ...) | |
| { | |
| diff --git a/ind.h b/ind.h | |
| @@ -44,8 +44,6 @@ void addindexs(Indexs *idx, Elems *el); | |
| void addelem(Elems *e, char *s); | |
| void freeindex(Indexs *i); | |
| void freeelem(Elems *e); | |
| -int initlogging(char *logf); | |
| -void stoplogging(int fd); | |
| char *smprintf(char *fmt, ...); | |
| char *reverselookup(char *host); | |
| void setcgienviron(char *file, char *path, char *port, char *base, | |
| diff --git a/main.c b/main.c | |
| @@ -243,8 +243,10 @@ sighandler(int sig) | |
| case SIGABRT: | |
| case SIGTERM: | |
| case SIGKILL: | |
| - if (logfile != nil) | |
| - stoplogging(glfd); | |
| + if (logfile != nil && glfd != -1) { | |
| + close(glfd); | |
| + glfd = -1; | |
| + } | |
| if (listfd >= 0) { | |
| shutdown(listfd, SHUT_RDWR); | |
| close(listfd); | |
| @@ -440,9 +442,9 @@ main(int argc, char *argv[]) | |
| } | |
| if (logfile != nil) { | |
| - glfd = initlogging(logfile); | |
| + glfd = open(logfile, O_APPEND | O_WRONLY | O_CREAT, 0644); | |
| if (glfd < 0) { | |
| - perror("initlogging"); | |
| + perror("log"); | |
| return 1; | |
| } | |
| } else if (!dofork) { | |
| @@ -563,8 +565,10 @@ main(int argc, char *argv[]) | |
| shutdown(listfd, SHUT_RDWR); | |
| close(listfd); | |
| - if (logfile != nil) | |
| - stoplogging(glfd); | |
| + if (logfile != nil && glfd != -1) { | |
| + close(glfd); | |
| + glfd = -1; | |
| + } | |
| free(ohost); | |
| return 0; |