Set facility with openlog, fix message priorites.

This commit is contained in:
Mike Barnes 2022-01-29 16:01:29 +11:00
parent 01f2503376
commit 47e075383f
2 changed files with 15 additions and 8 deletions

17
main.c
View file

@ -236,14 +236,14 @@ display_file(const char *fname)
while ((nread = fread(buffer, 1, sizeof(buffer), fd)) != 0) while ((nread = fread(buffer, 1, sizeof(buffer), fd)) != 0)
fwrite(buffer, 1, nread, stdout); fwrite(buffer, 1, nread, stdout);
goto closefd; /* close file descriptor */ goto closefd; /* close file descriptor */
syslog(LOG_DAEMON, "path served %s", fname); syslog(LOG_INFO, "path served %s", fname);
return; return;
err: err:
/* return an error code and no content */ /* return an error code and no content */
status_error(51, "file not found"); status_error(51, "file not found");
syslog(LOG_DAEMON, "path invalid %s", fname); syslog(LOG_INFO, "path invalid %s", fname);
goto closefd; goto closefd;
redirect: redirect:
@ -252,7 +252,7 @@ redirect:
goto err; goto err;
status_redirect(30, target); status_redirect(30, target);
syslog(LOG_DAEMON, "redirection from %s to %s", fname, target); syslog(LOG_INFO, "redirection from %s to %s", fname, target);
closefd: closefd:
if (S_ISREG(sb.st_mode) != 0) if (S_ISREG(sb.st_mode) != 0)
@ -267,7 +267,7 @@ autoindex(const char *path)
int n = 0; int n = 0;
struct dirent **namelist; /* this must be freed at last */ struct dirent **namelist; /* this must be freed at last */
syslog(LOG_DAEMON, "autoindex: %s", path); syslog(LOG_INFO, "autoindex: %s", path);
/* use alphasort to always have the same order on every system */ /* use alphasort to always have the same order on every system */
if ((n = scandir(path, &namelist, NULL, alphasort)) < 0) { if ((n = scandir(path, &namelist, NULL, alphasort)) < 0) {
@ -356,6 +356,10 @@ main(int argc, char **argv)
break; break;
} }
} }
/*
* set logging options and defaults
*/
openlog("vger", LOG_PID, LOG_DAEMON);
/* /*
* do chroot if an user is supplied * do chroot if an user is supplied
@ -398,7 +402,7 @@ main(int argc, char **argv)
errlog("request «%s» doesn't match gemini://", errlog("request «%s» doesn't match gemini://",
request); request);
} }
syslog(LOG_DAEMON, "request %s", request); syslog(LOG_INFO, "request %s", request);
/* remove the gemini:// part */ /* remove the gemini:// part */
memmove(request, request + GEMINI_PART, strlen(request) + 1 - GEMINI_PART); memmove(request, request + GEMINI_PART, strlen(request) + 1 - GEMINI_PART);
@ -506,5 +510,8 @@ file_to_stdout:
/* regular file to stdout */ /* regular file to stdout */
display_file(file); display_file(file);
/* end logging */
closelog();
return (0); return (0);
} }

View file

@ -25,7 +25,7 @@ void
eunveil(const char *path, const char *permissions) eunveil(const char *path, const char *permissions)
{ {
if (unveil(path, permissions) == -1) { if (unveil(path, permissions) == -1) {
syslog(LOG_DAEMON, "unveil on %s failed", path); syslog(LOG_ERR, "unveil on %s failed", path);
err(1, "unveil on %s failed", path); err(1, "unveil on %s failed", path);
} }
} }
@ -34,7 +34,7 @@ void
epledge(const char *promises, const char *execpromises) epledge(const char *promises, const char *execpromises)
{ {
if (pledge(promises, execpromises) == -1) { if (pledge(promises, execpromises) == -1) {
syslog(LOG_DAEMON, "pledge failed for: %s", promises); syslog(LOG_ERR, "pledge failed for: %s", promises);
err(1, "pledge failed for: %s", promises); err(1, "pledge failed for: %s", promises);
} }
} }
@ -89,6 +89,6 @@ errlog(const char *format, ...)
vsnprintf(e, sizeof(e), format, ap); vsnprintf(e, sizeof(e), format, ap);
va_end(ap); va_end(ap);
syslog(LOG_DAEMON, "%s", e); syslog(LOG_ERR, "%s", e);
err(1, "%s", e); err(1, "%s", e);
} }