28 |
28 |
29 #include "wstool.h" |
29 #include "wstool.h" |
30 |
30 |
31 #include <stdio.h> |
31 #include <stdio.h> |
32 #include <stdlib.h> |
32 #include <stdlib.h> |
|
33 #include <string.h> |
|
34 |
|
35 #include "../server/config/serverconf.h" |
33 |
36 |
34 #include "srvctrlsocket.h" |
37 #include "srvctrlsocket.h" |
35 |
38 |
36 static void print_info(char *cmd) { |
39 static void print_info(char *cmd) { |
37 fprintf(stderr, "usage: %s -s <socketpath> <command>\n\n"); |
40 fprintf(stderr, "usage:\n"); |
|
41 fprintf(stderr, "%s -t <srvconfigfile>\n", cmd); |
|
42 fprintf(stderr, "%s -s <socketpath> <command>\n", cmd); |
38 fprintf(stderr, "Commands: reconfig, shutdown, stat, log\n"); |
43 fprintf(stderr, "Commands: reconfig, shutdown, stat, log\n"); |
39 } |
44 } |
40 |
45 |
41 int main(int argc, char **argv) { |
46 int main(int argc, char **argv) { |
42 if(argc < 3) { |
47 if(argc > 2) { |
43 print_info(argv[0]); |
48 if(!strcmp(argv[1], "-t")) { |
44 return -2; |
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 } |
45 } |
57 } |
46 |
58 |
47 SrvConnection *srv = srvctrl_connet(argv[1]); |
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); |
48 if(!srv) { |
88 if(!srv) { |
49 return -1; |
89 return -1; |
50 } |
90 } |
51 |
91 |
52 fprintf(srv->stream, "%s\n", argv[2]); |
92 fprintf(srv->stream, "%s\n", cmd); |
53 fflush(srv->stream); |
93 fflush(srv->stream); |
54 |
94 |
55 SrvMsg msg; |
95 SrvMsg msg; |
56 while(!srvctrl_readmsg(srv, &msg)) { |
96 while(!srvctrl_readmsg(srv, &msg)) { |
57 if(msg.type == 0) { |
97 if(msg.type == 0) { |