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/serverconfig.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 = serverconfig_load(configfile);
65 CxList *list = serverconfig_get_node_list(serverconf->root,
CONFIG_NODE_OBJECT, cx_str(
"Runtime"));
66 if(!list) {
67 fprintf(stderr,
"Error: No Runtime element in %s\n", configfile);
68 return -
1;
69 }
70 if(list->size !=
1) {
71 fprintf(stderr,
"Error: Multiple Runtime elements in %s\n", configfile);
72 return -
1;
73 }
74 ConfigNode *runtime = cxListAt(list,
0);
75 cxstring tmp = serverconfig_object_directive_value(runtime, cx_str(
"Temp"));
76
77 cxListDestroy(list);
78
79 if(!tmp.ptr) {
80 fprintf(stderr,
"Error: No Temp directive in Runtime Object\n");
81 return -
1;
82 }
83
84 printf(
"%.*s\n", (
int)tmp.length, tmp.ptr);
85
86 return 0;
87 }
88
89 int tool_srvctrl(
char *socketfile,
char *cmd) {
90 SrvConnection *srv = srvctrl_connet(socketfile);
91 if(!srv) {
92 return -
1;
93 }
94
95 fprintf(srv->stream,
"%s\n", cmd);
96 fflush(srv->stream);
97
98 SrvMsg msg;
99 while(!srvctrl_readmsg(srv, &msg)) {
100 if(msg.type ==
0) {
101 fprintf(stdout,
"%.*s", (
int)msg.length, msg.message);
102 fflush(stdout);
103 }
else if(msg.type ==
1) {
104 fprintf(stderr,
"%.*s", (
int)msg.length, msg.message);
105 fflush(stderr);
106 }
107 }
108
109 srvctrl_close(srv);
110
111 return 0;
112 }
113
114
115
116 int log_ereport(
int degree,
const char *format, ...) {
117 va_list args;
118 va_start(args, format);
119 int ret = log_ereport_v(degree, format, args);
120 va_end(args);
121 return ret;
122 }
123
124 int log_ereport_v(
int degree,
const char *format, va_list args) {
125 return 0;
126 }
127