Belle II Software  release-08-01-10
Daemon.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include "daq/slc/system/Daemon.h"
9 
10 #include <daq/slc/system/LogFile.h>
11 
12 #include <daq/slc/base/StringUtil.h>
13 
14 #include <unistd.h>
15 #include <cstring>
16 
17 using namespace Belle2;
18 
19 bool Daemon::start(const char* title,
20  int argc, char** argv,
21  int nargc, const char* msg)
22 {
23  g_argc = argc;
24  g_argv = argv;
25  bool isdaemon = false;
26  for (int i = 1; i < argc; i++) {
27  if (strcmp(argv[i], "-d") == 0) {
28  isdaemon = true;
29  nargc++;
30  } else if (strcmp(argv[i], "-h") == 0) {
31  LogFile::debug("Usage : %s %s [-d]", argv[0], msg);
32  return false;
33  }
34  }
35  if (argc < nargc + 1) {
36  LogFile::debug("Usage : %s %s [-d]", argv[0], msg);
37  return false;
38  }
39  LogFile::open(StringUtil::form("%s/%s", argv[0], title));
40  if (isdaemon) {
41  daemon(0, 0);
42  }
43  return true;
44 }
45 
46 
47 bool Daemon::restart()
48 {
49  return execv(g_argv[0], g_argv) != -1;
50 }
51 
52 int Daemon::g_argc = 0;
53 char** Daemon::g_argv = NULL;
Abstract base class for different kinds of events.