382
by Monty Taylor
Removed bogus copyright headers. |
1 |
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 MySQL
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
1
by brian
clean slate |
20 |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
21 |
/* maintaince of drizzle databases */
|
1
by brian
clean slate |
22 |
|
23 |
#include "client_priv.h" |
|
24 |
#include <signal.h> |
|
212.5.13
by Monty Taylor
Moved my_sys/my_pthread/my_nosys and mysys_err to mysys. |
25 |
#include <mysys/my_pthread.h> /* because of signal() */ |
1
by brian
clean slate |
26 |
#include <sys/stat.h> |
27 |
||
264.1.21
by forstm1w
Added gettext translations to strings. |
28 |
/* Added this for string translation. */
|
538
by Monty Taylor
Moved gettext.h into drizzled in anticipation of the new client lib. |
29 |
#include <drizzled/gettext.h> |
264.1.21
by forstm1w
Added gettext translations to strings. |
30 |
|
1
by brian
clean slate |
31 |
#define ADMIN_VERSION "8.42"
|
32 |
#define SHUTDOWN_DEF_TIMEOUT 3600 /* Wait for shutdown */ |
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
33 |
|
165
by Brian Aker
mysqladmin patch (plus removal of password auth bits) |
34 |
char *host= NULL, *user= NULL, *opt_password= NULL; |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
35 |
static bool interrupted= false, opt_verbose= false,tty_password= false; |
165
by Brian Aker
mysqladmin patch (plus removal of password auth bits) |
36 |
static uint32_t tcp_port= 0, option_wait= 0, option_silent= 0; |
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
37 |
static uint32_t my_end_arg; |
38 |
static uint32_t opt_connect_timeout, opt_shutdown_timeout; |
|
1
by brian
clean slate |
39 |
static myf error_flags; /* flags to pass to my_printf_error, like ME_BELL */ |
40 |
||
520.4.43
by mordred
A set of Solaris fixes. |
41 |
using namespace std; |
42 |
||
1
by brian
clean slate |
43 |
/*
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
44 |
Forward declarations
|
1
by brian
clean slate |
45 |
*/
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
46 |
static void usage(void); |
1
by brian
clean slate |
47 |
static void print_version(void); |
779.2.11
by Monty Taylor
General build cleanup - removed cruft, removed depreated checks. |
48 |
extern "C" void endprog(int signal_number); |
143
by Brian Aker
Bool cleanup. |
49 |
extern "C" bool get_one_option(int optid, const struct my_option *opt, |
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
50 |
char *argument); |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
51 |
static int execute_commands(DRIZZLE *drizzle,int argc, char **argv); |
52 |
static bool sql_connect(DRIZZLE *drizzle, uint wait); |
|
1
by brian
clean slate |
53 |
|
54 |
/*
|
|
55 |
The order of commands must be the same as command_names,
|
|
56 |
except ADMIN_ERROR
|
|
57 |
*/
|
|
58 |
enum commands { |
|
59 |
ADMIN_ERROR, |
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
60 |
ADMIN_SHUTDOWN, |
61 |
ADMIN_PING
|
|
1
by brian
clean slate |
62 |
};
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
63 |
|
1
by brian
clean slate |
64 |
static const char *command_names[]= { |
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
65 |
"shutdown", |
66 |
"ping", |
|
461
by Monty Taylor
Removed NullS. bu-bye. |
67 |
NULL
|
1
by brian
clean slate |
68 |
};
|
69 |
||
70 |
static TYPELIB command_typelib= |
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
71 |
{ array_elements(command_names)-1,"commands", command_names, NULL }; |
1
by brian
clean slate |
72 |
|
73 |
static struct my_option my_long_options[] = |
|
74 |
{
|
|
264.1.21
by forstm1w
Added gettext translations to strings. |
75 |
{"help", '?', N_("Display this help and exit."), 0, 0, 0, GET_NO_ARG, |
1
by brian
clean slate |
76 |
NO_ARG, 0, 0, 0, 0, 0, 0}, |
264.1.21
by forstm1w
Added gettext translations to strings. |
77 |
{"host", 'h', N_("Connect to host."), (char**) &host, (char**) &host, 0, GET_STR, |
1
by brian
clean slate |
78 |
REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, |
673.5.12
by Andrew Hutchings
Apply -p means port changes to drizzleadmin |
79 |
{"password", 'P', |
264.1.21
by forstm1w
Added gettext translations to strings. |
80 |
N_("Password to use when connecting to server. If password is not given it's asked from the tty."), |
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
81 |
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, |
673.5.12
by Andrew Hutchings
Apply -p means port changes to drizzleadmin |
82 |
{"port", 'p', N_("Port number to use for connection or 0 for default to, in " |
520.4.28
by Monty Taylor
Changed my.cnf to drizzle.cnf and /etc/mysql to /etc/drizzle. |
83 |
"order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
|
301
by Brian Aker
Clean up port startup |
84 |
"built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ")."), |
673.5.12
by Andrew Hutchings
Apply -p means port changes to drizzleadmin |
85 |
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, |
264.1.21
by forstm1w
Added gettext translations to strings. |
86 |
{"silent", 's', N_("Silently exit if one can't connect to server."), |
1
by brian
clean slate |
87 |
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, |
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
88 |
#ifndef DONT_ALLOW_USER_CHANGE
|
264.1.21
by forstm1w
Added gettext translations to strings. |
89 |
{"user", 'u', N_("User for login if not current user."), (char**) &user, |
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
90 |
(char**) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, |
91 |
#endif
|
|
264.1.21
by forstm1w
Added gettext translations to strings. |
92 |
{"verbose", 'v', N_("Write more information."), (char**) &opt_verbose, |
77.1.77
by Monty Taylor
A crapton more warning cleanups (I turned on more warnings) |
93 |
(char**) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, |
264.1.21
by forstm1w
Added gettext translations to strings. |
94 |
{"version", 'V', N_("Output version information and exit."), 0, 0, 0, GET_NO_ARG, |
1
by brian
clean slate |
95 |
NO_ARG, 0, 0, 0, 0, 0, 0}, |
264.1.21
by forstm1w
Added gettext translations to strings. |
96 |
{"wait", 'w', N_("Wait and retry if connection is down."), 0, 0, 0, GET_UINT, |
1
by brian
clean slate |
97 |
OPT_ARG, 0, 0, 0, 0, 0, 0}, |
77.1.77
by Monty Taylor
A crapton more warning cleanups (I turned on more warnings) |
98 |
{"connect_timeout", OPT_CONNECT_TIMEOUT, "", (char**) &opt_connect_timeout, |
99 |
(char**) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 3600*12, 0, |
|
1
by brian
clean slate |
100 |
3600*12, 0, 1, 0}, |
77.1.77
by Monty Taylor
A crapton more warning cleanups (I turned on more warnings) |
101 |
{"shutdown_timeout", OPT_SHUTDOWN_TIMEOUT, "", (char**) &opt_shutdown_timeout, |
102 |
(char**) &opt_shutdown_timeout, 0, GET_ULONG, REQUIRED_ARG, |
|
1
by brian
clean slate |
103 |
SHUTDOWN_DEF_TIMEOUT, 0, 3600*12, 0, 1, 0}, |
104 |
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} |
|
105 |
};
|
|
106 |
||
107 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
108 |
static const char *load_default_groups[]= { "drizzleadmin","client",0 }; |
1
by brian
clean slate |
109 |
|
143
by Brian Aker
Bool cleanup. |
110 |
bool
|
632.1.12
by Monty Taylor
Fixed more sun studio warnings. |
111 |
get_one_option(int optid, const struct my_option *, char *argument) |
1
by brian
clean slate |
112 |
{
|
673.5.12
by Andrew Hutchings
Apply -p means port changes to drizzleadmin |
113 |
char *endchar= NULL; |
114 |
uint64_t temp_drizzle_port= 0; |
|
1
by brian
clean slate |
115 |
int error = 0; |
116 |
||
117 |
switch(optid) { |
|
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
118 |
case 'p': |
673.5.12
by Andrew Hutchings
Apply -p means port changes to drizzleadmin |
119 |
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10); |
120 |
/* if there is an alpha character this is not a valid port */
|
|
121 |
if (strlen(endchar) != 0) |
|
122 |
{
|
|
123 |
fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n")); |
|
124 |
exit(1); |
|
125 |
}
|
|
126 |
/* If the port number is > 65535 it is not a valid port
|
|
673.5.13
by Andrew Hutchings
Apply -p means port changes to all client apps |
127 |
This also helps with potential data loss casting unsigned long to a
|
128 |
uint32_t. */
|
|
673.5.12
by Andrew Hutchings
Apply -p means port changes to drizzleadmin |
129 |
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535)) |
130 |
{
|
|
131 |
fprintf(stderr, _("Value supplied for port is not valid.\n")); |
|
132 |
exit(1); |
|
133 |
}
|
|
134 |
else
|
|
135 |
{
|
|
136 |
tcp_port= (uint32_t) temp_drizzle_port; |
|
137 |
}
|
|
138 |
break; |
|
139 |
case 'P': |
|
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
140 |
if (argument) |
141 |
{
|
|
142 |
char *start=argument; |
|
656.1.51
by Monty Taylor
Fixed strdup return checking in client/ |
143 |
if (opt_password) |
144 |
free(opt_password); |
|
145 |
||
656.1.20
by Monty Taylor
Removed my_strdup, my_malloc, my_realloc from client/ |
146 |
opt_password= strdup(argument); |
656.1.51
by Monty Taylor
Fixed strdup return checking in client/ |
147 |
if (opt_password == NULL) |
148 |
{
|
|
149 |
fprintf(stderr, _("Memory allocation error while copying password. " |
|
150 |
"Aborting.\n")); |
|
151 |
exit(ENOMEM); |
|
152 |
}
|
|
673.5.13
by Andrew Hutchings
Apply -p means port changes to all client apps |
153 |
while (*argument) |
154 |
{
|
|
155 |
/* Overwriting password with 'x' */
|
|
156 |
*argument++= 'x'; |
|
157 |
}
|
|
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
158 |
if (*start) |
673.5.13
by Andrew Hutchings
Apply -p means port changes to all client apps |
159 |
{
|
160 |
/* Cut length of argument */
|
|
161 |
start[1]= 0; |
|
162 |
}
|
|
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
163 |
tty_password= 0; |
164 |
}
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
165 |
else
|
166 |
tty_password= 1; |
|
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
167 |
break; |
1
by brian
clean slate |
168 |
case 's': |
169 |
option_silent++; |
|
170 |
break; |
|
171 |
case 'V': |
|
172 |
print_version(); |
|
173 |
exit(0); |
|
174 |
case 'w': |
|
175 |
if (argument) |
|
176 |
{
|
|
177 |
if ((option_wait=atoi(argument)) <= 0) |
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
178 |
option_wait=1; |
1
by brian
clean slate |
179 |
}
|
180 |
else
|
|
181 |
option_wait= ~(uint)0; |
|
182 |
break; |
|
183 |
case '?': |
|
184 |
case 'I': /* Info */ |
|
185 |
error++; |
|
186 |
break; |
|
187 |
}
|
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
188 |
|
1
by brian
clean slate |
189 |
if (error) |
190 |
{
|
|
191 |
usage(); |
|
192 |
exit(1); |
|
193 |
}
|
|
194 |
return 0; |
|
195 |
}
|
|
196 |
||
197 |
int main(int argc,char *argv[]) |
|
198 |
{
|
|
199 |
int error= 0, ho_error; |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
200 |
DRIZZLE drizzle; |
1
by brian
clean slate |
201 |
char **commands, **save_argv; |
202 |
||
203 |
MY_INIT(argv[0]); |
|
202.2.4
by Monty Taylor
Merged from Patrick. |
204 |
drizzle_create(&drizzle); |
520.4.28
by Monty Taylor
Changed my.cnf to drizzle.cnf and /etc/mysql to /etc/drizzle. |
205 |
load_defaults("drizzle",load_default_groups,&argc,&argv); |
1
by brian
clean slate |
206 |
save_argv = argv; /* Save for free_defaults */ |
207 |
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) |
|
208 |
{
|
|
209 |
free_defaults(save_argv); |
|
210 |
exit(ho_error); |
|
211 |
}
|
|
212 |
||
213 |
if (argc == 0) |
|
214 |
{
|
|
215 |
usage(); |
|
216 |
exit(1); |
|
217 |
}
|
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
218 |
|
1
by brian
clean slate |
219 |
commands = argv; |
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
220 |
if (tty_password) |
461
by Monty Taylor
Removed NullS. bu-bye. |
221 |
opt_password = get_tty_password(NULL); |
1
by brian
clean slate |
222 |
|
398.1.10
by Monty Taylor
Actually removed VOID() this time. |
223 |
signal(SIGINT,endprog); /* Here if abort */ |
224 |
signal(SIGTERM,endprog); /* Here if abort */ |
|
1
by brian
clean slate |
225 |
|
226 |
if (opt_connect_timeout) |
|
227 |
{
|
|
228 |
uint tmp=opt_connect_timeout; |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
229 |
drizzle_options(&drizzle,DRIZZLE_OPT_CONNECT_TIMEOUT, (char*) &tmp); |
1
by brian
clean slate |
230 |
}
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
231 |
|
232 |
error_flags= (myf)0; |
|
1
by brian
clean slate |
233 |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
234 |
if (sql_connect(&drizzle, option_wait)) |
1
by brian
clean slate |
235 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
236 |
unsigned int err= drizzle_errno(&drizzle); |
1
by brian
clean slate |
237 |
if (err >= CR_MIN_ERROR && err <= CR_MAX_ERROR) |
238 |
error= 1; |
|
239 |
else
|
|
240 |
{
|
|
241 |
/* Return 0 if all commands are PING */
|
|
242 |
for (; argc > 0; argv++, argc--) |
|
243 |
{
|
|
244 |
if (find_type(argv[0], &command_typelib, 2) != ADMIN_PING) |
|
245 |
{
|
|
246 |
error= 1; |
|
247 |
break; |
|
248 |
}
|
|
249 |
}
|
|
250 |
}
|
|
251 |
}
|
|
252 |
else
|
|
253 |
{
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
254 |
error=execute_commands(&drizzle,argc,commands); |
255 |
drizzle_close(&drizzle); |
|
1
by brian
clean slate |
256 |
}
|
477
by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that. |
257 |
free(opt_password); |
258 |
free(user); |
|
1
by brian
clean slate |
259 |
free_defaults(save_argv); |
260 |
my_end(my_end_arg); |
|
632.1.12
by Monty Taylor
Fixed more sun studio warnings. |
261 |
return error ? 1 : 0; |
1
by brian
clean slate |
262 |
}
|
263 |
||
779.2.11
by Monty Taylor
General build cleanup - removed cruft, removed depreated checks. |
264 |
void endprog(int) |
1
by brian
clean slate |
265 |
{
|
266 |
interrupted=1; |
|
267 |
}
|
|
268 |
||
206.3.1
by Patrick Galbraith
Most everything working with client rename |
269 |
static bool sql_connect(DRIZZLE *drizzle, uint wait) |
1
by brian
clean slate |
270 |
{
|
143
by Brian Aker
Bool cleanup. |
271 |
bool info=0; |
1
by brian
clean slate |
272 |
|
273 |
for (;;) |
|
274 |
{
|
|
461
by Monty Taylor
Removed NullS. bu-bye. |
275 |
if (drizzle_connect(drizzle,host,user,opt_password,NULL,tcp_port,NULL,0)) |
1
by brian
clean slate |
276 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
277 |
drizzle->reconnect= 1; |
1
by brian
clean slate |
278 |
if (info) |
279 |
{
|
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
280 |
fputs("\n",stderr); |
281 |
(void) fflush(stderr); |
|
1
by brian
clean slate |
282 |
}
|
283 |
return 0; |
|
284 |
}
|
|
285 |
||
286 |
if (!wait) |
|
287 |
{
|
|
288 |
if (!option_silent) |
|
289 |
{
|
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
290 |
if (!host) |
291 |
host= (char*) LOCAL_HOST; |
|
292 |
||
264.1.21
by forstm1w
Added gettext translations to strings. |
293 |
my_printf_error(0,_("connect to server at '%s' failed\nerror: '%s'"), |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
294 |
error_flags, host, drizzle_error(drizzle)); |
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
295 |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
296 |
if (drizzle_errno(drizzle) == CR_CONN_HOST_ERROR || |
297 |
drizzle_errno(drizzle) == CR_UNKNOWN_HOST) |
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
298 |
{
|
264.1.21
by forstm1w
Added gettext translations to strings. |
299 |
fprintf(stderr,_("Check that drizzled is running on %s"),host); |
300 |
fprintf(stderr,_(" and that the port is %d.\n"), |
|
390.1.5
by Monty Taylor
Moved more functions into drizzle.c as part of the split of code. |
301 |
tcp_port ? tcp_port: drizzle_get_default_port()); |
264.1.21
by forstm1w
Added gettext translations to strings. |
302 |
fprintf(stderr,_("You can check this by doing 'telnet %s %d'\n"), |
390.1.5
by Monty Taylor
Moved more functions into drizzle.c as part of the split of code. |
303 |
host, tcp_port ? tcp_port: drizzle_get_default_port()); |
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
304 |
}
|
1
by brian
clean slate |
305 |
}
|
306 |
return 1; |
|
307 |
}
|
|
365.2.8
by Monty Taylor
More MAX macros. |
308 |
if (wait != UINT32_MAX) |
1
by brian
clean slate |
309 |
wait--; /* One less retry */ |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
310 |
if ((drizzle_errno(drizzle) != CR_CONN_HOST_ERROR) && |
311 |
(drizzle_errno(drizzle) != CR_CONNECTION_ERROR)) |
|
1
by brian
clean slate |
312 |
{
|
264.1.21
by forstm1w
Added gettext translations to strings. |
313 |
fprintf(stderr,_("Got error: %s\n"), drizzle_error(drizzle)); |
1
by brian
clean slate |
314 |
}
|
315 |
else if (!option_silent) |
|
316 |
{
|
|
317 |
if (!info) |
|
318 |
{
|
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
319 |
info=1; |
264.1.21
by forstm1w
Added gettext translations to strings. |
320 |
fputs(_("Waiting for Drizzle server to answer"),stderr); |
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
321 |
(void) fflush(stderr); |
1
by brian
clean slate |
322 |
}
|
323 |
else
|
|
324 |
{
|
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
325 |
putc('.',stderr); |
326 |
(void) fflush(stderr); |
|
1
by brian
clean slate |
327 |
}
|
328 |
}
|
|
329 |
sleep(5); |
|
330 |
}
|
|
331 |
}
|
|
332 |
||
333 |
/*
|
|
334 |
Execute a command.
|
|
335 |
Return 0 on ok
|
|
336 |
-1 on retryable error
|
|
337 |
1 on fatal error
|
|
338 |
*/
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
339 |
static int execute_commands(DRIZZLE *drizzle,int argc, char **argv) |
1
by brian
clean slate |
340 |
{
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
341 |
|
1
by brian
clean slate |
342 |
/*
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
343 |
DRIZZLE documentation relies on the fact that drizzleadmin will
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
344 |
execute commands in the order specified.
|
1
by brian
clean slate |
345 |
If this behaviour is ever changed, Docs should be notified.
|
346 |
*/
|
|
347 |
for (; argc > 0 ; argv++,argc--) |
|
348 |
{
|
|
349 |
switch (find_type(argv[0],&command_typelib,2)) { |
|
350 |
case ADMIN_SHUTDOWN: |
|
351 |
{
|
|
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
352 |
if (opt_verbose) |
264.1.21
by forstm1w
Added gettext translations to strings. |
353 |
printf(_("shutting down drizzled...\n")); |
1
by brian
clean slate |
354 |
|
438.1.9
by Brian Aker
Removed dead shutdown code. |
355 |
if (drizzle_shutdown(drizzle)) |
1
by brian
clean slate |
356 |
{
|
264.1.21
by forstm1w
Added gettext translations to strings. |
357 |
my_printf_error(0, _("shutdown failed; error: '%s'"), error_flags, |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
358 |
drizzle_error(drizzle)); |
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
359 |
return -1; |
1
by brian
clean slate |
360 |
}
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
361 |
drizzle_close(drizzle); /* Close connection to avoid error messages */ |
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
362 |
|
363 |
if (opt_verbose) |
|
264.1.21
by forstm1w
Added gettext translations to strings. |
364 |
printf(_("done\n")); |
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
365 |
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
366 |
argc=1; /* Force SHUTDOWN to be the last command */ |
154.1.2
by Toru Maesaka
further slimdown of mysqladmin and code review fixes |
367 |
break; |
1
by brian
clean slate |
368 |
}
|
369 |
case ADMIN_PING: |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
370 |
drizzle->reconnect=0; /* We want to know of reconnects */ |
371 |
if (!drizzle_ping(drizzle)) |
|
1
by brian
clean slate |
372 |
{
|
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
373 |
if (option_silent < 2) |
264.1.21
by forstm1w
Added gettext translations to strings. |
374 |
puts(_("drizzled is alive")); |
1
by brian
clean slate |
375 |
}
|
376 |
else
|
|
377 |
{
|
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
378 |
if (drizzle_errno(drizzle) == CR_SERVER_GONE_ERROR) |
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
379 |
{
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
380 |
drizzle->reconnect=1; |
381 |
if (!drizzle_ping(drizzle)) |
|
264.1.21
by forstm1w
Added gettext translations to strings. |
382 |
puts(_("connection was down, but drizzled is now alive")); |
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
383 |
}
|
384 |
else
|
|
385 |
{
|
|
264.1.21
by forstm1w
Added gettext translations to strings. |
386 |
my_printf_error(0,_("drizzled doesn't answer to ping, error: '%s'"), |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
387 |
error_flags, drizzle_error(drizzle)); |
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
388 |
return -1; |
389 |
}
|
|
1
by brian
clean slate |
390 |
}
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
391 |
drizzle->reconnect=1; /* Automatic reconnect is default */ |
1
by brian
clean slate |
392 |
break; |
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
393 |
|
1
by brian
clean slate |
394 |
default: |
264.1.21
by forstm1w
Added gettext translations to strings. |
395 |
my_printf_error(0, _("Unknown command: '%-.60s'"), error_flags, argv[0]); |
1
by brian
clean slate |
396 |
return 1; |
397 |
}
|
|
398 |
}
|
|
399 |
return 0; |
|
400 |
}
|
|
401 |
||
402 |
static void print_version(void) |
|
403 |
{
|
|
264.1.21
by forstm1w
Added gettext translations to strings. |
404 |
printf(_("%s Ver %s Distrib %s, for %s on %s\n"),my_progname,ADMIN_VERSION, |
264.1.10
by Monty Taylor
Removed client insistence on version.h stuff. |
405 |
drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE); |
1
by brian
clean slate |
406 |
}
|
407 |
||
408 |
static void usage(void) |
|
409 |
{
|
|
410 |
print_version(); |
|
264.1.21
by forstm1w
Added gettext translations to strings. |
411 |
puts(_("Copyright (C) 2000-2008 MySQL AB")); |
412 |
puts(_("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n")); |
|
413 |
puts(_("Administration program for the drizzled daemon.")); |
|
414 |
printf(_("Usage: %s [OPTIONS] command command....\n"), my_progname); |
|
1
by brian
clean slate |
415 |
my_print_help(my_long_options); |
264.1.21
by forstm1w
Added gettext translations to strings. |
416 |
puts(_("\ |
154.1.1
by Toru Maesaka
Slimmed down mysqladmin to ping and shutdown only. Some dead code were removed too |
417 |
ping Check if server is down\n\ |
264.1.21
by forstm1w
Added gettext translations to strings. |
418 |
shutdown Take server down\n")); |
1
by brian
clean slate |
419 |
}
|