diff options
Diffstat (limited to 'bbot/agent.cxx')
-rw-r--r-- | bbot/agent.cxx | 75 |
1 files changed, 46 insertions, 29 deletions
diff --git a/bbot/agent.cxx b/bbot/agent.cxx index a8c1b6e..26b0073 100644 --- a/bbot/agent.cxx +++ b/bbot/agent.cxx @@ -2,11 +2,8 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -#ifndef _WIN32 -# include <signal.h> // signal() -#else -# include <stdlib.h> // getenv(), _putenv() -#endif +#include <signal.h> // signal() +#include <unistd.h> // sleep() #include <iostream> @@ -22,44 +19,57 @@ using namespace std; using namespace butl; using namespace bbot; +extern "C" void +handle_signal (int sig) +{ + switch (sig) + { + case SIGHUP: exit (3); // Unimplemented feature. + case SIGTERM: exit (0); + default: assert (false); + } +} + int main (int argc, char* argv[]) try { - // This is a little hack to make out baseutils for Windows work when called - // with absolute path. In a nutshell, MSYS2's exec*p() doesn't search in the - // parent's executable directory, only in PATH. And since we are running - // without a shell (that would read /etc/profile which sets PATH to some - // sensible values), we are only getting Win32 PATH values. And MSYS2 /bin - // is not one of them. So what we are going to do is add /bin at the end of - // PATH (which will be passed as is by the MSYS2 machinery). This will make - // MSYS2 search in /bin (where our baseutils live). And for everyone else - // this should be harmless since it is not a valid Win32 path. + // Map to systemd severity prefixes (see sd-daemon(3) for details). Note + // that here we assume we will never have location (like file name which + // would end up being before the prefix). // -#ifdef _WIN32 - { - string mp ("PATH="); - if (const char* p = getenv ("PATH")) - { - mp += p; - mp += ';'; - } - mp += "/bin"; - - _putenv (mp.c_str ()); - } -#endif + const char indent[] = "\xE2\x86\xB2\n"; // Right arrow followed by newline. + + trace_indent = + fail.indent_ = + error.indent_ = + warn.indent_ = + info.indent_ = + text.indent_ = indent; + + fail.type_ = "<3>"; + error.type_ = "<3>"; + warn.type_ = "<4>"; + info.type_ = "<6>"; + trace_type = "<7>"; + + tracer trace ("main"); // On POSIX ignore SIGPIPE which is signaled to a pipe-writing process if // the pipe reading end is closed. Note that by default this signal // terminates a process. Also note that there is no way to disable this // behavior on a file descriptor basis or for the write() function call. // -#ifndef _WIN32 if (signal (SIGPIPE, SIG_IGN) == SIG_ERR) fail << "unable to ignore broken pipe (SIGPIPE) signal: " << system_error (errno, generic_category ()); // Sanitize. -#endif + + // Handle SIGHUP and SIGTERM. + // + if (signal (SIGHUP, &handle_signal) == SIG_ERR || + signal (SIGTERM, &handle_signal) == SIG_ERR) + fail << "unable to set signal handler: " + << system_error (errno, generic_category ()); // Sanitize. cli::argv_scanner scan (argc, argv, true); agent_options ops (scan); @@ -88,6 +98,13 @@ try // return p.wait () ? 0 : 1; } + + for (;;) + { + error << "sleeping" << + warn << "lightly"; + sleep (10); + } } catch (const failed&) { |