Permalink
Browse files

allow arbitrary loggers, like Facebook's scribe.

git-svn-id: svn://okws.org/sfslite2/devel/1.2@5591 7d287422-6eea-da11-b677-00123f2a783a
  • Loading branch information...
1 parent 4c58509 commit d58f011498ac2388064faa4c9c991f9f058e746c max committed Feb 1, 2011
Showing with 116 additions and 69 deletions.
  1. +2 −0 async/amisc.h
  2. +2 −2 async/async.h
  3. +110 −64 async/daemonize.C
  4. +2 −2 configure.in
  5. +0 −1 libtame/tame_connectors.Th
View
@@ -154,6 +154,8 @@ void daemonize (const str &name = NULL);
void start_logger ();
int start_logger (const str &pri, const str &tag, const str &line,
const str &logfile, int flags, mode_t mode);
+void set_syslog_logger (const vec<str> &v);
+bool get_syslog_logger (vec<str> *out);
/* Random usefull operators */
#include "keyfunc.h"
View
@@ -107,7 +107,7 @@ void ifchgcb_remove (ifchgcb_t *chg);
#define SFSLITE_VERSION_MAJOR 1
#define SFSLITE_VERSION_MINOR 2
#define SFSLITE_VERSION_PATCHLEVEL 9
-#define SFSLITE_VERSION_PRE 105
+#define SFSLITE_VERSION_PRE 106
//
// VERSION_PRE < 100 means pre1, pre2, etc. releases
@@ -125,6 +125,6 @@ void ifchgcb_remove (ifchgcb_t *chg);
SFSLITE_VERSION_PATCHLEVEL, \
SFSLITE_VERSION_PRE))
-#define SFSLITE_PATCHLEVEL_STR "1.2.9.5"
+#define SFSLITE_PATCHLEVEL_STR "1.2.9.6"
#endif /* !_ASYNC_ASYNC_H_ */
View
@@ -25,6 +25,45 @@
str syslog_priority ("daemon.notice");
str syslog_tag ("");
+static vec<str> *g_syslog_logger;
+
+void set_syslog_logger (const vec<str> &v)
+{
+ g_syslog_logger = New vec<str> ();
+ *g_syslog_logger = v;
+}
+
+bool
+get_syslog_logger (vec<str> *out)
+{
+ bool ret = true;
+ if (g_syslog_logger) {
+ *out = *g_syslog_logger;
+ } else {
+#ifdef PATH_LOGGER
+ out->push_back (PATH_LOGGER);
+ out->push_back ("-p");
+ out->push_back (syslog_priority);
+ out->push_back ("-t");
+ out->push_back (syslog_tag.cstr ());
+#else
+ ret = false;
+#endif
+ }
+ return ret;
+}
+
+const char **
+vec2argv (const vec<str> &v)
+{
+ const char **ret = New const char * [v.size () + 1];
+ size_t i;
+ for (i = 0; i < v.size (); i++) {
+ ret[i] = v[i].cstr ();
+ }
+ ret[i] = NULL;
+ return ret;
+}
static int
start_log_to_file (const str &line, const str &logfile, int flags, mode_t m)
@@ -49,81 +88,88 @@ int
start_logger (const str &priority, const str &tag, const str &line,
const str &logfile, int flags, mode_t mode)
{
+ str logger;
#ifdef PATH_LOGGER
- const char *av[] = { PATH_LOGGER, "-p", NULL, "-t", NULL, NULL, NULL };
- av[2] = const_cast<char *> (priority.cstr ());
-
- if (line)
- av[5] = const_cast<char *> (line.cstr ());
- else
- av[5] = "log started";
-
- if (tag)
- av[4] = const_cast<char *> (tag.cstr ());
- else
- av[4] = "";
+ logger = PATH_LOGGER;
+#endif
- pid_t pid;
- int status;
- if ((pid = spawn (PATH_LOGGER, av, 0, 0, errfd)) < 0) {
- warn ("%s: %m\n", PATH_LOGGER);
- return start_log_to_file (line, logfile, flags, mode);
- }
- if (waitpid (pid, &status, 0) <= 0 || !WIFEXITED (status) ||
- WEXITSTATUS (status))
- return start_log_to_file (line, logfile, flags, mode);
-
- int fds[2];
- if (socketpair (AF_UNIX, SOCK_STREAM, 0, fds) < 0)
- fatal ("socketpair: %m\n");
- close_on_exec (fds[0]);
- if (fds[1] != 0)
- close_on_exec (fds[1]);
+ if (logger) {
+ const char *av[] = { NULL, "-p", NULL, "-t", NULL, NULL, NULL };
+ av[0] = const_cast<char *> (logger.cstr ());
+ av[2] = const_cast<char *> (priority.cstr ());
- av[5] = NULL;
- if (spawn (PATH_LOGGER, av, fds[1], 0, 0) >= 0) {
- close (fds[1]);
- return fds[0];
- } else
- warn ("%s: %m\n", PATH_LOGGER);
-#endif /* PATH_LOGGER */
+ if (line)
+ av[5] = const_cast<char *> (line.cstr ());
+ else
+ av[5] = "log started";
+
+ if (tag)
+ av[4] = const_cast<char *> (tag.cstr ());
+ else
+ av[4] = "";
+
+ pid_t pid;
+ int status;
+ if ((pid = spawn (av[0], av, 0, 0, errfd)) < 0) {
+ warn ("%s: %m\n", logger.cstr ());
+ return start_log_to_file (line, logfile, flags, mode);
+ }
+ if (waitpid (pid, &status, 0) <= 0 || !WIFEXITED (status) ||
+ WEXITSTATUS (status))
+ return start_log_to_file (line, logfile, flags, mode);
+
+ int fds[2];
+ if (socketpair (AF_UNIX, SOCK_STREAM, 0, fds) < 0)
+ fatal ("socketpair: %m\n");
+ close_on_exec (fds[0]);
+ if (fds[1] != 0)
+ close_on_exec (fds[1]);
+
+ av[5] = NULL;
+ if (spawn (av[0], av, fds[1], 0, 0) >= 0) {
+ close (fds[1]);
+ return fds[0];
+ } else {
+ warn ("%s: %m\n", logger.cstr ());
+ }
+ }
return start_log_to_file (line, logfile, flags, mode);
}
void
start_logger ()
{
-#ifdef PATH_LOGGER
- const char *av[] = { PATH_LOGGER, "-p",
- syslog_priority.cstr (),
- "-t", syslog_tag.cstr (), NULL};
- int fds[2];
-
- close (0);
- if (int fd = open ("/dev/null", O_RDONLY))
- close (fd);
-
- if (socketpair (AF_UNIX, SOCK_STREAM, 0, fds) < 0)
- fatal ("socketpair: %m\n");
- close_on_exec (fds[0]);
- if (fds[1] != 0)
- close_on_exec (fds[1]);
-
- if (spawn (PATH_LOGGER, av, fds[1], 0, 0) >= 0) {
- close (fds[1]);
- if (fds[0] != errfd) {
- err_flush (); // XXX - we shouldn't depend on aerr.C
- if (dup2 (fds[0], errfd) < 0)
- fatal ("dup2: %m\n");
- close (fds[0]);
+ vec<str> logger_argv;
+ if (get_syslog_logger (&logger_argv)) {
+ const char **av = vec2argv (logger_argv);
+ int fds[2];
+
+ close (0);
+ if (int fd = open ("/dev/null", O_RDONLY))
+ close (fd);
+
+ if (socketpair (AF_UNIX, SOCK_STREAM, 0, fds) < 0)
+ fatal ("socketpair: %m\n");
+ close_on_exec (fds[0]);
+ if (fds[1] != 0)
+ close_on_exec (fds[1]);
+
+ if (spawn (av[0], av, fds[1], 0, 0) >= 0) {
+ close (fds[1]);
+ if (fds[0] != errfd) {
+ err_flush (); // XXX - we shouldn't depend on aerr.C
+ if (dup2 (fds[0], errfd) < 0)
+ fatal ("dup2: %m\n");
+ close (fds[0]);
+ }
+ if (errfd != 1)
+ dup2 (errfd, 1);
+ return;
}
- if (errfd != 1)
- dup2 (errfd, 1);
- return;
+ else
+ warn ("%s: %m\n", av[0]);
+ delete [] av;
}
- else
- warn ("%s: %m\n", PATH_LOGGER);
-#endif /* PATH_LOGGER */
/* No logger, at least send chatter to stdout rather than stderr, so
* that it can be redirected. */
View
@@ -4,7 +4,7 @@ dnl Process this file with autoconf to produce a configure script.
dnl
AC_INIT(acinclude.m4)
-AM_INIT_AUTOMAKE(sfslite,1.2.9.5)
+AM_INIT_AUTOMAKE(sfslite,1.2.9.6)
AM_CONFIG_HEADER(config.h)
dnl
@@ -18,7 +18,7 @@ dnl versioning the .so's that we're going to spit out. Start
dnl with version 1.0.0, since 0.0.0 is already in use. Must
dnl manually update everytim we change the ABI.
dnl
-SFS_INIT_LDVERSION(34)
+SFS_INIT_LDVERSION(35)
dnl
dnl begin SFSLITE change
@@ -148,7 +148,6 @@ connector_t<T1,T2,T3>::__sig (typename event<T1,T2,T3>::ptr *out,
}
tamed template<class T1, class T2, class T3> void
-
connector_t<T1,T2,T3>::__kto (typename event<T1,T2,T3>::ptr *out,
ptr<closure_t> c,
typename event<T1,T2,T3>::ref in,

0 comments on commit d58f011

Please sign in to comment.