summaryrefslogtreecommitdiff
path: root/src/tipideed
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-09-23 02:38:54 +0000
committerLaurent Bercot <ska@appnovation.com>2023-09-23 02:38:54 +0000
commit68a35fb8e58f86995929839330b7aee0a3a92a87 (patch)
treebebf8cf5b90c3104a211e2f326cbf0f3799a47d4 /src/tipideed
parent139b577cbeccd495038da51a8a3ddc8eb3397a4d (diff)
downloadtipidee-68a35fb8e58f86995929839330b7aee0a3a92a87.tar.xz
Better logging
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/tipideed')
-rw-r--r--src/tipideed/cgi.c4
-rw-r--r--src/tipideed/log.c4
-rw-r--r--src/tipideed/regular.c2
-rw-r--r--src/tipideed/responses.c7
-rw-r--r--src/tipideed/tipideed-internal.h2
5 files changed, 13 insertions, 6 deletions
diff --git a/src/tipideed/cgi.c b/src/tipideed/cgi.c
index 1ce0b1d..c2c62a1 100644
--- a/src/tipideed/cgi.c
+++ b/src/tipideed/cgi.c
@@ -102,7 +102,6 @@ static inline int do_nph (tipidee_rql const *rql, char const *const *argv, char
static inline int do_nph (tipidee_rql const *rql, char const *const *argv, char const *const *envp, char const *body, size_t bodylen)
{
int p[2] ;
- log_nph(argv, envp) ;
if (pipe(p) == -1) die500sys(rql, 111, "pipe") ;
if (bodylen)
{
@@ -134,6 +133,7 @@ static inline int do_nph (tipidee_rql const *rql, char const *const *argv, char
}
close(p[1]) ;
if (fd_move(0, p[0]) == -1) die500sys(rql, 111, "fd_move") ;
+ log_nph(argv, envp) ;
exec_e(argv, envp) ;
die500sys(rql, errno == ENOENT ? 127 : 126, "exec nph ", argv[0]) ;
}
@@ -365,7 +365,7 @@ static inline int process_cgi_output (tipidee_rql *rql, tipidee_headers const *h
}
if (!buffer_timed_flush_g(buffer_1, &deadline))
strerr_diefu1sys(111, "write to stdout") ;
- if (g.verbosity >= 4)
+ if (g.verbosity >= 2)
{
char fmt[UINT_FMT] ;
fmt[uint_fmt(fmt, status)] = 0 ;
diff --git a/src/tipideed/log.c b/src/tipideed/log.c
index f5f2e81..b08e16f 100644
--- a/src/tipideed/log.c
+++ b/src/tipideed/log.c
@@ -44,10 +44,10 @@ void log_regular (char const *fn, char const *sizefmt, int ishead, char const *c
strerr_warni8x("sending ", ishead ? "headers for " : "", "regular file ", fn, " (", sizefmt, " bytes) with type ", ct) ;
}
-void log_304 (char const *fn)
+void log_response (char const *ans, char const *fn)
{
if (g.verbosity >= 2)
- strerr_warni2x("answering 304 for regular file ", fn) ;
+ strerr_warni4x("answering ", ans, fn ? " for " : 0, fn) ;
}
void log_nph (char const *const *argv, char const *const *envp)
diff --git a/src/tipideed/regular.c b/src/tipideed/regular.c
index 5af364d..24dc392 100644
--- a/src/tipideed/regular.c
+++ b/src/tipideed/regular.c
@@ -70,7 +70,7 @@ int respond_304 (tipidee_rql const *rql, char const *fn, struct stat const *st)
if (l) n += buffer_putnoflush(buffer_1, fmt, l) ;
}
n += buffer_putnoflush(buffer_1, "\r\n", 2) ;
- log_304(fn) ;
+ log_response("304", fn) ;
tain_add_g(&deadline, &g.writetto) ;
if (!buffer_timed_flush_g(buffer_1, &deadline))
strerr_diefu1sys(111, "write to stdout") ;
diff --git a/src/tipideed/responses.c b/src/tipideed/responses.c
index 0c93582..8c6f1f5 100644
--- a/src/tipideed/responses.c
+++ b/src/tipideed/responses.c
@@ -2,6 +2,7 @@
#include <unistd.h>
+#include <skalibs/types.h>
#include <skalibs/buffer.h>
#include <skalibs/strerr.h>
#include <skalibs/tai.h>
@@ -15,8 +16,11 @@
void response_error (tipidee_rql const *rql, char const *rsl, char const *text, int doclose)
{
tain deadline ;
+ char ans[4] = "???" ;
+ memcpy(ans, rsl, 3) ;
tipidee_response_error(buffer_1, rql, rsl, text, doclose || !g.cont) ;
tain_add_g(&deadline, &g.writetto) ;
+ log_response(ans, 0) ;
if (!buffer_timed_flush_g(buffer_1, &deadline))
strerr_diefu1sys(111, "write to stdout") ;
}
@@ -52,6 +56,8 @@ void respond_30x (tipidee_rql const *rql, tipidee_redirection const *rd)
{
static char const *rsl[4] = { "307 Temporary Redirect", "308 Permanent Redirect", "302 Found", "301 Moved Permanently" } ;
tain deadline ;
+ char ans[4] = "30x" ;
+ memcpy(ans, rsl[rd->type], 3) ;
tipidee_response_status_line(buffer_1, rql, rsl[rd->type]) ;
tipidee_response_header_common_put_g(buffer_1, 0) ;
buffer_putsnoflush(buffer_1, "Content-Length: 0\r\nLocation: ") ;
@@ -59,6 +65,7 @@ void respond_30x (tipidee_rql const *rql, tipidee_redirection const *rd)
if (rd->sub) buffer_putsnoflush(buffer_1, rd->sub) ;
buffer_putnoflush(buffer_1, "\r\n\r\n", 4) ;
tain_add_g(&deadline, &g.writetto) ;
+ log_response(ans, 0) ;
if (!buffer_timed_flush_g(buffer_1, &deadline))
strerr_diefu1sys(111, "write to stdout") ;
}
diff --git a/src/tipideed/tipideed-internal.h b/src/tipideed/tipideed-internal.h
index a53fc0c..75f5be2 100644
--- a/src/tipideed/tipideed-internal.h
+++ b/src/tipideed/tipideed-internal.h
@@ -145,7 +145,7 @@ extern void log_start (void) ;
extern void log_and_exit (int) gccattr_noreturn ;
extern void log_request (tipidee_rql const *) ;
extern void log_regular (char const *, char const *, int, char const *) ;
-extern void log_304 (char const *) ;
+extern void log_response (char const *, char const *) ;
extern void log_nph (char const *const *, char const *const *) ;
extern void log_cgi (char const *const *, char const *const *) ;