2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2015-04-04 17:43:56 +00:00
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2015-04-04 17:43:56 +00:00
|
|
|
|
2024-02-25 22:12:08 +00:00
|
|
|
#include <cstdio>
|
2022-09-13 06:37:12 +00:00
|
|
|
#include <string>
|
2015-04-04 17:43:56 +00:00
|
|
|
|
2023-07-08 15:24:03 +00:00
|
|
|
#ifdef HAVE_SYS_SIGNALFD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2022-09-13 06:37:12 +00:00
|
|
|
#include <libtransmission/variant.h>
|
2023-07-08 15:24:03 +00:00
|
|
|
#include <libtransmission/quark.h>
|
|
|
|
|
2024-01-11 13:20:22 +00:00
|
|
|
struct event_base;
|
2023-07-08 15:24:03 +00:00
|
|
|
struct tr_error;
|
|
|
|
struct tr_session;
|
2022-09-13 06:37:12 +00:00
|
|
|
|
|
|
|
class tr_daemon
|
2015-04-04 17:43:56 +00:00
|
|
|
{
|
2022-09-13 06:37:12 +00:00
|
|
|
public:
|
|
|
|
tr_daemon() = default;
|
|
|
|
|
|
|
|
~tr_daemon()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SYS_SIGNALFD_H
|
|
|
|
if (sigfd_ != -1)
|
|
|
|
{
|
|
|
|
close(sigfd_);
|
|
|
|
}
|
|
|
|
#endif /* signalfd API */
|
|
|
|
}
|
|
|
|
|
2023-11-04 16:39:41 +00:00
|
|
|
bool spawn(bool foreground, int* exit_code, tr_error& error);
|
2022-12-21 20:21:16 +00:00
|
|
|
bool init(int argc, char const* const argv[], bool* foreground, int* ret);
|
2023-11-04 16:39:41 +00:00
|
|
|
void handle_error(tr_error const&) const;
|
2022-09-13 06:37:12 +00:00
|
|
|
int start(bool foreground);
|
|
|
|
void periodic_update();
|
|
|
|
void reconfigure();
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
private:
|
|
|
|
#ifdef HAVE_SYS_SIGNALFD_H
|
|
|
|
int sigfd_ = -1;
|
|
|
|
#endif /* signalfd API */
|
|
|
|
bool seen_hup_ = false;
|
|
|
|
std::string config_dir_;
|
|
|
|
tr_variant settings_ = {};
|
|
|
|
tr_session* my_session_ = nullptr;
|
|
|
|
char const* log_file_name_ = nullptr;
|
|
|
|
struct event_base* ev_base_ = nullptr;
|
2024-02-25 22:12:08 +00:00
|
|
|
FILE* log_stream_ = nullptr;
|
2024-01-07 17:12:31 +00:00
|
|
|
|
2022-12-21 20:21:16 +00:00
|
|
|
bool parse_args(int argc, char const* const* argv, bool* dump_settings, bool* foreground, int* exit_code);
|
2022-09-13 06:37:12 +00:00
|
|
|
bool reopen_log_file(char const* filename);
|
2023-07-07 22:18:38 +00:00
|
|
|
bool setup_signals(struct event*& sig_ev);
|
|
|
|
void cleanup_signals(struct event* sig_ev) const;
|
2022-09-13 06:37:12 +00:00
|
|
|
void report_status();
|
|
|
|
};
|