Commit 82e3bac4 authored by Seblu's avatar Seblu
Browse files

Mode quiet ferme redirige STDOUT et STDERR sur /dev/null

parent b2526d38
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ public:
    bool operator()(const Job &a, const Job &b);
  };

  inline bool verbose() const { return options.verbose == 1; }
  inline bool verbose() const { return options.verbose == 2; }

  Options options;

+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ Options &Options::getoptions(int argc, char *argv[]) {
      throw Error(ERR_USAGE);
    }
    else if (!strcmp(argv[i], "-v")) {
      this->verbose = 1;
      this->verbose = 2;
    }
    else if (!strcmp(argv[i], "-q")) {
      this->verbose = 0;
+15 −0
Original line number Diff line number Diff line
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string>

@@ -43,6 +45,18 @@ int main(int argc, char *argv[])

  delete lineopt;

  // dup on quiet mode
  if (daemon.options.verbose == 0) {
    int dn = open("/dev/null", O_RDWR);
    if (dn == -1) {
      perror("sld: open(/dev/null, O_RDWR)");
      return ERR_UNKNOWN;
    }
    dup2(dn, STDOUT_FILENO);
    dup2(dn, STDERR_FILENO);
    close(dn);
  }

  // register sigchild handler
  if (signal(SIGCHLD, sigchild) == SIG_ERR) {
    perror("sld: error");
@@ -89,6 +103,7 @@ static Options get_default_options() {
  options.retrydelay = 60;
  options.daemon = 0;
  options.closefd = 1;
  options.verbose = 1;
  return options;
}