1#include "libmythbase/mythconfig.h"
2#if CONFIG_SYSTEMD_NOTIFY
3 #include <systemd/sd-daemon.h>
11#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
12#include <QtEnvironmentVariables>
13#include <QtSystemDetection>
16#include <QCoreApplication>
18#include <QApplication>
26#include <QProcessEnvironment>
43#include "libmythbase/mythversion.h"
63#define LOC QString("MythBackend: ")
64#define LOC_WARN QString("MythBackend, Warning: ")
65#define LOC_ERR QString("MythBackend, Error: ")
74int main(
int argc,
char **argv)
99 for (
long i =
UNUSED_FILENO; i < sysconf(_SC_OPEN_MAX) - 1; ++i)
102 QCoreApplication a(argc, argv);
106 QApplication a(argc, argv);
111 QString path = QCoreApplication::applicationDirPath();
112 qputenv(
"PYTHONPATH",
113 QString(
"%1/../Resources/lib/%2:%1/../Resources/lib/%2/site-packages:%1/../Resources/lib/%2/lib-dynload:%3")
115 .arg(QFileInfo(PYTHON_EXE).fileName())
116 .arg(QProcessEnvironment::systemEnvironment().value(
"PYTHONPATH"))
117 .toUtf8().constData());
125 QString mask(
"general");
134#if CONFIG_SYSTEMD_NOTIFY
135 (void)sd_notify(0,
"STATUS=Connecting to database.");
156 if (!context.Init(
false,
false,
false,ignoreDB))
158 LOG(VB_GENERAL, LOG_CRIT,
"Failed to init MythContext.");
183 if (retval == 258 || retval == 259)
185 char ** newargv =
new char * [argc + 2];
186 std::string webonly =
"--webonly";
187 newargv[0] = argv[0];
189 for (
int ix = 1 ; ix < argc ; ++ix)
191 if (webonly != argv[ix])
192 newargv[newargc++] = argv[ix];
195 newargv[newargc++] = webonly.data();
196 newargv[newargc] =
nullptr;
197 LOG(VB_GENERAL, LOG_INFO,
198 QString(
"Restarting mythbackend"));
199 std::this_thread::sleep_for(50ms);
200 int rc = execvp(newargv[0], newargv);
201 LOG(VB_GENERAL, LOG_ERR,
202 QString(
"execvp failed prog %1 rc=%2 errno=%3").arg(argv[0]).arg(rc).arg(errno));
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
void ApplySettingsOverride(void)
Apply all overrides to the global context.
int Daemonize(void) const
Fork application into background, and detatch from terminal.
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
static void PrintVersion(void)
Print application version information.
void PrintHelp(void) const
Print command line option help.
Startup context for MythTV.
void SetAsBackend(bool backend)
static void load(const QString &module_name)
Load a QTranslator for the user's preferred language.
static WebOnlyStartup s_WebOnlyStartup
@ GENERIC_EXIT_NO_MYTHCONTEXT
No MythContext available.
@ GENERIC_EXIT_OK
Exited with no error.
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
static constexpr const char * MYTH_APPNAME_MYTHBACKEND
int main(int argc, char **argv)
static constexpr long UNUSED_FILENO
int handle_command(const MythBackendCommandLineParser &cmdline)
int run_backend(MythBackendCommandLineParser &cmdline)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
void InitializeMythDirs(void)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
void setHttpProxy(void)
Get network proxy settings from OS, and use for [Q]Http[Comms].
MythCommFlagCommandLineParser cmdline
static QString cleanup(const QString &str)