| | varnish-cache/bin/varnishd/mgt/mgt.h |
| 0 |
|
/*- |
| 1 |
|
* Copyright (c) 2006 Verdens Gang AS |
| 2 |
|
* Copyright (c) 2006-2011 Varnish Software AS |
| 3 |
|
* All rights reserved. |
| 4 |
|
* |
| 5 |
|
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk> |
| 6 |
|
* |
| 7 |
|
* SPDX-License-Identifier: BSD-2-Clause |
| 8 |
|
* |
| 9 |
|
* Redistribution and use in source and binary forms, with or without |
| 10 |
|
* modification, are permitted provided that the following conditions |
| 11 |
|
* are met: |
| 12 |
|
* 1. Redistributions of source code must retain the above copyright |
| 13 |
|
* notice, this list of conditions and the following disclaimer. |
| 14 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 15 |
|
* notice, this list of conditions and the following disclaimer in the |
| 16 |
|
* documentation and/or other materials provided with the distribution. |
| 17 |
|
* |
| 18 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 19 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
| 22 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 24 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 26 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 27 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 |
|
* SUCH DAMAGE. |
| 29 |
|
* |
| 30 |
|
*/ |
| 31 |
|
|
| 32 |
|
#ifdef MGT_MGT_H |
| 33 |
|
#error "Multiple includes of mgt/mgt.h" |
| 34 |
|
#endif |
| 35 |
|
#define MGT_MGT_H |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
#include <stdint.h> |
| 39 |
|
|
| 40 |
|
#include "string.h" |
| 41 |
|
#include <sys/types.h> |
| 42 |
|
|
| 43 |
|
#include "vdef.h" |
| 44 |
|
|
| 45 |
|
#include "miniobj.h" |
| 46 |
|
#include "vas.h" |
| 47 |
|
#include "vcs.h" |
| 48 |
|
#include "vqueue.h" |
| 49 |
|
#include "vsb.h" |
| 50 |
|
|
| 51 |
|
#include "common/common_param.h" |
| 52 |
|
|
| 53 |
|
struct vjsn; |
| 54 |
|
struct vsc_seg; |
| 55 |
|
struct vsmw_cluster; |
| 56 |
|
#include "VSC_mgt.h" |
| 57 |
|
|
| 58 |
|
struct cli; |
| 59 |
|
struct parspec; |
| 60 |
|
struct vcc; |
| 61 |
|
struct vclprog; |
| 62 |
|
|
| 63 |
|
extern struct vev_root *mgt_evb; |
| 64 |
|
extern unsigned d_flag; |
| 65 |
|
extern int exit_status; |
| 66 |
|
|
| 67 |
|
/* option=value argument parse helper */ |
| 68 |
|
static inline const char * |
| 69 |
1160 |
keyval(const char *p, const char *name) |
| 70 |
|
{ |
| 71 |
1160 |
size_t l = strlen(name); |
| 72 |
1160 |
if (strncmp(p, name, l)) |
| 73 |
640 |
return (NULL); |
| 74 |
520 |
return (p + l); |
| 75 |
1160 |
} |
| 76 |
|
|
| 77 |
|
/* builtin_vcl.c */ |
| 78 |
|
|
| 79 |
|
extern const char * const builtin_vcl; |
| 80 |
|
|
| 81 |
|
/* mgt_child.c */ |
| 82 |
|
void MCH_Init(void); |
| 83 |
|
int MCH_Running(void); |
| 84 |
|
void MCH_Stop_Child(void); |
| 85 |
|
int MCH_Start_Child(void); |
| 86 |
|
void MCH_TrackHighFd(int fd); |
| 87 |
|
void MCH_Cli_Fail(void); |
| 88 |
|
|
| 89 |
|
/* mgt_cli.c */ |
| 90 |
|
extern struct VCLS *mgt_cls; |
| 91 |
|
|
| 92 |
|
typedef int mgt_cli_close_f(void *priv); |
| 93 |
|
void mgt_cli_setup(int fdi, int fdo, int auth, const char *ident, |
| 94 |
|
mgt_cli_close_f *close_func, void *priv); |
| 95 |
|
int mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...) |
| 96 |
|
v_printflike_(3, 4); |
| 97 |
|
unsigned mgt_cli_start_child(int fd, double tmo); |
| 98 |
|
void mgt_cli_stop_child(void); |
| 99 |
|
void mgt_cli_telnet(const char *T_arg); |
| 100 |
|
void mgt_cli_master(const char *M_arg); |
| 101 |
|
void mgt_cli_secret(const char *S_arg); |
| 102 |
|
void mgt_cli_close_all(void); |
| 103 |
|
void mgt_DumpRstCli(void); |
| 104 |
|
void mgt_cli_init_cls(void); |
| 105 |
|
#define MCF_NOAUTH 0 /* NB: zero disables here-documents */ |
| 106 |
|
#define MCF_AUTH 16 |
| 107 |
|
|
| 108 |
|
/* mgt_jail.c */ |
| 109 |
|
|
| 110 |
|
enum jail_master_e { |
| 111 |
|
JAIL_MASTER_LOW = 0, |
| 112 |
|
JAIL_MASTER_SYSTEM, |
| 113 |
|
JAIL_MASTER_FILE, |
| 114 |
|
JAIL_MASTER_STORAGE, |
| 115 |
|
JAIL_MASTER_PRIVPORT, |
| 116 |
|
JAIL_MASTER_KILL, |
| 117 |
|
#define JAIL_SUBPROC (JAIL_MASTER_KILL + 1) |
| 118 |
|
}; |
| 119 |
|
|
| 120 |
|
enum jail_subproc_e { |
| 121 |
|
JAIL_SUBPROC_VCC = JAIL_SUBPROC, |
| 122 |
|
JAIL_SUBPROC_CC, |
| 123 |
|
JAIL_SUBPROC_VCLLOAD, |
| 124 |
|
JAIL_SUBPROC_WORKER, |
| 125 |
|
#define JAIL_LIMIT (JAIL_SUBPROC_WORKER + 1) |
| 126 |
|
}; |
| 127 |
|
|
| 128 |
|
#define ASSERT_JAIL_MASTER(x) assert((x) < JAIL_SUBPROC) |
| 129 |
|
|
| 130 |
|
#define ASSERT_JAIL_SUBPROC(x) do { \ |
| 131 |
|
assert((x) >= JAIL_SUBPROC); \ |
| 132 |
|
assert((x) < JAIL_LIMIT); \ |
| 133 |
|
} while (0) |
| 134 |
|
|
| 135 |
|
enum jail_fixfd_e { |
| 136 |
|
JAIL_FIXFD_FILE, |
| 137 |
|
JAIL_FIXFD_VSMMGT, |
| 138 |
|
JAIL_FIXFD_VSMWRK, |
| 139 |
|
JAIL_FIXFD_WRKTMP, |
| 140 |
|
}; |
| 141 |
|
|
| 142 |
|
typedef int jail_init_f(char **); |
| 143 |
|
typedef void jail_master_f(enum jail_master_e); |
| 144 |
|
typedef void jail_subproc_f(enum jail_subproc_e); |
| 145 |
|
typedef int jail_make_dir_f(const char *, const char *, struct vsb *); |
| 146 |
|
typedef void jail_fixfd_f(int, enum jail_fixfd_e); |
| 147 |
|
|
| 148 |
|
struct jail_tech { |
| 149 |
|
unsigned magic; |
| 150 |
|
#define JAIL_TECH_MAGIC 0x4d00fa4d |
| 151 |
|
const char *name; |
| 152 |
|
jail_init_f *init; |
| 153 |
|
jail_master_f *master; |
| 154 |
|
jail_subproc_f *subproc; |
| 155 |
|
jail_make_dir_f *make_workdir; |
| 156 |
|
jail_make_dir_f *make_subdir; |
| 157 |
|
jail_fixfd_f *fixfd; |
| 158 |
|
}; |
| 159 |
|
|
| 160 |
|
void VJ_Init(const char *); |
| 161 |
|
void VJ_master(enum jail_master_e); |
| 162 |
|
void VJ_subproc(enum jail_subproc_e); |
| 163 |
|
int VJ_make_workdir(const char *, struct vsb *); |
| 164 |
|
int VJ_make_subdir(const char *, const char *, struct vsb *); |
| 165 |
|
void VJ_fix_fd(int, enum jail_fixfd_e); |
| 166 |
|
void VJ_unlink(const char *, int); |
| 167 |
|
void VJ_rmdir(const char *); |
| 168 |
|
|
| 169 |
|
extern const struct jail_tech jail_tech_unix; |
| 170 |
|
extern const struct jail_tech jail_tech_solaris; |
| 171 |
|
extern const struct jail_tech jail_tech_linux; |
| 172 |
|
|
| 173 |
|
/* mgt_main.c */ |
| 174 |
|
extern struct vsb *vident; |
| 175 |
|
extern struct VSC_mgt *VSC_C_mgt; |
| 176 |
|
struct choice { |
| 177 |
|
const char *name; |
| 178 |
|
const void *ptr; |
| 179 |
|
}; |
| 180 |
|
|
| 181 |
|
extern const char C_ERR[]; // Things are not as they should be |
| 182 |
|
extern const char C_INFO[]; // Normal stuff, keep a record for later |
| 183 |
|
extern const char C_DEBUG[]; // More detail than you'd normally want |
| 184 |
|
extern const char C_SECURITY[]; // Security issues |
| 185 |
|
extern const char C_CLI[]; // CLI traffic between master and child |
| 186 |
|
extern int complain_to_stderr; |
| 187 |
|
|
| 188 |
|
/* mgt_param.c */ |
| 189 |
|
void MCF_InitParams(struct cli *); |
| 190 |
|
enum mcf_which_e { |
| 191 |
|
MCF_DEFAULT = 32, |
| 192 |
|
MCF_MINIMUM = 33, |
| 193 |
|
MCF_MAXIMUM = 34, |
| 194 |
|
}; |
| 195 |
|
void MCF_ParamConf(enum mcf_which_e, const char *param, const char *, ...) |
| 196 |
|
v_printflike_(3, 4); |
| 197 |
|
|
| 198 |
|
void MCF_ParamSet(struct cli *, const char *param, const char *val); |
| 199 |
|
void MCF_ParamProtect(struct cli *, const char *arg); |
| 200 |
|
void MCF_DumpRstParam(void); |
| 201 |
|
extern struct params mgt_param; |
| 202 |
|
|
| 203 |
|
/* mgt_shmem.c */ |
| 204 |
|
void mgt_SHM_Init(void); |
| 205 |
|
void mgt_SHM_static_alloc(const void *, ssize_t size, |
| 206 |
|
const char *category, const char *ident); |
| 207 |
|
void mgt_SHM_Create(void); |
| 208 |
|
void mgt_SHM_Destroy(int keep); |
| 209 |
|
|
| 210 |
|
void mgt_SHM_ChildNew(void); |
| 211 |
|
void mgt_SHM_ChildDestroy(void); |
| 212 |
|
|
| 213 |
|
/* mgt_param_tcp.c */ |
| 214 |
|
void MCF_TcpParams(void); |
| 215 |
|
|
| 216 |
|
/* mgt_util.c */ |
| 217 |
|
char *mgt_HostName(void); |
| 218 |
|
void mgt_ProcTitle(const char *comp); |
| 219 |
|
void mgt_DumpRstVsl(void); |
| 220 |
|
struct vsb *mgt_BuildVident(void); |
| 221 |
|
void MGT_ComplainVSB(const char *, struct vsb *vsb); |
| 222 |
|
void MGT_Complain(const char *, const char *, ...) v_printflike_(2, 3); |
| 223 |
|
const void *MGT_Pick(const struct choice *, const char *, const char *); |
| 224 |
|
char **MGT_NamedArg(const char *, const char **, const char *); |
| 225 |
|
|
| 226 |
|
|
| 227 |
|
/* stevedore_mgt.c */ |
| 228 |
|
extern const char *mgt_stv_h2_rxbuf; |
| 229 |
|
void STV_Config(const char *spec); |
| 230 |
|
void STV_Config_Final(void); |
| 231 |
|
void STV_Init(void); |
| 232 |
|
|
| 233 |
|
/* mgt_vcc.c */ |
| 234 |
|
void mgt_DumpBuiltin(void); |
| 235 |
|
char *mgt_VccCompile(struct cli *, struct vclprog *, const char *vclname, |
| 236 |
|
const char *vclsrc, const char *vclsrcfile, int C_flag); |
| 237 |
|
|
| 238 |
|
void mgt_vcl_init(void); |
| 239 |
|
void mgt_vcl_startup(struct cli *, const char *vclsrc, const char *origin, |
| 240 |
|
const char *vclname, int Cflag); |
| 241 |
|
int mgt_push_vcls(struct cli *, unsigned *status, char **p); |
| 242 |
|
const char *mgt_has_vcl(void); |
| 243 |
|
extern char *mgt_cc_cmd; |
| 244 |
|
extern char *mgt_cc_cmd_def; |
| 245 |
|
extern char *mgt_cc_warn; |
| 246 |
|
extern const char *mgt_vcl_path; |
| 247 |
|
extern const char *mgt_vmod_path; |
| 248 |
|
|
| 249 |
|
#if defined(PTHREAD_CANCELED) || defined(PTHREAD_MUTEX_DEFAULT) |
| 250 |
|
#error "Keep pthreads out of the manager process" |
| 251 |
|
#endif |
| 252 |
|
|
| 253 |
|
//lint -e{401} deliberate conflict triggers flexelint |
| 254 |
|
static inline void |
| 255 |
|
pthread_create(void) |
| 256 |
|
{ |
| 257 |
|
|
| 258 |
|
WRONG("Intentional conflict with pthread.h"); |
| 259 |
|
} |
| 260 |
|
|
| 261 |
|
#define MGT_FEATURE(x) COM_FEATURE(mgt_param.feature_bits, x) |
| 262 |
|
#define MGT_EXPERIMENT(x) COM_EXPERIMENT(mgt_param.experimental_bits, x) |
| 263 |
|
#define MGT_DO_DEBUG(x) COM_DO_DEBUG(mgt_param.debug_bits, x) |
| 264 |
|
#define MGT_VCC_FEATURE(x) COM_VCC_FEATURE(mgt_param.vcc_feature_bits, x) |