2 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
3 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
5 #include "cmogstored.h"
10 const char *param
, const char *a_orig
, const char *b_orig
,
11 enum canonicalize_mode_t canon_mode
)
13 char *a
= mog_canonpath_die(a_orig
, canon_mode
);
14 char *b
= mog_canonpath_die(b_orig
, canon_mode
);
15 int ok
= (strcmp(a
, b
) == 0);
22 die("conflicting path values for %s: `%s' != `%s'",
23 param
, a_orig
, b_orig
);
26 static void merge_addr(struct mog_addrinfo
**dst
, struct mog_addrinfo
*src
)
28 if (!*dst
&& src
) *dst
= mog_listen_parse(src
->orig
);
31 static void merge_str(const char **dst
, const char *src
)
33 if (!*dst
&& src
) *dst
= xstrdup(src
);
36 static void validate_merge_common(struct mog_cfg
*ent
, struct mog_cfg
*cli
)
38 merge_addr(&cli
->mgmtlisten
, ent
->mgmtlisten
);
39 merge_addr(&cli
->httplisten
, ent
->httplisten
);
40 merge_addr(&cli
->httpgetlisten
, ent
->httpgetlisten
);
42 /* multiple config files can all specify the same pidfile */
43 if (cli
->pidfile
&& ent
->pidfile
)
44 paths_eql_or_die("pidfile", cli
->pidfile
, ent
->pidfile
,
46 merge_str(&cli
->pidfile
, ent
->pidfile
);
48 cli
->maxconns
+= ent
->maxconns
;
49 cli
->daemonize
|= ent
->daemonize
;
52 bool mog_cfg_validate_one(void *ent_ptr
, void *cli_ptr
)
54 struct mog_cfg
*ent
= ent_ptr
;
55 struct mog_cfg
*cli
= cli_ptr
;
58 * in the mixed single config file + CLI usage case, ensure docroot
59 * is the same (or only specified in one
61 if (cli
->docroot
&& ent
->docroot
)
62 paths_eql_or_die("docroot", cli
->docroot
, ent
->docroot
,
64 merge_str(&cli
->docroot
, ent
->docroot
);
66 validate_merge_common(ent
, cli
);
71 bool mog_cfg_validate_multi(void *ent_ptr
, void *cli_ptr
)
73 struct mog_cfg
*ent
= ent_ptr
;
74 struct mog_cfg
*cli
= cli_ptr
;
77 die("BUG: no config path");
78 if (!ent
->httplisten
&& !ent
->mgmtlisten
&& !ent
->httpgetlisten
)
79 die("no listeners in --config=%s", ent
->configfile
);
81 die("no docroot in --config=%s", ent
->configfile
);
83 validate_merge_common(ent
, cli
);
88 static void warn_daemonize(size_t *nerr
, const char *key
, const char *val
)
90 warn("%s=%s must use an absolute path", key
, val
);
94 bool mog_cfg_validate_daemon(void *ent_ptr
, void *nerr
)
96 struct mog_cfg
*ent
= ent_ptr
;
98 if (ent
->config
&& ent
->config
[0] != '/')
99 warn_daemonize(nerr
, "config", ent
->config
);
100 if (ent
->pidfile
&& ent
->pidfile
[0] != '/')
101 warn_daemonize(nerr
, "pidfile", ent
->pidfile
);
102 if (ent
->docroot
&& ent
->docroot
[0] != '/')
103 warn_daemonize(nerr
, "docroot", ent
->docroot
);
108 static void die_if_set(const void *a
, const char *sw
)
111 die("--%s may not be used with multiple --config files", sw
);
115 * some settings we can't make sense of when supporting multiple
118 void mog_cfg_die_if_cli_set(struct mog_cfg
*cli
)
120 die_if_set(cli
->docroot
, "docroot");
121 die_if_set(cli
->httplisten
, "httplisten");
122 die_if_set(cli
->mgmtlisten
, "mgmtlisten");
124 /* we don't actually support --httpgetlisten on the CLI ... */
125 die_if_set(cli
->httpgetlisten
, "httpgetlisten");
128 void mog_cfg_merge_defaults(struct mog_cfg
*cli
)
131 cli
->docroot
= xstrdup(MOG_DEFAULT_DOCROOT
);
133 /* default listeners */
134 if (!cli
->httplisten
&& !cli
->httpgetlisten
&& !cli
->mgmtlisten
) {
135 cli
->httplisten
= mog_listen_parse(MOG_DEFAULT_HTTPLISTEN
);
136 cli
->mgmtlisten
= mog_listen_parse(MOG_DEFAULT_MGMTLISTEN
);
140 void mog_cfg_check_server(struct mog_cfg
*cfg
)
142 const char *s
= cfg
->server
;
146 if (strcmp(s
, "none") == 0) return;
147 if (strcmp(s
, "perlbal") == 0)
148 warn("W: using internal HTTP for 'server = perlbal' instead");
150 die("E: 'server = %s' not understood by cmogstored", s
);