source: bin/varnishd/cache_cli.c @ 4a1413

Revision 4a1413, 6.2 KB checked in by Poul-Henning Kamp <phk@…>, 3 years ago (diff)

Remove unused #includes

  • Property mode set to 100644
Line 
1/*-
2 * Copyright (c) 2006 Verdens Gang AS
3 * Copyright (c) 2006-2011 Varnish Software AS
4 * All rights reserved.
5 *
6 * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
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 * Caching process CLI handling.
30 *
31 * We only have one CLI source, the stdin/stdout pipes from the manager
32 * process, but we complicate things by having undocumented commands that
33 * we do not want to show in a plain help, and by having commands that the
34 * manager has already shown in help before asking us.
35 */
36
37#include "config.h"
38
39#include <stddef.h>                     // offsetof
40
41#include "cache.h"
42
43#include "vcli.h"
44#include "cli_priv.h"
45#include "cli_common.h"
46#include "cli_serve.h"
47#include "hash_slinger.h"               // objhead
48
49pthread_t               cli_thread;
50static struct lock      cli_mtx;
51static int              add_check;
52static struct VCLS      *cls;
53
54/*
55 * The CLI commandlist is split in three:
56 *  - Commands we get from/share with the manager, we don't show these
57 *      in help, as the manager already did that.
58 *  - Cache process commands, show in help
59 *  - Undocumented debug commands, show in undocumented "help -d"
60 */
61
62/*--------------------------------------------------------------------
63 * Add CLI functions to the appropriate command set
64 */
65
66void
67CLI_AddFuncs(struct cli_proto *p)
68{
69
70        AZ(add_check);
71        Lck_Lock(&cli_mtx);
72        AZ(VCLS_AddFunc(cls, 0, p));
73        Lck_Unlock(&cli_mtx);
74}
75
76static void
77cli_cb_before(const struct cli *cli)
78{
79
80        ASSERT_CLI();
81        VSL(SLT_CLI, 0, "Rd %s", cli->cmd);
82        VCL_Poll();
83        VBE_Poll();
84        Lck_Lock(&cli_mtx);
85}
86
87static void
88cli_cb_after(const struct cli *cli)
89{
90
91        ASSERT_CLI();
92        Lck_Unlock(&cli_mtx);
93        VSL(SLT_CLI, 0, "Wr %03u %u %s",
94            cli->result, VSB_len(cli->sb), VSB_data(cli->sb));
95}
96
97void
98CLI_Run(void)
99{
100        int i;
101
102        add_check = 1;
103
104        AN(VCLS_AddFd(cls, heritage.cli_in, heritage.VCLI_Out, NULL, NULL));
105
106        do {
107                i = VCLS_Poll(cls, -1);
108        } while(i > 0);
109        VSL(SLT_CLI, 0, "EOF on CLI connection, worker stops");
110        VCA_Shutdown();
111}
112
113/*--------------------------------------------------------------------*/
114
115static void
116cli_debug_sizeof(struct cli *cli, const char * const *av, void *priv)
117{
118        (void)av;
119        (void)priv;
120
121#define SZOF(foo)       VCLI_Out(cli, \
122    "sizeof(%s) = %zd = 0x%zx\n", #foo, sizeof(foo), sizeof(foo))
123        SZOF(struct ws);
124        SZOF(struct http);
125        SZOF(struct http_conn);
126        SZOF(struct acct);
127        SZOF(struct worker);
128        SZOF(struct storage);
129        SZOF(struct object);
130        SZOF(struct objcore);
131        SZOF(struct objhead);
132        SZOF(struct sess);
133        SZOF(struct vbc);
134        SZOF(struct VSC_C_main);
135        SZOF(struct lock);
136#if 0
137#define OFOF(foo, bar)  { foo __foo; VCLI_Out(cli, \
138    "%-30s = 0x%4zx @ 0x%4zx\n", \
139        #foo "." #bar, sizeof(__foo.bar), offsetof(foo, bar)); }
140#if 0
141        OFOF(struct objhead, magic);
142        OFOF(struct objhead, refcnt);
143        OFOF(struct objhead, mtx);
144        OFOF(struct objhead, objcs);
145        OFOF(struct objhead, digest);
146        OFOF(struct objhead, waitinglist);
147        OFOF(struct objhead, _u);
148#endif
149#if 0
150        OFOF(struct http, magic);
151        OFOF(struct http, logtag);
152        OFOF(struct http, ws);
153        OFOF(struct http, hd);
154        OFOF(struct http, hdf);
155        OFOF(struct http, shd);
156        OFOF(struct http, nhd);
157        OFOF(struct http, status);
158        OFOF(struct http, protover);
159        OFOF(struct http, conds);
160#endif
161#if 0
162        OFOF(struct storage, magic);
163        OFOF(struct storage, fd);
164        OFOF(struct storage, where);
165        OFOF(struct storage, list);
166        OFOF(struct storage, stevedore);
167        OFOF(struct storage, priv);
168        OFOF(struct storage, ptr);
169        OFOF(struct storage, len);
170        OFOF(struct storage, space);
171#endif
172#if 0
173        OFOF(struct object, magic);
174        OFOF(struct object, xid);
175        OFOF(struct object, objstore);
176        OFOF(struct object, objcore);
177        OFOF(struct object, ws_o);
178        OFOF(struct object, vary);
179        OFOF(struct object, hits);
180        OFOF(struct object, response);
181        OFOF(struct object, gziped);
182        OFOF(struct object, gzip_start);
183        OFOF(struct object, gzip_last);
184        OFOF(struct object, gzip_stop);
185        OFOF(struct object, len);
186        OFOF(struct object, age);
187        OFOF(struct object, entered);
188        OFOF(struct object, exp);
189        OFOF(struct object, last_modified);
190        OFOF(struct object, last_lru);
191        OFOF(struct object, http);
192        OFOF(struct object, store);
193        OFOF(struct object, esidata);
194        OFOF(struct object, last_use);
195#endif
196#undef OFOF
197#endif
198}
199
200/*--------------------------------------------------------------------*/
201
202static void
203ccf_panic(struct cli *cli, const char * const *av, void *priv)
204{
205
206        (void)cli;
207        (void)av;
208        (void)priv;
209        assert(!strcmp("", "You asked for it"));
210}
211
212/*--------------------------------------------------------------------*/
213
214static struct cli_proto master_cmds[] = {
215        { CLI_PING,             "i", VCLS_func_ping },
216        { CLI_HELP,             "i", VCLS_func_help },
217        { "debug.sizeof", "debug.sizeof",
218                "\tDump sizeof various data structures\n",
219                0, 0, "d", cli_debug_sizeof },
220        { "debug.panic.worker", "debug.panic.worker",
221                "\tPanic the worker process.\n",
222                0, 0, "d", ccf_panic },
223        { NULL }
224};
225
226/*--------------------------------------------------------------------
227 * Initialize the CLI subsystem
228 */
229
230void
231CLI_Init(void)
232{
233
234        Lck_New(&cli_mtx, lck_cli);
235        cli_thread = pthread_self();
236
237        cls = VCLS_New(cli_cb_before, cli_cb_after, params->cli_buffer);
238        AN(cls);
239
240        CLI_AddFuncs(master_cmds);
241}
Note: See TracBrowser for help on using the repository browser.