source: trunk/server/common/patches/httpd-suexec-journald.patch @ 2698

Last change on this file since 2698 was 2603, checked in by achernya, 8 years ago
oops, include the suexec patch
File size: 2.9 KB
RevLine 
[2603]1From 7eefa90ac1422825db6f1bbbe4e66f1336fca531 Mon Sep 17 00:00:00 2001
2From: Alexander Chernyakhovsky <achernya@mit.edu>
3Date: Thu, 28 Aug 2014 22:51:21 -0400
4Subject: [PATCH] Redirect stderr to systemd-journald
5
6Scripts provides the "logview" facility for users to be able to see
7the error logs from their applications. However, this facility
8requires running the moral equivalent of grep $USER error_log. Not all
9error messages contain the username, and therefore, the logview
10facility is unreliable at best.
11
12Additionally, the error_log contains an interleaving of all errors,
13which makes it difficult for system administrators to help withs
14upport requests in which an Internal Server Error has been
15experienced.
16
17Since systemd-journald supports per-user journals, replace stderr,
18which is provided by Apache, with a file descriptor pointing to the
19journal. Assuming that journald is configured to split the log on
20UIDs, this will allow journalctl --user to show each individual user
21their error logs.
22---
23 support/Makefile.in |  7 ++++++-
24 support/suexec.c    | 21 +++++++++++++++++++++
25 2 files changed, 27 insertions(+), 1 deletion(-)
26
27diff --git a/support/Makefile.in b/support/Makefile.in
28index 745d86c..4014c1f 100644
29--- a/support/Makefile.in
30+++ b/support/Makefile.in
31@@ -73,8 +73,13 @@ checkgid: $(checkgid_OBJECTS)
32        $(LINK) $(checkgid_LTFLAGS) $(checkgid_OBJECTS) $(PROGRAM_LDADD)
33 
34 suexec_OBJECTS = suexec.lo
35+suexec_LDADD = "-lsystemd-journal -lsystemd-id128"
36+suexec.lo: suexec.c
37+       $(LIBTOOL) --mode=compile $(CC) $(ab_CFLAGS) $(ALL_CFLAGS) $(ALL_CPPFLAGS) \
38+           $(ALL_INCLUDES) $(PICFLAGS) $(LTCFLAGS) -DSCRIPTS_HAVE_SYSTEMD_JOURNAL \
39+           -c $< && touch $@
40 suexec: $(suexec_OBJECTS)
41-       $(LINK) $(suexec_OBJECTS)
42+       $(LINK) $(suexec_OBJECTS) $(suexec_LDADD)
43 
44 htcacheclean_OBJECTS = htcacheclean.lo
45 htcacheclean: $(htcacheclean_OBJECTS)
46diff --git a/support/suexec.c b/support/suexec.c
47index 3a4d802..4fe4c44 100644
48--- a/support/suexec.c
49+++ b/support/suexec.c
50@@ -61,6 +61,11 @@
51 #include <grp.h>
52 #endif
53 
54+#ifdef SCRIPTS_HAVE_SYSTEMD_JOURNAL
55+#include <systemd/sd-journal.h>
56+#include <systemd/sd-daemon.h>
57+#endif
58+
59 #ifdef AP_LOG_SYSLOG
60 #include <syslog.h>
61 #endif
62@@ -769,6 +774,22 @@ TRUSTED_DIRECTORY:
63     umask(AP_SUEXEC_UMASK);
64 #endif /* AP_SUEXEC_UMASK */
65 
66+#ifdef SCRIPTS_HAVE_SYSTEMD_JOURNAL
67+    int fd = sd_journal_stream_fd("CGI Script", LOG_NOTICE, 0);
68+    if (fd < 0) {
69+       log_err("unable to open systemd-journald file descriptor\n");
70+       exit(254);
71+    }
72+    if (dup2(fd, STDERR_FILENO) < 0) {
73+       log_err("unable to make journald file descriptor available as stderr\n");
74+       exit(253);
75+    }
76+    if (close(fd) < 0) {
77+       log_err("unable to close journald file descriptor copy\n");
78+       exit(252);
79+    }
80+#endif /* SCRIPTS_HAVE_SYSTEMD_JOURNAL */
81+
82     /* Be sure to close the log file so the CGI can't mess with it. */
83 #ifdef AP_LOG_SYSLOG
84     if (log_open) {
85--
861.8.5.2 (Apple Git-48)
87
Note: See TracBrowser for help on using the repository browser.