From: Ian Jackson Date: Wed, 30 Mar 2016 00:20:18 +0000 (+0100) Subject: cgi-fcgi-interp: Send our own stage2 messages to syslog X-Git-Tag: archive/debian/5.0.0~24 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=commitdiff_plain;h=fe83c002f6082d5f035c39bbbdd2258c4c7cfa86 cgi-fcgi-interp: Send our own stage2 messages to syslog And (sadly), provide the actual interpreter with /dev/null as stderr. This is necessary because the caller expects us to behave like a proper cgi script and close our stderr. So we do that (as late as we can). --- diff --git a/cprogs/cgi-fcgi-interp.c b/cprogs/cgi-fcgi-interp.c index 5c32efe..1612e4f 100644 --- a/cprogs/cgi-fcgi-interp.c +++ b/cprogs/cgi-fcgi-interp.c @@ -145,6 +145,7 @@ #include #include #include +#include #include @@ -159,13 +160,31 @@ static int check_interval=300; static struct sha256_ctx identsc; +static bool logging; static const char *stage2; static void vmsgcore(int estatus, int errnoval, const char *fmt, va_list al) { - fputs("cgi-fcgi-interp: ",stderr); - vfprintf(stderr,fmt,al); - if (errnoval!=-1) fprintf(stderr,": %s",strerror(errnoval)); - fputc('\n',stderr); + int r; + + if (logging) { + const char *fmt_use = fmt; + char *fmt_free = 0; + if (errnoval) { + r = asprintf(&fmt_free, "%s: %%m", fmt); + if (r) { + fmt_free = 0; + } else { + fmt_use = fmt_free; + } + } + vsyslog(LOG_ERR, fmt_use, al); + free(fmt_free); + } else { + fputs("cgi-fcgi-interp: ",stderr); + vfprintf(stderr,fmt,al); + if (errnoval!=-1) fprintf(stderr,": %s",strerror(errnoval)); + fputc('\n',stderr); + } if (estatus) exit(estatus); } @@ -525,6 +544,7 @@ static void become_pgrp(void); static void setup_handlers(void); static void spawn_script(void); static void queue_alarm(void); +static void start_logging(void); static void await_something(void); int main(int argc, const char *const *argv) { @@ -543,6 +563,9 @@ int main(int argc, const char *const *argv) { if (r<0) diee("open /dev/null as stdout"); if (r>=3) close(r); else if (r!=1) die("open /dev/null for stdout gave bad fd %d",r); + + r = close(stderrfd); + if (r) diee("close saved stderr fd"); } sha256_init(&identsc); @@ -614,6 +637,7 @@ int main(int argc, const char *const *argv) { record_baseline_time(); become_pgrp(); + start_logging(); setup_handlers(); spawn_script(); queue_alarm(); @@ -732,6 +756,15 @@ static void queue_alarm(void) { alarm(check_interval); } +static void start_logging(void) { + int r; + + openlog(script, LOG_NOWAIT|LOG_PID, LOG_USER); + logging = 1; + r = dup2(1,2); + if (r!=2) diee("dup2 stdout to stderr"); +} + static void await_something(void) { int r; sigset_t mask; diff --git a/debian/changelog b/debian/changelog index 11724ca..eded82e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,8 +4,10 @@ chiark-utils (4.5.0~iwj2) UNRELEASED; urgency=medium * cgi-fcgi-interp: Provide -G option. * cgi-fcgi-interp: Provide -E option. * cgi-fcgi-interp: Demote its dependencies to Recommends. + * cgi-fcgi-interp: Send our own stage2 messages to syslog, + and (sadly), provide the actual interpreter with /dev/null as stderr. - -- Ian Jackson Tue, 29 Mar 2016 23:09:45 +0100 + -- Ian Jackson Wed, 30 Mar 2016 01:19:12 +0100 chiark-utils (4.5.0~iwj1) UNRELEASED; urgency=medium