src/tools/wstool.c

changeset 179
ef6827505bd2
parent 175
9823770ba4ee
child 254
4784c14aa639
equal deleted inserted replaced
174:8f2a834d1d68 179:ef6827505bd2
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2017 Olaf Wintermann. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "wstool.h"
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include "../server/config/serverconf.h"
36
37 #include "srvctrlsocket.h"
38
39 static void print_info(char *cmd) {
40 fprintf(stderr, "usage:\n");
41 fprintf(stderr, "%s -t <srvconfigfile>\n", cmd);
42 fprintf(stderr, "%s -s <socketpath> <command>\n", cmd);
43 fprintf(stderr, "Commands: reconfig, shutdown, stat, log\n");
44 }
45
46 int main(int argc, char **argv) {
47 if(argc > 2) {
48 if(!strcmp(argv[1], "-t")) {
49 return tool_get_tmpdir(argv[2]);
50 } else if(!strcmp(argv[1], "-s")) {
51 if(argc != 4) {
52 print_info(argv[0]);
53 return -2;
54 }
55 return tool_srvctrl(argv[2], argv[3]);
56 }
57 }
58
59 print_info(argv[0]);
60 return -2;
61 }
62
63 int tool_get_tmpdir(char *configfile) {
64 ServerConfig *serverconf = load_server_config(configfile);
65 UcxList *list = ucx_map_sstr_get(serverconf->objects, sstrn("Runtime", 7));
66 if(!list) {
67 fprintf(stderr, "Error: No Runtime element in %s\n", configfile);
68 return -1;
69 }
70 if(ucx_list_size(list) != 1) {
71 fprintf(stderr, "Error: Multiple Runtime elements in %s\n", configfile);
72 return -1;
73 }
74 ServerConfigObject *runtime = list->data;
75 sstr_t tmp = cfg_directivelist_get_str(runtime->directives, sstr("Temp"));
76 if(!tmp.ptr) {
77 fprintf(stderr, "Error: No Temp directive in Runtime Object\n");
78 return -1;
79 }
80
81 printf("%.*s\n", (int)tmp.length, tmp.ptr);
82
83 return 0;
84 }
85
86 int tool_srvctrl(char *socketfile, char *cmd) {
87 SrvConnection *srv = srvctrl_connet(socketfile);
88 if(!srv) {
89 return -1;
90 }
91
92 fprintf(srv->stream, "%s\n", cmd);
93 fflush(srv->stream);
94
95 SrvMsg msg;
96 while(!srvctrl_readmsg(srv, &msg)) {
97 if(msg.type == 0) {
98 fprintf(stdout, "%.*s", (int)msg.length, msg.message);
99 fflush(stdout);
100 } else if(msg.type == 1) {
101 fprintf(stderr, "%.*s", (int)msg.length, msg.message);
102 fflush(stderr);
103 }
104 }
105
106 srvctrl_close(srv);
107
108 return 0;
109 }
110
111
112
113 int log_ereport(int degree, const char *format, ...) {
114 va_list args;
115 va_start(args, format);
116 int ret = log_ereport_v(degree, format, args);
117 va_end(args);
118 return ret;
119 }
120
121 int log_ereport_v(int degree, const char *format, va_list args) {
122 return 0;
123 }

mercurial