Skip to content

Commit 50493ef

Browse files
committed
Move all setting strings to single-instance variables
Make a named variable for each setting, and use the variable instead of using the setting in any string literal that refers to the setting (eg error messages). This should make localisation (translation) easier down the line, and also provides simple ways to find out where code handling particular settings can be found (without having to resort to text search).
1 parent 52cfebb commit 50493ef

File tree

3 files changed

+218
-125
lines changed

3 files changed

+218
-125
lines changed

src/includes/dinit-settings.h

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// Service settings definitions/declarations.
2+
3+
#ifndef DINIT_SETTINGS_H
4+
#define DINIT_SETTINGS_H 1
5+
6+
#include <mconfig.h>
7+
#include <static-string.h>
8+
9+
namespace dinit_load {
10+
namespace setting_str {
11+
12+
// These are the authoritative definitions of the setting names. Setting names should not appear
13+
// as literals elsewhere. These definitions can be used to concatenate message strings (for error
14+
// messages etc). Standalone setting names should instead be taken from the all_settings array,
15+
// to prevent duplicated strings in the compiled executable binaries.
16+
constexpr auto str_type = cts::literal("type");
17+
constexpr auto str_command = cts::literal("command");
18+
constexpr auto str_working_dir = cts::literal("working-dir");
19+
constexpr auto str_env_file = cts::literal("env-file");
20+
constexpr auto str_socket_listen = cts::literal("socket-listen");
21+
constexpr auto str_socket_permissions = cts::literal("socket-permissions");
22+
constexpr auto str_socket_uid = cts::literal("socket-uid");
23+
constexpr auto str_socket_gid = cts::literal("socket-gid");
24+
constexpr auto str_stop_command = cts::literal("stop-command");
25+
constexpr auto str_pid_file = cts::literal("pid-file");
26+
constexpr auto str_depends_on = cts::literal("depends-on");
27+
constexpr auto str_depends_ms = cts::literal("depends-ms");
28+
constexpr auto str_waits_for = cts::literal("waits-for");
29+
constexpr auto str_waits_for_d = cts::literal("waits-for.d");
30+
constexpr auto str_depends_on_d = cts::literal("depends-on.d");
31+
constexpr auto str_depends_ms_d = cts::literal("depends-ms.d");
32+
constexpr auto str_after = cts::literal("after");
33+
constexpr auto str_before = cts::literal("before");
34+
constexpr auto str_logfile = cts::literal("logfile");
35+
constexpr auto str_logfile_permissions = cts::literal("logfile-permissions");
36+
constexpr auto str_logfile_uid = cts::literal("logfile-uid");
37+
constexpr auto str_logfile_gid = cts::literal("logfile-gid");
38+
constexpr auto str_log_type = cts::literal("log-type");
39+
constexpr auto str_log_buffer_size = cts::literal("log-buffer-size");
40+
constexpr auto str_consumer_of = cts::literal("consumer-of");
41+
constexpr auto str_restart = cts::literal("restart");
42+
constexpr auto str_smooth_recovery = cts::literal("smooth-recovery");
43+
constexpr auto str_options = cts::literal("options");
44+
constexpr auto str_load_options = cts::literal("load-options");
45+
constexpr auto str_term_signal = cts::literal("term-signal");
46+
constexpr auto str_termsignal = cts::literal("termsignal"); // (deprecated)
47+
constexpr auto str_restart_limit_interval = cts::literal("restart-limit-interval");
48+
constexpr auto str_restart_delay = cts::literal("restart-delay");
49+
constexpr auto str_restart_limit_count = cts::literal("restart-limit-count");
50+
constexpr auto str_stop_timeout = cts::literal("stop-timeout");
51+
constexpr auto str_start_timeout = cts::literal("start-timeout");
52+
constexpr auto str_run_as = cts::literal("run-as");
53+
constexpr auto str_chain_to = cts::literal("chain-to");
54+
constexpr auto str_ready_notification = cts::literal("ready-notification");
55+
constexpr auto str_inittab_id = cts::literal("inittab-id");
56+
constexpr auto str_inittab_line = cts::literal("inittab-line");
57+
constexpr auto str_rlimit_nofile = cts::literal("rlimit-nofile");
58+
constexpr auto str_rlimit_core = cts::literal("rlimit-core");
59+
constexpr auto str_rlimit_data = cts::literal("rlimit-data");
60+
constexpr auto str_rlimit_addrspace = cts::literal("rlimit-addrspace");
61+
constexpr auto str_nice = cts::literal("nice");
62+
63+
#if SUPPORT_CGROUPS
64+
constexpr auto str_run_in_cgroup = cts::literal("run-in-cgroup");
65+
#endif
66+
67+
#if SUPPORT_CAPABILITIES
68+
constexpr auto str_capabilities = cts::literal("capabilities");
69+
constexpr auto str_securebits = cts::literal("securebits");
70+
#endif
71+
72+
#if SUPPORT_IOPRIO
73+
constexpr auto str_ioprio = cts::literal("ioprio");
74+
#endif
75+
76+
#if SUPPORT_OOM_ADJ
77+
constexpr auto str_oom_score_adj = cts::literal("oom-score-adj");
78+
#endif
79+
80+
} // namespace dinit_load::setting_str
81+
82+
// The setting ids - these correspond to the index of the setting within the all_settings array.
83+
enum class setting_id_t {
84+
LAST = -1, // used to indicate end of settings
85+
TYPE, COMMAND, WORKING_DIR, ENV_FILE, SOCKET_LISTEN, SOCKET_PERMISSIONS, SOCKET_UID,
86+
SOCKET_GID, STOP_COMMAND, PID_FILE, DEPENDS_ON, DEPENDS_MS, WAITS_FOR, WAITS_FOR_D,
87+
DEPENDS_ON_D, DEPENDS_MS_D, AFTER, BEFORE, LOGFILE, LOGFILE_PERMISSIONS, LOGFILE_UID,
88+
LOGFILE_GID, LOG_TYPE, LOG_BUFFER_SIZE, CONSUMER_OF, RESTART, SMOOTH_RECOVERY, OPTIONS,
89+
LOAD_OPTIONS, TERM_SIGNAL, TERMSIGNAL /* deprecated */, RESTART_LIMIT_INTERVAL, RESTART_DELAY,
90+
RESTART_LIMIT_COUNT, STOP_TIMEOUT, START_TIMEOUT, RUN_AS, CHAIN_TO, READY_NOTIFICATION,
91+
INITTAB_ID, INITTAB_LINE, NICE,
92+
// Prefixed with SETTING_ to avoid name collision with system macros:
93+
SETTING_RLIMIT_NOFILE, SETTING_RLIMIT_CORE, SETTING_RLIMIT_DATA, SETTING_RLIMIT_ADDRSPACE,
94+
// Possibly unsupported depending on platform/build options:
95+
#if SUPPORT_CGROUPS
96+
RUN_IN_CGROUP,
97+
#endif
98+
#if SUPPORT_CAPABILITIES
99+
CAPABILITIES,
100+
SECUREBITS,
101+
#endif
102+
#if SUPPORT_IOPRIO
103+
IOPRIO,
104+
#endif
105+
#if SUPPORT_OOM_ADJ
106+
OOM_SCORE_ADJ,
107+
#endif
108+
};
109+
110+
struct setting_details {
111+
const char *setting_str; // (may be null for blank entry)
112+
setting_id_t setting_id;
113+
bool supp_colon : 1; // supports ':' assignment
114+
bool supp_assign : 1; // supports '=' assignment
115+
bool supp_plus_assign : 1; // supports '+=' assignment operator
116+
// Note: if '=' not supported but ':' is, '=' maps to ':' for backwards compatibility
117+
};
118+
119+
extern setting_details all_settings[];
120+
121+
}
122+
123+
#endif

0 commit comments

Comments
 (0)