varnish-cache/bin/varnishtest/vtest2/src/vtc_haproxy.c
0
/*-
1
 * Copyright (c) 2008-2018 Varnish Software AS
2
 * All rights reserved.
3
 *
4
 * Author: Frédéric Lécaille <flecaille@haproxy.com>
5
 *
6
 * SPDX-License-Identifier: BSD-2-Clause
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 */
29
30
#include "config.h"
31
32
#include <inttypes.h>
33
#include <poll.h>
34
#include <stdio.h>
35
#include <stdlib.h>
36
#include <string.h>
37
#include <sys/stat.h> /* for MUSL (mode_t) */
38
#include <sys/types.h>
39
#include <sys/socket.h>
40
#include <sys/un.h>
41
#include <unistd.h>
42
43
#include "vtc.h"
44
45
#include "vfil.h"
46
#include "vpf.h"
47
#include "vre.h"
48
#include "vtcp.h"
49
#include "vsa.h"
50
#include "vtim.h"
51
52
#define HAPROXY_PROGRAM_ENV_VAR "HAPROXY_PROGRAM"
53
#define HAPROXY_ARGS_ENV_VAR    "HAPROXY_ARGS"
54
#define HAPROXY_OPT_WORKER      "-W"
55
#define HAPROXY_OPT_SD_WORKER   "-Ws"
56
#define HAPROXY_OPT_MCLI        "-S"
57
#define HAPROXY_OPT_DAEMON      "-D"
58
#define HAPROXY_SIGNAL          SIGINT
59
#define HAPROXY_EXPECT_EXIT     (128 + HAPROXY_SIGNAL)
60
61
struct envar {
62
        VTAILQ_ENTRY(envar) list;
63
        char *name;
64
        char *value;
65
};
66
67
struct haproxy {
68
        unsigned                magic;
69
#define HAPROXY_MAGIC           0x8a45cf75
70
        char                    *name;
71
        struct vtclog           *vl;
72
        VTAILQ_ENTRY(haproxy)   list;
73
74
        const char              *filename;
75
        struct vsb              *args;
76
        int                     opt_worker;
77
        int                     opt_mcli;
78
        int                     opt_daemon;
79
        int                     opt_check_mode;
80
        char                    *pid_fn;
81
        pid_t                   pid;
82
        pid_t                   ppid;
83
        int                     fds[4];
84
        char                    *cfg_fn;
85
        struct vsb              *cfg_vsb;
86
87
        pthread_t               tp;
88
        int                     expect_exit;
89
        int                     expect_signal;
90
        int                     its_dead_jim;
91
92
        /* sd_notify unix socket */
93
        struct sockaddr_un      sd_uds;
94
        int                     sd_sock;
95
96
        /* UNIX socket CLI. */
97
        char                    *cli_fn;
98
        /* TCP socket CLI. */
99
        struct haproxy_cli *cli;
100
101
        /* master CLI */
102
        struct haproxy_cli *mcli;
103
104
        char                    *workdir;
105
        struct vsb              *msgs;
106
        char                    closed_sock[256]; /* Closed TCP socket */
107
        VTAILQ_HEAD(,envar) envars;
108
};
109
110
static VTAILQ_HEAD(, haproxy)   haproxies =
111
    VTAILQ_HEAD_INITIALIZER(haproxies);
112
113
struct haproxy_cli {
114
        unsigned                magic;
115
#define HAPROXY_CLI_MAGIC       0xb09a4ed8
116
        struct vtclog           *vl;
117
        char                    running;
118
119
        char                    *spec;
120
121
        int                     sock;
122
        char                    connect[256];
123
124
        pthread_t               tp;
125
        size_t                  txbuf_sz;
126
        char                    *txbuf;
127
        size_t                  rxbuf_sz;
128
        char                    *rxbuf;
129
130
        vtim_dur                timeout;
131
};
132
133
static void haproxy_write_conf(struct haproxy *h);
134
135
static void
136
haproxy_add_envar(struct haproxy *h,
137 38
                  const char *name, const char *value)
138
{
139
        struct envar *e;
140
141
        e = malloc(sizeof *e);
142 38
        AN(e);
143 38
        e->name = strdup(name);
144 38
        e->value = strdup(value);
145 38
        AN(e->name);
146 38
        AN(e->value);
147 38
        VTAILQ_INSERT_TAIL(&h->envars, e, list);
148 38
}
149 38
150
static void
151
haproxy_delete_envars(struct haproxy *h)
152 22
{
153
        struct envar *e, *e2;
154
        VTAILQ_FOREACH_SAFE(e, &h->envars, list, e2) {
155 60
                VTAILQ_REMOVE(&h->envars, e, list);
156 38
                free(e->name);
157 38
                free(e->value);
158 38
                free(e);
159 38
        }
160 38
}
161 22
162
static void
163
haproxy_build_env(const struct haproxy *h)
164 22
{
165
        struct envar *e;
166
167
        VTAILQ_FOREACH(e, &h->envars, list) {
168 60
                if (setenv(e->name, e->value, 0) == -1)
169 38
                        vtc_fatal(h->vl, "setenv() failed: %s (%d)",
170 0
                                  strerror(errno), errno);
171 0
        }
172 38
}
173 22
174
/**********************************************************************
175
 * Socket connect (same as client_tcp_connect()).
176
 */
177
178
static int
179
haproxy_cli_tcp_connect(struct vtclog *vl, const char *addr, vtim_dur tmo,
180 4
    const char **errp)
181
{
182
        int fd;
183
        char mabuf[VTCP_ADDRBUFSIZE], mpbuf[VTCP_PORTBUFSIZE];
184
185
        AN(addr);
186 4
        AN(errp);
187 4
        fd = VTCP_open(addr, NULL, tmo, errp);
188 4
        if (fd < 0)
189 4
                return (fd);
190 0
        VTCP_myname(fd, mabuf, sizeof mabuf, mpbuf, sizeof mpbuf);
191 4
        vtc_log(vl, 3,
192 8
            "CLI connected fd %d from %s %s to %s", fd, mabuf, mpbuf, addr);
193 4
        return (fd);
194 4
}
195 4
196
/*
197
 * SECTION: haproxy.cli haproxy CLI Specification
198
 * SECTION: haproxy.cli.send
199
 * send STRING
200
 *         Push STRING on the CLI connection. STRING will be terminated by an
201
 *         end of line character (\n).
202
 */
203
static void v_matchproto_(cmd_f)
204
cmd_haproxy_cli_send(CMD_ARGS)
205 4
{
206
        struct vsb *vsb;
207
        struct haproxy_cli *hc;
208
        int j;
209
210
        (void)vl;
211 4
        CAST_OBJ_NOTNULL(hc, priv, HAPROXY_CLI_MAGIC);
212 4
        AZ(strcmp(av[0], "send"));
213 4
        AN(av[1]);
214 4
        AZ(av[2]);
215 4
216
        vsb = VSB_new_auto();
217 4
        AN(vsb);
218 4
        AZ(VSB_cat(vsb, av[1]));
219 4
        AZ(VSB_cat(vsb, "\n"));
220 4
        AZ(VSB_finish(vsb));
221 4
        if (hc->sock == -1) {
222 4
                int fd;
223
                const char *err;
224
                struct vsb *vsb_connect;
225
226
                vsb_connect = macro_expand(hc->vl, hc->connect);
227 0
                AN(vsb_connect);
228 0
                fd = haproxy_cli_tcp_connect(hc->vl,
229 0
                    VSB_data(vsb_connect), 10., &err);
230 0
                if (fd < 0)
231 0
                        vtc_fatal(hc->vl,
232 0
                            "CLI failed to open %s: %s", VSB_data(vsb), err);
233 0
                VSB_destroy(&vsb_connect);
234 0
                hc->sock = fd;
235 0
        }
236 0
        vtc_dump(hc->vl, 4, "CLI send", VSB_data(vsb), -1);
237 4
238
        if (VSB_tofile(vsb, hc->sock))
239 4
                vtc_fatal(hc->vl,
240 0
                    "CLI fd %d send error %s", hc->sock, strerror(errno));
241 0
242
        /* a CLI command must be followed by a SHUT_WR if we want HAProxy to
243
         * close after the response */
244
        j = shutdown(hc->sock, SHUT_WR);
245 4
        vtc_log(hc->vl, 3, "CLI shutting fd %d", hc->sock);
246 4
        if (!VTCP_Check(j))
247 4
                vtc_fatal(hc->vl, "Shutdown failed: %s", strerror(errno));
248 0
249
        VSB_destroy(&vsb);
250 4
}
251 4
252
#define HAPROXY_CLI_RECV_LEN (1 << 14)
253
static void
254
haproxy_cli_recv(struct haproxy_cli *hc)
255 4
{
256
        ssize_t ret;
257
        size_t rdz, left, off;
258
259
        rdz = ret = off = 0;
260 4
        /* We want to null terminate this buffer. */
261
        left = hc->rxbuf_sz - 1;
262 4
        while (!vtc_error && left > 0) {
263 8
                VTCP_set_read_timeout(hc->sock, hc->timeout);
264 8
265
                ret = recv(hc->sock, hc->rxbuf + off, HAPROXY_CLI_RECV_LEN, 0);
266 8
                if (ret < 0) {
267 8
                        if (errno == EINTR || errno == EAGAIN)
268 0
                                continue;
269 0
270
                        vtc_fatal(hc->vl,
271 0
                            "CLI fd %d recv() failed (%s)",
272
                            hc->sock, strerror(errno));
273 0
                }
274
                /* Connection closed. */
275
                if (ret == 0) {
276 8
                        if (rdz > 0 && hc->rxbuf[rdz - 1] != '\n')
277 4
                                vtc_fatal(hc->vl,
278 0
                                    "CLI rx timeout (fd: %d %.3fs ret: %zd)",
279
                                    hc->sock, hc->timeout, ret);
280 0
281
                        vtc_log(hc->vl, 4, "CLI connection normally closed");
282 4
                        vtc_log(hc->vl, 3, "CLI closing fd %d", hc->sock);
283 4
                        VTCP_close(&hc->sock);
284 4
                        break;
285 4
                }
286
287
                rdz += ret;
288 4
                left -= ret;
289 4
                off  += ret;
290 4
        }
291
        hc->rxbuf[rdz] = '\0';
292 4
        vtc_dump(hc->vl, 4, "CLI recv", hc->rxbuf, rdz);
293 4
}
294 4
295
/*
296
 * SECTION: haproxy.cli.expect
297
 * expect OP STRING
298
 *         Regex match the CLI reception buffer with STRING
299
 *         if OP is ~ or, on the contrary, if OP is !~ check that there is
300
 *         no regex match.
301
 */
302
static void v_matchproto_(cmd_f)
303
cmd_haproxy_cli_expect(CMD_ARGS)
304 4
{
305
        struct haproxy_cli *hc;
306
        struct vsb vsb[1];
307
        vre_t *vre;
308
        int error, erroroffset, i, ret;
309
        char *cmp, *spec, errbuf[VRE_ERROR_LEN];
310
311
        (void)vl;
312 4
        CAST_OBJ_NOTNULL(hc, priv, HAPROXY_CLI_MAGIC);
313 4
        AZ(strcmp(av[0], "expect"));
314 4
        av++;
315 4
316
        cmp = av[0];
317 4
        spec = av[1];
318 4
        AN(cmp);
319 4
        AN(spec);
320 4
        AZ(av[2]);
321 4
322
        assert(!strcmp(cmp, "~") || !strcmp(cmp, "!~"));
323 4
324
        haproxy_cli_recv(hc);
325 4
326
        vre = VRE_compile(spec, 0, &error, &erroroffset, 1);
327 4
        if (vre == NULL) {
328 4
                AN(VSB_init(vsb, errbuf, sizeof errbuf));
329 0
                AZ(VRE_error(vsb, error));
330 0
                AZ(VSB_finish(vsb));
331 0
                VSB_fini(vsb);
332 0
                vtc_fatal(hc->vl, "CLI regexp error: '%s' (@%d) (%s)",
333 0
                    errbuf, erroroffset, spec);
334 0
        }
335
336
        i = VRE_match(vre, hc->rxbuf, 0, 0, NULL);
337 4
338
        VRE_free(&vre);
339 4
340
        ret = (i >= 0 && *cmp == '~') || (i < 0 && *cmp == '!');
341 4
        if (!ret)
342 4
                vtc_fatal(hc->vl, "CLI expect failed %s \"%s\"", cmp, spec);
343 0
        else
344
                vtc_log(hc->vl, 4, "CLI expect match %s \"%s\"", cmp, spec);
345 4
}
346 4
347
static const struct cmds haproxy_cli_cmds[] = {
348
#define CMD_HAPROXY_CLI(n) { #n, cmd_haproxy_cli_##n },
349
        CMD_HAPROXY_CLI(send)
350
        CMD_HAPROXY_CLI(expect)
351
#undef CMD_HAPROXY_CLI
352
        { NULL, NULL }
353
};
354
355
/**********************************************************************
356
 * HAProxy CLI client thread
357
 */
358
359
static void *
360
haproxy_cli_thread(void *priv)
361 4
{
362
        struct haproxy_cli *hc;
363
        struct vsb *vsb;
364
        int fd;
365
        const char *err;
366
367
        CAST_OBJ_NOTNULL(hc, priv, HAPROXY_CLI_MAGIC);
368 4
        AN(*hc->connect);
369 4
370
        vsb = macro_expand(hc->vl, hc->connect);
371 4
        AN(vsb);
372 4
373
        fd = haproxy_cli_tcp_connect(hc->vl, VSB_data(vsb), 10., &err);
374 4
        if (fd < 0)
375 4
                vtc_fatal(hc->vl,
376 0
                    "CLI failed to open %s: %s", VSB_data(vsb), err);
377 0
        VTCP_blocking(fd);
378 4
        hc->sock = fd;
379 4
        parse_string(hc->vl, hc, hc->spec);
380 4
        vtc_log(hc->vl, 2, "CLI ending");
381 4
        VSB_destroy(&vsb);
382 4
        return (NULL);
383 4
}
384
385
/**********************************************************************
386
 * Wait for the CLI client thread to stop
387
 */
388
389
static void
390
haproxy_cli_wait(struct haproxy_cli *hc)
391 4
{
392
        void *res;
393
394
        CHECK_OBJ_NOTNULL(hc, HAPROXY_CLI_MAGIC);
395 4
        vtc_log(hc->vl, 2, "CLI waiting");
396 4
        PTOK(pthread_join(hc->tp, &res));
397 4
        if (res != NULL)
398 4
                vtc_fatal(hc->vl, "CLI returned \"%s\"", (char *)res);
399 0
        REPLACE(hc->spec, NULL);
400 4
        hc->tp = 0;
401 4
        hc->running = 0;
402 4
}
403 4
404
/**********************************************************************
405
 * Start the CLI client thread
406
 */
407
408
static void
409
haproxy_cli_start(struct haproxy_cli *hc)
410 4
{
411
        CHECK_OBJ_NOTNULL(hc, HAPROXY_CLI_MAGIC);
412 4
        vtc_log(hc->vl, 2, "CLI starting");
413 4
        PTOK(pthread_create(&hc->tp, NULL, haproxy_cli_thread, hc));
414 4
        hc->running = 1;
415 4
416
}
417 4
418
/**********************************************************************
419
 * Run the CLI client thread
420
 */
421
422
static void
423
haproxy_cli_run(struct haproxy_cli *hc)
424 4
{
425
        haproxy_cli_start(hc);
426 4
        haproxy_cli_wait(hc);
427 4
}
428 4
429
/**********************************************************************
430
 * Wait for the pidfile
431
 */
432
433
static void
434
haproxy_wait_pidfile(struct haproxy *h)
435 8
{
436
        char buf_err[1024] = {0};
437 8
        int usleep_time = 1000;
438 8
        double t0;
439
        pid_t pid;
440
441
        vtc_log(h->vl, 3, "wait-pid-file");
442 8
        for (t0 = VTIM_mono(); VTIM_mono() - t0 < 3;) {
443 287
                if (vtc_error)
444 287
                        return;
445 0
446
                if (VPF_Read(h->pid_fn, &pid) != 0) {
447 287
                        bprintf(buf_err,
448 279
                            "Could not read PID file '%s'", h->pid_fn);
449
                        usleep(usleep_time);
450 279
                        continue;
451 279
                }
452
453
                if (!h->opt_daemon && pid != h->pid) {
454 8
                        bprintf(buf_err,
455 0
                            "PID file has different PID (%ld != %lld)",
456
                            (long)pid, (long long)h->pid);
457
                        usleep(usleep_time);
458 0
                        continue;
459 0
                }
460
461
                if (kill(pid, 0) < 0) {
462 8
                        bprintf(buf_err,
463 0
                            "Could not find PID %ld process", (long)pid);
464
                        usleep(usleep_time);
465 0
                        continue;
466 0
                }
467
468
                h->pid = pid;
469 8
470
                vtc_log(h->vl, 2, "haproxy PID %ld successfully started",
471 16
                    (long)pid);
472 8
                return;
473 8
        }
474
        vtc_fatal(h->vl, "haproxy %s PID file check failed:\n\t%s\n",
475 0
                  h->name, buf_err);
476 0
}
477 8
478
/**********************************************************************
479
 * Bind the sd_notify socket
480
 */
481
static void
482
haproxy_bind_sdnotify(struct haproxy *h)
483 2
{
484
        char sd_path[PATH_MAX];
485
        int sd;
486
        int ret;
487
        const char *err = NULL;
488 2
        struct sockaddr_un *uds = &h->sd_uds;
489 2
        socklen_t sl = sizeof(*uds);
490 2
491
        bprintf(sd_path, "%s/sd_notify.sock", h->workdir);
492 2
        assert(sd_path[0] == '/');
493 2
494
        if (strlen(sd_path) + 1 > sizeof(uds->sun_path)) {
495 2
                vtc_fatal(h->vl, "Path %s too long for a Unix domain socket", sd_path);
496 0
        }
497
        memset(uds->sun_path, 0, sizeof(uds->sun_path));
498 2
        bprintf(uds->sun_path, "%s", sd_path);
499 2
        uds->sun_family = PF_UNIX;
500 2
501
        sd = socket(AF_UNIX, SOCK_DGRAM, 0);
502 2
        if (sd < 0) {
503 2
                err = "socket(2)";
504 0
                goto error;
505 0
        }
506
507
        if (unlink(uds->sun_path) != 0 && errno != ENOENT) {
508 2
                err = "unlink(2)";
509 0
                closefd(&sd);
510 0
                goto error;
511 0
        }
512
513
        if (bind(sd, (const void*)uds, sl) != 0) {
514 2
                err = "bind(2)";
515 0
                closefd(&sd);
516 0
                goto error;
517 0
        }
518
519
        h->sd_sock = sd;
520 2
521
        assert(h->sd_sock > 0);
522 2
        vtc_log(h->vl, 4, "sd_notify %s", sd_path);
523 2
        ret = setenv("NOTIFY_SOCKET", sd_path, 1);
524 2
        assert(ret == 0);
525 2
526
error:
527
        if (err != NULL)
528 2
                vtc_fatal(h->vl, "Create sd_notify socket failed: %s", err);
529 0
}
530 2
531
/**********************************************************************
532
 * Wait for the "READY" from sd_notify
533
 */
534
static void
535
haproxy_wait_sdnotify_ready(struct haproxy *h)
536 2
{
537
        struct pollfd fd[1];
538
        char buf[BUFSIZ];
539
        int i, r;
540
        char *ready = NULL;
541 2
542
        vtc_log(h->vl, 3, "wait-sdnotify-ready");
543 2
544
        /* First try to do an accept on h->sd_sock */
545
        memset(fd, 0, sizeof(fd));
546 2
        fd[0].fd = h->sd_sock;
547 2
        fd[0].events = POLLIN;
548 2
549
        i = poll(fd, 1, vtc_maxdur * 1000 / 3);
550 2
        vtc_log(h->vl, 4, "sd_notify recv poll %d 0x%x ", i, fd[0].revents);
551 2
        if (i == 0)
552 2
                vtc_fatal(h->vl, "FAIL timeout waiting for sd_notify recv");
553 0
        if (!(fd[0].revents & POLLIN))
554 2
                vtc_fatal(h->vl, "FAIL sd_notify recv wait failure");
555 0
556
        r = recv(h->sd_sock, buf, sizeof(buf) - 1, 0);
557 2
        if (r > 0) {
558 2
                buf[r] = '\0';
559 2
                ready = strstr(buf, "READY=1");
560 2
        }
561 2
562
        if (!ready)
563 2
                vtc_fatal(h->vl, "FAIL sd_notify recv READY failure");
564 0
        else
565
                vtc_log(h->vl, 3, "sd_notify READY=1");
566 2
}
567 2
/**********************************************************************
568
 * Allocate and initialize a CLI client
569
 */
570
571
static struct haproxy_cli *
572
haproxy_cli_new(struct haproxy *h)
573 22
{
574
        struct haproxy_cli *hc;
575
576
        ALLOC_OBJ(hc, HAPROXY_CLI_MAGIC);
577 22
        AN(hc);
578 22
579
        hc->vl = h->vl;
580 22
        vtc_log_set_cmd(hc->vl, haproxy_cli_cmds);
581 22
        hc->sock = -1;
582 22
        bprintf(hc->connect, "${%s_cli_sock}", h->name);
583 22
584
        hc->txbuf_sz = hc->rxbuf_sz = 2048 * 1024;
585 22
        hc->txbuf = malloc(hc->txbuf_sz);
586 22
        AN(hc->txbuf);
587 22
        hc->rxbuf = malloc(hc->rxbuf_sz);
588 22
        AN(hc->rxbuf);
589 22
590
        return (hc);
591 22
}
592
593
/* creates a master CLI client (-mcli) */
594
static struct haproxy_cli *
595
haproxy_mcli_new(struct haproxy *h)
596 22
{
597
        struct haproxy_cli *hc;
598
599
        ALLOC_OBJ(hc, HAPROXY_CLI_MAGIC);
600 22
        AN(hc);
601 22
602
        hc->vl = h->vl;
603 22
        vtc_log_set_cmd(hc->vl, haproxy_cli_cmds);
604 22
        hc->sock = -1;
605 22
        bprintf(hc->connect, "${%s_mcli_sock}", h->name);
606 22
607
        hc->txbuf_sz = hc->rxbuf_sz = 2048 * 1024;
608 22
        hc->txbuf = malloc(hc->txbuf_sz);
609 22
        AN(hc->txbuf);
610 22
        hc->rxbuf = malloc(hc->rxbuf_sz);
611 22
        AN(hc->rxbuf);
612 22
613
        return (hc);
614 22
}
615
616
/* Bind an address/port for the master CLI (-mcli) */
617
static int
618
haproxy_create_mcli(struct haproxy *h)
619 2
{
620
        int sock;
621
        const char *err;
622
        char buf[128], addr[128], port[128];
623
        char vsabuf[vsa_suckaddr_len];
624 2
        const struct suckaddr *sua;
625
626
        sock = VTCP_listen_on(default_listen_addr, NULL, 100, &err);
627 2
        if (err != NULL)
628 2
                vtc_fatal(h->vl,
629 0
                          "Create listen socket failed: %s", err);
630 0
        assert(sock > 0);
631 2
        sua = VSA_getsockname(sock, vsabuf, sizeof vsabuf);
632 2
        AN(sua);
633 2
634
        VTCP_name(sua, addr, sizeof addr, port, sizeof port);
635 2
        bprintf(buf, "%s_mcli", h->name);
636 2
        if (VSA_Get_Proto(sua) == AF_INET)
637 2
                macro_def(h->vl, buf, "sock", "%s:%s", addr, port);
638 2
        else
639
                macro_def(h->vl, buf, "sock", "[%s]:%s", addr, port);
640 0
        macro_def(h->vl, buf, "addr", "%s", addr);
641 2
        macro_def(h->vl, buf, "port", "%s", port);
642 2
643
        return (sock);
644 2
}
645 2
646
static void
647
haproxy_cli_delete(struct haproxy_cli *hc)
648 44
{
649
        CHECK_OBJ_NOTNULL(hc, HAPROXY_CLI_MAGIC);
650 44
        REPLACE(hc->spec, NULL);
651 44
        REPLACE(hc->txbuf, NULL);
652 44
        REPLACE(hc->rxbuf, NULL);
653 44
        FREE_OBJ(hc);
654 44
}
655 44
656
/**********************************************************************
657
 * Allocate and initialize a haproxy
658
 */
659
660
static struct haproxy *
661
haproxy_new(const char *name)
662 22
{
663
        struct haproxy *h;
664
        struct vsb *vsb;
665
        char buf[PATH_MAX];
666
        int closed_sock;
667
        char addr[128], port[128];
668
        const char *err;
669
        const char *env_args;
670
        char vsabuf[vsa_suckaddr_len];
671 22
        const struct suckaddr *sua;
672
673
        ALLOC_OBJ(h, HAPROXY_MAGIC);
674 22
        AN(h);
675 22
        REPLACE(h->name, name);
676 22
677
        h->args = VSB_new_auto();
678 22
        env_args = getenv(HAPROXY_ARGS_ENV_VAR);
679 22
        if (env_args) {
680 22
                VSB_cat(h->args, env_args);
681 0
                VSB_cat(h->args, " ");
682 0
        }
683 0
684
        h->vl = vtc_logopen("%s", name);
685 22
        vtc_log_set_cmd(h->vl, haproxy_cli_cmds);
686 22
        AN(h->vl);
687 22
688
        h->filename = getenv(HAPROXY_PROGRAM_ENV_VAR);
689 22
        if (h->filename == NULL)
690 22
                h->filename = "haproxy";
691 22
692
        bprintf(buf, "${tmpdir}/%s", name);
693 22
        vsb = macro_expand(h->vl, buf);
694 22
        AN(vsb);
695 22
        h->workdir = strdup(VSB_data(vsb));
696 22
        AN(h->workdir);
697 22
        VSB_destroy(&vsb);
698 22
699
        bprintf(buf, "%s/stats.sock", h->workdir);
700 22
        h->cli_fn = strdup(buf);
701 22
        AN(h->cli_fn);
702 22
703
        bprintf(buf, "%s/cfg", h->workdir);
704 22
        h->cfg_fn = strdup(buf);
705 22
        AN(h->cfg_fn);
706 22
707
        /* Create a new TCP socket to reserve an IP:port and close it asap.
708
         * May be useful to simulate an unreachable server.
709
         */
710
        bprintf(h->closed_sock, "%s_closed", h->name);
711 22
        closed_sock = VTCP_listen_on("127.0.0.1:0", NULL, 100, &err);
712 22
        if (err != NULL)
713 22
                vtc_fatal(h->vl,
714 0
                        "Create listen socket failed: %s", err);
715 0
        assert(closed_sock > 0);
716 22
        sua = VSA_getsockname(closed_sock, vsabuf, sizeof vsabuf);
717 22
        AN(sua);
718 22
        VTCP_name(sua, addr, sizeof addr, port, sizeof port);
719 22
        if (VSA_Get_Proto(sua) == AF_INET)
720 22
                macro_def(h->vl, h->closed_sock, "sock", "%s:%s", addr, port);
721 22
        else
722
                macro_def(h->vl, h->closed_sock, "sock", "[%s]:%s", addr, port);
723 0
        macro_def(h->vl, h->closed_sock, "addr", "%s", addr);
724 22
        macro_def(h->vl, h->closed_sock, "port", "%s", port);
725 22
        VTCP_close(&closed_sock);
726 22
727
        h->cli = haproxy_cli_new(h);
728 22
        AN(h->cli);
729 22
730
        h->mcli = haproxy_mcli_new(h);
731 22
        AN(h->mcli);
732 22
733
        bprintf(buf, "rm -rf \"%s\" ; mkdir -p \"%s\"", h->workdir, h->workdir);
734 22
        AZ(system(buf));
735 22
736
        h->sd_sock = -1;
737 22
738
        VTAILQ_INIT(&h->envars);
739 22
        VTAILQ_INSERT_TAIL(&haproxies, h, list);
740 22
741
        return (h);
742 22
}
743 22
744
/**********************************************************************
745
 * Delete a haproxy instance
746
 */
747
748
static void
749
haproxy_delete(struct haproxy *h)
750 22
{
751
        char buf[PATH_MAX];
752
753
        CHECK_OBJ_NOTNULL(h, HAPROXY_MAGIC);
754 22
        vtc_logclose(h->vl);
755 22
756
        if (!leave_temp) {
757 22
                bprintf(buf, "rm -rf \"%s\"", h->workdir);
758 22
                AZ(system(buf));
759 22
        }
760 22
761
        if (h->sd_sock >= 0)
762 42
                closefd(&h->sd_sock);
763 2
764
        free(h->name);
765 22
        free(h->workdir);
766 22
        free(h->cli_fn);
767 22
        free(h->cfg_fn);
768 22
        free(h->pid_fn);
769 22
        VSB_destroy(&h->args);
770 22
        haproxy_cli_delete(h->cli);
771 22
        haproxy_cli_delete(h->mcli);
772 22
773
        /* XXX: MEMLEAK (?) */
774
        FREE_OBJ(h);
775 22
}
776 22
777
/**********************************************************************
778
 * HAProxy listener
779
 */
780
781
static void *
782
haproxy_thread(void *priv)
783 22
{
784
        struct haproxy *h;
785
786
        CAST_OBJ_NOTNULL(h, priv, HAPROXY_MAGIC);
787 22
        (void)vtc_record(h->vl, h->fds[0], h->msgs);
788 22
        h->its_dead_jim = 1;
789 22
        return (NULL);
790 22
}
791
792
793
/**********************************************************************
794
 * Start a HAProxy instance.
795
 */
796
797
static void
798
haproxy_start(struct haproxy *h)
799 22
{
800
        char buf[PATH_MAX];
801
        struct vsb *vsb;
802
803
        vtc_log(h->vl, 2, "%s", __func__);
804 22
805
        AZ(VSB_finish(h->args));
806 22
        vtc_log(h->vl, 4, "opt_worker %d opt_daemon %d opt_check_mode %d opt_mcli %d",
807 44
            h->opt_worker, h->opt_daemon, h->opt_check_mode, h->opt_mcli);
808 22
809
        vsb = VSB_new_auto();
810 22
        AN(vsb);
811 22
812
        VSB_printf(vsb, "exec \"%s\"", h->filename);
813 22
        if (h->opt_check_mode)
814 22
                VSB_cat(vsb, " -c");
815 4
        else if (h->opt_daemon)
816 18
                VSB_cat(vsb, " -D");
817 6
        else
818
                VSB_cat(vsb, " -d");
819 12
820
        if (h->opt_worker) {
821 22
                if (h->opt_worker == 2) { /* sd_notify mode */
822 2
                        VSB_cat(vsb, " -Ws");
823 2
                        haproxy_bind_sdnotify(h);
824 2
                } else {
825 2
                        VSB_cat(vsb, " -W");
826 0
                }
827
                if (h->opt_mcli) {
828 2
                        int sock;
829
                        sock = haproxy_create_mcli(h);
830 2
                        VSB_printf(vsb, " -S \"fd@%d\"", sock);
831 2
                }
832 2
        }
833 2
834
        VSB_printf(vsb, " %s", VSB_data(h->args));
835 20
836
        VSB_printf(vsb, " -f \"%s\" ", h->cfg_fn);
837 20
838
        if (h->opt_worker || h->opt_daemon) {
839 20
                bprintf(buf, "%s/pid", h->workdir);
840 8
                h->pid_fn = strdup(buf);
841 8
                AN(h->pid_fn);
842 8
                VSB_printf(vsb, " -p \"%s\"", h->pid_fn);
843 8
        }
844 8
845
        AZ(VSB_finish(vsb));
846 22
        vtc_dump(h->vl, 4, "argv", VSB_data(vsb), -1);
847 22
848
        if (h->opt_worker && !h->opt_daemon) {
849 22
                /*
850
                 * HAProxy master process must exit with status 128 + <signum>
851
                 * if signaled by <signum> signal.
852
                 */
853
                h->expect_exit = HAPROXY_EXPECT_EXIT;
854 2
        }
855 2
856
        haproxy_write_conf(h);
857 22
858
        AZ(pipe(&h->fds[0]));
859 22
        vtc_log(h->vl, 4, "XXX %d @%d", h->fds[1], __LINE__);
860 22
        AZ(pipe(&h->fds[2]));
861 22
        h->pid = h->ppid = fork();
862 22
        assert(h->pid >= 0);
863 22
        if (h->pid == 0) {
864 44
                haproxy_build_env(h);
865 22
                haproxy_delete_envars(h);
866 22
                AZ(chdir(h->name));
867 22
                AZ(dup2(h->fds[0], 0));
868 22
                assert(dup2(h->fds[3], 1) == 1);
869 22
                assert(dup2(1, 2) == 2);
870 22
                closefd(&h->fds[0]);
871 22
                closefd(&h->fds[1]);
872 22
                closefd(&h->fds[2]);
873 22
                closefd(&h->fds[3]);
874 22
                AZ(execl("/bin/sh", "/bin/sh", "-c", VSB_data(vsb), (char*)0));
875 22
                exit(1);
876 0
        }
877
        VSB_destroy(&vsb);
878 22
879
        vtc_log(h->vl, 3, "PID: %ld", (long)h->pid);
880 22
        macro_def(h->vl, h->name, "pid", "%ld", (long)h->pid);
881 22
        macro_def(h->vl, h->name, "name", "%s", h->workdir);
882 22
883
        closefd(&h->fds[0]);
884 22
        closefd(&h->fds[3]);
885 22
        h->fds[0] = h->fds[2];
886 22
        h->fds[2] = h->fds[3] = -1;
887 22
888
        PTOK(pthread_create(&h->tp, NULL, haproxy_thread, h));
889 22
890
        if (h->pid_fn != NULL)
891 22
                haproxy_wait_pidfile(h);
892 8
893
        if (h->opt_worker == 2) /* sd_notify mode */
894 14
                haproxy_wait_sdnotify_ready(h);
895 2
}
896 22
897
898
/**********************************************************************
899
 * Wait for a HAProxy instance.
900
 */
901
902
static void
903
haproxy_wait(struct haproxy *h)
904 22
{
905
        void *p;
906
        int i, n, sig;
907
908
        vtc_log(h->vl, 2, "Wait");
909 22
910
        if (h->pid < 0)
911 22
                haproxy_start(h);
912 0
913
        if (h->cli->spec)
914 0
                haproxy_cli_run(h->cli);
915 0
916
        if (h->mcli->spec)
917 0
                haproxy_cli_run(h->mcli);
918 0
919
        closefd(&h->fds[1]);
920 22
921
        sig = SIGINT;
922 22
        n = 0;
923 22
        vtc_log(h->vl, 2, "Stop HAproxy pid=%ld", (long)h->pid);
924 22
        while (h->opt_daemon || (!h->opt_check_mode && !h->its_dead_jim)) {
925 154
                assert(h->pid > 0);
926 138
                if (n == 0) {
927 138
                        i = kill(h->pid, sig);
928 24
                        if (i == 0)
929 24
                                h->expect_signal = -sig;
930 18
                        if (i && errno == ESRCH)
931 30
                                break;
932 6
                        vtc_log(h->vl, 4,
933 36
                            "Kill(%d)=%d: %s", sig, i, strerror(errno));
934 18
                }
935 18
                VTIM_sleep(0.1);
936 30
                if (++n == 20) {
937 30
                        switch (sig) {
938 6
                        case SIGINT:    sig = SIGTERM ; break;
939 6
                        case SIGTERM:   sig = SIGKILL ; break;
940 0
                        default:        break;
941 0
                        }
942
                        n = 0;
943 6
                }
944 6
        }
945
946
        PTOK(pthread_join(h->tp, &p));
947 22
        AZ(p);
948 22
        closefd(&h->fds[0]);
949 22
        if (!h->opt_daemon) {
950 22
                vtc_wait4(h->vl, h->ppid, h->expect_exit, h->expect_signal, 0);
951 16
                h->ppid = -1;
952 16
        }
953 16
        h->pid = -1;
954 22
}
955 22
956
#define HAPROXY_BE_FD_STR     "fd@${"
957
#define HAPROXY_BE_FD_STRLEN  strlen(HAPROXY_BE_FD_STR)
958
959
static int
960
haproxy_build_backends(struct haproxy *h, const char *vsb_data)
961 22
{
962
        char *s, *p, *q;
963
964
        s = strdup(vsb_data);
965 22
        if (!s)
966 22
                return (-1);
967 0
968
        p = s;
969 22
        while (1) {
970 60
                int sock;
971
                char buf[128], addr[128], port[128];
972
                const char *err;
973
                char vsabuf[vsa_suckaddr_len];
974 60
                const struct suckaddr *sua;
975
976
                p = strstr(p, HAPROXY_BE_FD_STR);
977
                if (!p)
978 60
                        break;
979 60
980 22
                q = p += HAPROXY_BE_FD_STRLEN;
981
                while (*q && *q != '}')
982 38
                        q++;
983 38
                if (*q != '}')
984 160
                        break;
985 122
986 38
                *q++ = '\0';
987 0
                sock = VTCP_listen_on("127.0.0.1:0", NULL, 100, &err);
988
                if (err != NULL)
989 38
                        vtc_fatal(h->vl,
990 38
                            "Create listen socket failed: %s", err);
991 0
                assert(sock > 0);
992 0
                sua = VSA_getsockname(sock, vsabuf, sizeof vsabuf);
993
                AN(sua);
994 38
995
                VTCP_name(sua, addr, sizeof addr, port, sizeof port);
996 38
                bprintf(buf, "%s_%s", h->name, p);
997 0
                if (VSA_Get_Proto(sua) == AF_INET)
998 0
                        macro_def(h->vl, buf, "sock", "%s:%s", addr, port);
999 38
                else
1000 38
                        macro_def(h->vl, buf, "sock", "[%s]:%s", addr, port);
1001 38
                macro_def(h->vl, buf, "addr", "%s", addr);
1002
                macro_def(h->vl, buf, "port", "%s", port);
1003 38
1004 38
                bprintf(buf, "%d", sock);
1005 38
                vtc_log(h->vl, 4, "setenv(%s, %s)", p, buf);
1006 38
                haproxy_add_envar(h, p, buf);
1007
                p = q;
1008 0
        }
1009 38
        free(s);
1010 38
        return (0);
1011
}
1012 38
1013 38
static void
1014 38
haproxy_check_conf(struct haproxy *h, const char *expect)
1015 38
{
1016 60
1017 22
        h->msgs = VSB_new_auto();
1018 22
        AN(h->msgs);
1019 22
        h->opt_check_mode = 1;
1020
        haproxy_start(h);
1021
        haproxy_wait(h);
1022 4
        AZ(VSB_finish(h->msgs));
1023
        if (strstr(VSB_data(h->msgs), expect) == NULL)
1024
                vtc_fatal(h->vl, "Did not find expected string '%s'", expect);
1025 4
        vtc_log(h->vl, 2, "Found expected '%s'", expect);
1026 4
        VSB_destroy(&h->msgs);
1027 4
}
1028 4
1029 4
/**********************************************************************
1030 4
 * Write a configuration for <h> HAProxy instance.
1031 4
 */
1032 0
1033 4
static void
1034 4
haproxy_store_conf(struct haproxy *h, const char *cfg, int auto_be)
1035 4
{
1036
        struct vsb *vsb, *vsb2;
1037
1038
        vsb = VSB_new_auto();
1039
        AN(vsb);
1040
1041
        vsb2 = VSB_new_auto();
1042 22
        AN(vsb2);
1043
1044
        VSB_printf(vsb, "    global\n\tstats socket \"%s\" "
1045
                   "level admin mode 600\n", h->cli_fn);
1046 22
        VSB_cat(vsb, "    stats socket \"fd@${cli}\" level admin\n");
1047 22
        AZ(VSB_cat(vsb, cfg));
1048
1049 22
        if (auto_be)
1050 22
                cmd_server_gen_haproxy_conf(vsb);
1051
1052 44
        AZ(VSB_finish(vsb));
1053 22
1054 22
        AZ(haproxy_build_backends(h, VSB_data(vsb)));
1055 22
1056
        h->cfg_vsb = macro_expand(h->vl, VSB_data(vsb));
1057 22
        AN(h->cfg_vsb);
1058 2
1059
        VSB_destroy(&vsb2);
1060 22
        VSB_destroy(&vsb);
1061
}
1062 22
1063
static void
1064 22
haproxy_write_conf(struct haproxy *h)
1065 22
{
1066
        struct vsb *vsb;
1067 22
1068 22
        vsb = macro_expand(h->vl, VSB_data(h->cfg_vsb));
1069 22
        AN(vsb);
1070
        assert(VSB_len(vsb) >= 0);
1071
1072 22
        vtc_dump(h->vl, 4, "conf", VSB_data(vsb), VSB_len(vsb));
1073
        if (VFIL_writefile(h->workdir, h->cfg_fn,
1074
            VSB_data(vsb), VSB_len(vsb)) != 0)
1075
                vtc_fatal(h->vl,
1076 22
                    "failed to write haproxy configuration file: %s (%d)",
1077 22
                    strerror(errno), errno);
1078 22
1079
        VSB_destroy(&vsb);
1080 22
}
1081 66
1082 44
/* SECTION: haproxy haproxy
1083 0
 *
1084
 * Define and interact with haproxy instances.
1085 0
 *
1086
 * To define a haproxy server, you'll use this syntax::
1087 22
 *
1088 22
 *      haproxy hNAME -conf-OK CONFIG
1089
 *      haproxy hNAME -conf-BAD ERROR CONFIG
1090
 *      haproxy hNAME [-D] [-W] [-arg STRING] [-conf[+vcl] STRING]
1091
 *
1092
 * The first ``haproxy hNAME`` invocation will start the haproxy master
1093
 * process in the background, waiting for the ``-start`` switch to actually
1094
 * start the child.
1095
 *
1096
 * Arguments:
1097
 *
1098
 * hNAME
1099
 *         Identify the HAProxy server with a string, it must starts with 'h'.
1100
 *
1101
 * \-conf-OK CONFIG
1102
 *         Run haproxy in '-c' mode to check config is OK
1103
 *         stdout/stderr should contain 'Configuration file is valid'
1104
 *         The exit code should be 0.
1105
 *
1106
 * \-conf-BAD ERROR CONFIG
1107
 *         Run haproxy in '-c' mode to check config is BAD.
1108
 *         "ERROR" should be part of the diagnostics on stdout/stderr.
1109
 *         The exit code should be 1.
1110
 *
1111
 * \-D
1112
 *         Run HAproxy in daemon mode.  If not given '-d' mode used.
1113
 *
1114
 * \-W
1115
 *         Enable HAproxy in Worker mode.
1116
 *
1117
 * \-S
1118
 *         Enable HAproxy Master CLI in Worker mode
1119
 *
1120
 * \-arg STRING
1121
 *         Pass an argument to haproxy, for example "-h simple_list".
1122
 *
1123
 * \-cli STRING
1124
 *         Specify the spec to be run by the command line interface (CLI).
1125
 *
1126
 * \-mcli STRING
1127
 *         Specify the spec to be run by the command line interface (CLI)
1128
 *         of the Master process.
1129
 *
1130
 * \-conf STRING
1131
 *         Specify the configuration to be loaded by this HAProxy instance.
1132
 *
1133
 * \-conf+backend STRING
1134
 *         Specify the configuration to be loaded by this HAProxy instance,
1135
 *         all server instances will be automatically appended
1136
 *
1137
 * \-start
1138
 *         Start this HAProxy instance.
1139
 *
1140
 * \-wait
1141
 *         Stop this HAProxy instance.
1142
 *
1143
 * \-expectexit NUMBER
1144
 *         Expect haproxy to exit(3) with this value
1145
 *
1146
 */
1147
1148
void
1149
cmd_haproxy(CMD_ARGS)
1150
{
1151
        struct haproxy *h, *h2;
1152
1153
        (void)priv;
1154
1155
        if (av == NULL) {
1156
                /* Reset and free */
1157 2076
                VTAILQ_FOREACH_SAFE(h, &haproxies, list, h2) {
1158
                        vtc_log(h->vl, 2,
1159
                            "Reset and free %s haproxy %ld",
1160
                            h->name, (long)h->pid);
1161 2076
                        if (h->pid >= 0)
1162
                                haproxy_wait(h);
1163 2076
                        VTAILQ_REMOVE(&haproxies, h, list);
1164
                        haproxy_delete(h);
1165 2072
                }
1166 44
                return;
1167
        }
1168 22
1169 22
        AZ(strcmp(av[0], "haproxy"));
1170 14
        av++;
1171 22
1172 22
        VTC_CHECK_NAME(vl, av[0], "haproxy", 'h');
1173 22
        VTAILQ_FOREACH(h, &haproxies, list)
1174 2050
                if (!strcmp(h->name, av[0]))
1175
                        break;
1176
        if (h == NULL)
1177 26
                h = haproxy_new(av[0]);
1178 26
        av++;
1179
1180 26
        for (; *av != NULL; av++) {
1181 30
                if (vtc_error)
1182 8
                        break;
1183 4
1184 22
                if (!strcmp(*av, "-conf-OK")) {
1185 22
                        AN(av[1]);
1186 26
                        haproxy_store_conf(h, av[1], 0);
1187
                        h->expect_exit = 0;
1188 84
                        haproxy_check_conf(h, "");
1189 58
                        av++;
1190 0
                        continue;
1191
                }
1192 58
                if (!strcmp(*av, "-conf-BAD")) {
1193 2
                        AN(av[1]);
1194 2
                        AN(av[2]);
1195 2
                        haproxy_store_conf(h, av[2], 0);
1196 2
                        h->expect_exit = 1;
1197 2
                        haproxy_check_conf(h, av[1]);
1198 2
                        av += 2;
1199
                        continue;
1200 56
                }
1201 2
1202 2
                if (!strcmp(*av, HAPROXY_OPT_DAEMON)) {
1203 2
                        h->opt_daemon = 1;
1204 2
                        continue;
1205 2
                }
1206 2
                if (!strcmp(*av, HAPROXY_OPT_WORKER)) {
1207 2
                        h->opt_worker = 1;
1208
                        continue;
1209
                }
1210 54
                if (!strcmp(*av, HAPROXY_OPT_SD_WORKER)) {
1211 6
                        h->opt_worker = 2;
1212 6
                        continue;
1213
                }
1214 48
                if (!strcmp(*av, HAPROXY_OPT_MCLI)) {
1215 0
                        h->opt_mcli = 1;
1216 0
                        continue;
1217
                }
1218 48
                if (!strcmp(*av, "-arg")) {
1219 2
                        AN(av[1]);
1220 2
                        AZ(h->pid);
1221
                        VSB_cat(h->args, " ");
1222 46
                        VSB_cat(h->args, av[1]);
1223 2
                        av++;
1224 2
                        continue;
1225
                }
1226 44
1227 0
                if (!strcmp(*av, "-cli")) {
1228 0
                        REPLACE(h->cli->spec, av[1]);
1229 0
                        if (h->tp)
1230 0
                                haproxy_cli_run(h->cli);
1231 0
                        av++;
1232 0
                        continue;
1233
                }
1234
1235 44
                if (!strcmp(*av, "-mcli")) {
1236 2
                        REPLACE(h->mcli->spec, av[1]);
1237 2
                        if (h->tp)
1238 2
                                haproxy_cli_run(h->mcli);
1239 2
                        av++;
1240 2
                        continue;
1241
                }
1242
1243 42
                if (!strcmp(*av, "-conf")) {
1244 2
                        AN(av[1]);
1245 2
                        haproxy_store_conf(h, av[1], 0);
1246 2
                        av++;
1247 2
                        continue;
1248 2
                }
1249
                if (!strcmp(*av, "-conf+backend")) {
1250
                        AN(av[1]);
1251 40
                        haproxy_store_conf(h, av[1], 1);
1252 16
                        av++;
1253 16
                        continue;
1254 16
                }
1255 16
1256
                if (!strcmp(*av, "-expectexit")) {
1257 24
                        h->expect_exit = strtoul(av[1], NULL, 0);
1258 2
                        av++;
1259 2
                        continue;
1260 2
                }
1261 2
                if (!strcmp(*av, "-start")) {
1262
                        haproxy_start(h);
1263
                        continue;
1264 22
                }
1265 0
                if (!strcmp(*av, "-wait")) {
1266 0
                        haproxy_wait(h);
1267 0
                        continue;
1268
                }
1269 22
                vtc_fatal(h->vl, "Unknown haproxy argument: %s", *av);
1270 18
        }
1271 18
}