34 #ifndef PACKAGE_VERSION
35 #define PACKAGE_VERSION "0.1"
38 static const char * legal_text =
39 "Copyright (C) 2017 Graeme Walker\n"
41 "This program is free software: you can redistribute it and/or modify\n"
42 "it under the terms of the GNU General Public License as published by\n"
43 "the Free Software Foundation, either version 3 of the License, or\n"
44 "(at your option) any later version.\n"
46 "This program is distributed in the hope that it will be useful,\n"
47 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
48 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
49 "GNU General Public License for more details.\n"
51 "You should have received a copy of the GNU General Public License\n"
52 "along with this program. If not, see <http://www.gnu.org/licenses/>.\n"
59 static bool have_libjpeg ;
60 static bool have_libpng ;
61 static bool have_libav ;
62 static bool have_libv4l ;
63 static bool have_v4l ;
64 static bool have_curses ;
65 static bool have_x11 ;
67 bool with_debug(
bool b )
71 bool with_verbose(
bool b )
78 bool argc_ok ,
const std::string & extra_help ) :
79 m_debug(with_debug(opt.contains(
"debug"))) ,
80 m_log_output(opt.args().prefix() ,
83 with_verbose(opt.contains(
"verbose")||m_debug) ,
86 opt.contains(
"log-time") ,
88 opt.contains(
"syslog")) ,
89 m_daemon(opt.contains(
"daemon")) ,
90 m_syslog(opt.contains(
"syslog")) ,
91 m_verbose(opt.contains(
"verbose")) ,
92 m_pid_file(opt.value(
"pid-file")) ,
93 m_user(opt.value(
"user",
"")) ,
104 if( !extra_help.empty() )
105 std::cout <<
"\n" << extra_help << std::endl ;
106 std::cout <<
"\nCopyright (C) 2017 Graeme Walker" << std::endl ;
111 std::cout << PACKAGE_VERSION << std::endl ;
114 std::cout <<
"libjpeg: " << gconfig::have_libjpeg << std::endl ;
115 std::cout <<
"libpng: " << gconfig::have_libpng << std::endl ;
116 std::cout <<
"libav: " << gconfig::have_libav << std::endl ;
117 std::cout <<
"libv4l: " << gconfig::have_libv4l << std::endl ;
118 std::cout <<
"v4l: " << gconfig::have_v4l << std::endl ;
119 std::cout <<
"curses: " << gconfig::have_curses << std::endl ;
120 std::cout <<
"xlib: " << gconfig::have_x11 << std::endl ;
122 std::cout <<
"\n" << legal_text << std::endl ;
128 std::cerr <<
"\nCopyright (C) 2017 Graeme Walker" << std::endl ;
132 setlocale( LC_ALL ,
"" ) ;
133 G::SharedMemory::help(
": consider doing \"vt-channel %s delete\" to clean up if the channel publisher is not running" ) ;
140 const bool keep_stderr = true ;
141 G::Process::closeFiles( keep_stderr ) ;
146 m_log_output.
verbose(
false ) ;
151 if( !m_user.empty() )
167 G::Process::Umask umask( G::Process::Umask::Readable ) ;
168 m_pid_file.commit() ;
171 if( m_daemon && m_syslog )
173 G::Process::closeStderr() ;
174 m_log_output.verbose( m_verbose ) ;
179 ::signal( SIGHUP , Gv::Startup::onSignal ) ;
184 void Gv::Startup::onSignal(
int )
191 report( prefix , e.what() ) ;
198 if( m_started && ( m_daemon || m_syslog ) )
199 G_ERROR(
"" << prefix <<
": " << what ) ;
214 #if GCONFIG_HAVE_LIBJPEG
215 bool gconfig::have_libjpeg = true ;
217 bool gconfig::have_libjpeg = false ;
220 #if GCONFIG_HAVE_LIBPNG
221 bool gconfig::have_libpng = true ;
223 bool gconfig::have_libpng = false ;
226 #if GCONFIG_HAVE_LIBAV
227 bool gconfig::have_libav = true ;
229 bool gconfig::have_libav = false ;
232 #if GCONFIG_HAVE_LIBV4L
233 bool gconfig::have_libv4l = true ;
235 bool gconfig::have_libv4l = false ;
239 bool gconfig::have_v4l = true ;
241 bool gconfig::have_v4l = false ;
244 #if GCONFIG_HAVE_CURSES
245 bool gconfig::have_curses = true ;
247 bool gconfig::have_curses = false ;
251 bool gconfig::have_x11 = true ;
253 bool gconfig::have_x11 = false ;
static void help(const std::string &)
Sets some error-message help text for the case when named shared memory cannot be created because it ...
static void stop(const G::SignalSafe &)
Calls quit() on instance().
static std::string get(const std::string &name, const std::string &default_)
Returns the environment variable value or the given default.
void showErrors(std::ostream &stream, std::string prefix_1, std::string prefix_2=std::string(": ")) const
A convenience function which streams out each errorList() item to the given stream, prefixed with the given prefix(es).
std::string prefix() const
Returns the basename of v(0) without any extension.
An empty structure that is used to indicate a signal-safe, reentrant implementation.
static std::string prefix()
Returns the prefix, as set by by a call to the other overload.
bool hasErrors() const
Returns true if there are errors.
A class which acquires the process's special privileges on construction and releases them on destruct...
static void init(const std::string &non_root, bool default_change_group=true)
Initialises this class on process start-up by releasing root (or suid) privileges.
void report(const std::string &prefix, std::exception &e)
Reports an error if start()ed and "daemon" or "syslog" are in effect.
A simple exception structure holding a program exit value.
A command line option parser.
Arg args() const
Returns all the non-option command-line arguments.
Startup(const G::GetOpt &, const std::string &args_help, bool argc_ok, const std::string &extra_help=std::string())
Constructor, typically used very early in main().
const Options & options() const
Returns a reference to the internal option specification object.
static void sanitise(int argc, char *argv[])
Removes sensitive information from the command-line, if possible.
static void detach()
Detaches from the parent environment.
static bool exists()
Returns true if an instance exists.
bool contains(char option_letter) const
Returns true if the command line contains the option identified by its short-form letter...
void start()
Called just before the event loop.
static void filetext(const std::string &)
Sets some help text that gets written into the placeholder files.
void showUsage(std::ostream &stream, const std::string &exe, const std::string &args=std::string(), const std::string &introducer=introducerDefault(), Level level=levelDefault(), Layout layout=layoutDefault(), bool extra=true) const
Streams out multi-line usage text using usageSummary() and usageHelp().
void verbose(bool verbose_log=true)
Enables or disables verbose logging.