text: #include "linux_utils.h"
  #include "ledctl_pipe_manager.h"
  #include "ledctl_nop_controller.h"
  
  #include <cstdlib>
  #include <iostream>
  #include <system_error>
  
  #include <syslog.h>
  #include <cstring>
  
  void signal_handler(int sig, siginfo_t *info, void *ucontext);
  
  int main (int, char **)
  {
    std::error_code err;
    try
    {
      ::openlog("ledctlemud_test", LOG_CONS, LOG_NDELAY);
  
      err = linux_utils::sigaction(SIGINT, &signal_handler);
      if (!err)
        err = linux_utils::sigaction(SIGTERM, &signal_handler);
      if (err)
      {
        ::syslog(LOG_ERR, "Unable to setup signal handling: %d - %s", err.value(), err.message().c_str());
        return err.value();
      }
  
      ledctl::pipe_manager manager(std::make_unique<ledctl::nop_controller>());
      err = manager.start();
      if (err)
        ::syslog(LOG_ERR, "Error: %d - %s", err.value(), err.message().c_str());
    }
    catch(std::exception& ex)
    {
      std::cerr << ex.what() << std::endl;
      err.assign(EXIT_FAILURE, std::generic_category());
    }
  
    ::closelog();
    return err.value();
  }
  
  void signal_handler(int sig, siginfo_t *, void *)
  {
    static sig_atomic_t is_signalled = 0;
    if (is_signalled)
      return;
    ::syslog(LOG_ERR, "%s: %d", __func__, sig);
    if (sig == SIGINT || sig == SIGTERM)
    {
      ++is_signalled;
      ledctl::pipe_manager::stop();
    }
  }
  