• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OpenLightingProject / ola / 24609073669

18 Apr 2026 04:36PM UTC coverage: 44.864% (-0.9%) from 45.72%
24609073669

push

github

web-flow
Merge pull request #2043 from peternewman/nortle-ftdi

Revert some stuff via 146cf26 which accidentally snuck into #1999 by mistake

8554 of 19846 branches covered (43.1%)

22105 of 49271 relevant lines covered (44.86%)

48.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/olad/Olad.cpp
1
/*
2
 * This program is free software; you can redistribute it and/or modify
3
 * it under the terms of the GNU General Public License as published by
4
 * the Free Software Foundation; either version 2 of the License, or
5
 * (at your option) any later version.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU Library General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15
 *
16
 * Olad.cpp
17
 * Main file for olad, parses the options, forks if required and runs the
18
 * daemon.
19
 * Copyright (C) 2005 Simon Newton
20
 *
21
 */
22

23
#if HAVE_CONFIG_H
24
#include <config.h>
25
#endif  // HAVE_CONFIG_H
26

27
#include <signal.h>
28
#include <stdio.h>
29
#include <stdlib.h>
30
#include <unistd.h>
31

32
#include <iostream>
33
#include <memory>
34

35
// On MinGW, OlaDaemon.h pulls in SocketAddress.h which pulls in WinSock2.h,
36
// which needs to be after WinSock2.h, hence this order
37
#include "olad/OlaDaemon.h"
38

39
#include "ola/Logging.h"
40
#include "ola/base/Credentials.h"
41
#include "ola/base/Flags.h"
42
#include "ola/base/Init.h"
43
#include "ola/base/SysExits.h"
44
#include "ola/base/Version.h"
45
#include "ola/thread/SignalThread.h"
46

47
using ola::OlaDaemon;
48
using ola::thread::SignalThread;
49
using std::cout;
50
using std::endl;
51

52
DEFINE_default_bool(http, true, "Disable the HTTP server.");
53
DEFINE_default_bool(http_quit, true, "Disable the HTTP /quit handler.");
54
#ifndef _WIN32
55
DEFINE_s_default_bool(daemon, f, false,
56
                      "Fork and run as a background process.");
57
#endif  // _WIN32
58
DEFINE_s_string(http_data_dir, d, "", "The path to the static www content.");
59
DEFINE_s_string(interface, i, "",
60
                "The interface name (e.g. eth0) or IP address of the network "
61
                "interface to use for the web server.");
62
DEFINE_string(pid_location, "",
63
              "The directory containing the PID definitions.");
64
DEFINE_s_uint16(http_port, p, ola::OlaServer::DEFAULT_HTTP_PORT,
65
                "The port to run the HTTP server on. Defaults to 9090.");
66

67
/**
68
 * This is called by the SelectServer loop to start up the SignalThread. If the
69
 * thread fails to start, we terminate the SelectServer
70
 */
71
void StartSignalThread(ola::io::SelectServer *ss,
×
72
                       SignalThread *signal_thread) {
73
  if (!signal_thread->Start()) {
×
74
    ss->Terminate();
×
75
  }
76
}
×
77

78

79
/*
80
 * Main
81
 */
82
int main(int argc, char *argv[]) {
×
83
  // Take a copy of the arguments otherwise the export map is incorrect.
84
  const int original_argc = argc;
×
85
  char *original_argv[original_argc];
×
86
  for (int i = 0; i < original_argc; i++) {
×
87
    original_argv[i] = argv[i];
×
88
  }
89

90
  // We don't use the longer form for ServerInit here because we need to check
91
  // for root and possibly daemonise before doing the rest of the work from
92
  // ServerInit.
93

94
  ola::SetHelpString("[options]", "Start the OLA Daemon.");
×
95
  ola::ParseFlags(&argc, argv);
×
96

97
  ola::InitLoggingFromFlags();
×
98
  OLA_INFO << "OLA Daemon version " << ola::base::Version::GetVersion()
×
99
           << " build " << ola::base::Version::GetBuildName();
×
100

101
  #ifndef OLAD_SKIP_ROOT_CHECK
102
  uid_t uid;
×
103
  ola::GetEUID(&uid);
×
104
  if (ola::SupportsUIDs() && !uid) {
×
105
    OLA_FATAL << "Attempting to run as root, aborting.";
×
106
    return ola::EXIT_UNAVAILABLE;
×
107
  }
108
  #endif  // OLAD_SKIP_ROOT_CHECK
109

110
#ifndef _WIN32
111
  if (FLAGS_daemon)
×
112
    ola::Daemonise();
×
113
#endif  // _WIN32
114

115
  ola::ExportMap export_map;
×
116
  if (!ola::ServerInit(original_argc, original_argv, &export_map)) {
×
117
    return ola::EXIT_UNAVAILABLE;
×
118
  }
119

120
  // We need to block signals before we start any threads.
121
  // Signal setup is complex. First of all we need to install NULL handlers to
122
  // the signals are blocked before we start *any* threads. It's safest if we
123
  // do this before creating the OlaDaemon.
124
  SignalThread signal_thread;
×
125
  signal_thread.InstallSignalHandler(SIGINT, NULL);
×
126
  signal_thread.InstallSignalHandler(SIGTERM, NULL);
×
127
#ifndef _WIN32
128
  signal_thread.InstallSignalHandler(SIGHUP, NULL);
×
129
  signal_thread.InstallSignalHandler(
×
130
      SIGUSR1, ola::NewCallback(&ola::IncrementLogLevel));
131
#endif  // _WIN32
132

133
  ola::OlaServer::Options options;
×
134
  options.http_enable = FLAGS_http;
×
135
  options.http_enable_quit = FLAGS_http_quit;
×
136
  options.http_port = FLAGS_http_port;
×
137
  options.http_data_dir = FLAGS_http_data_dir.str();
×
138
  options.network_interface = FLAGS_interface.str();
×
139
  options.pid_data_dir = FLAGS_pid_location.str();
×
140

141
  std::auto_ptr<OlaDaemon> olad(new OlaDaemon(options, &export_map));
×
142
  if (!olad.get()) {
×
143
    return ola::EXIT_UNAVAILABLE;
144
  }
145

146
  // Now that the OlaDaemon has been created, we can reset the signal handlers
147
  // to do what we actually want them to.
148
  signal_thread.InstallSignalHandler(
×
149
      SIGINT,
150
      ola::NewCallback(olad->GetSelectServer(),
151
                       &ola::io::SelectServer::Terminate));
152
  signal_thread.InstallSignalHandler(
×
153
      SIGTERM,
154
      ola::NewCallback(olad->GetSelectServer(),
155
                       &ola::io::SelectServer::Terminate));
156

157
  // We can't start the signal thread here, otherwise there is a race
158
  // condition if a signal arrives before we enter the SelectServer Run()
159
  // method. Instead we schedule it to start from the SelectServer loop.
160
  olad->GetSelectServer()->Execute(ola::NewSingleCallback(
×
161
        &StartSignalThread,
162
        olad->GetSelectServer(),
163
        &signal_thread));
164

165
  if (!olad->Init()) {
×
166
    return ola::EXIT_UNAVAILABLE;
×
167
  }
168

169
#ifndef _WIN32
170
  // Finally the OlaServer is not-null.
171
  signal_thread.InstallSignalHandler(
×
172
      SIGHUP,
173
      ola::NewCallback(olad->GetOlaServer(), &ola::OlaServer::ReloadPlugins));
174
#endif  // _WIN32
175

176
  olad->Run();
×
177
  return ola::EXIT_OK;
×
178
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc