1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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 }
124