#include <time.h>
#include <signal.h>
#include <sys/wait.h>
+#include <syslog.h>
#include <nettle/sha.h>
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);
}
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) {
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);
record_baseline_time();
become_pgrp();
+ start_logging();
setup_handlers();
spawn_script();
queue_alarm();
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;
* 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 <ijackson@chiark.greenend.org.uk> Tue, 29 Mar 2016 23:09:45 +0100
+ -- Ian Jackson <ijackson@chiark.greenend.org.uk> Wed, 30 Mar 2016 01:19:12 +0100
chiark-utils (4.5.0~iwj1) UNRELEASED; urgency=medium