You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

477 lines
10 KiB

Changed prototype of killed_ptr() to make it more portable Applied patches for Netware innobase/include/os0thread.h: Applied patches for Netware innobase/os/os0thread.c: Applied patches for Netware libmysql/libmysql.c: Applied patches for Netware libmysql/libmysql.def: Applied patches for Netware myisam/myisamchk.c: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable myisam/myisamdef.h: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable mysql-test/t/rpl_relayspace-slave.opt: Applied patches for Netware mysys/my_pthread.c: Applied patches for Netware mysys/my_static.h: Portability fix netware/BUILD/compile-linux-tools: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable netware/BUILD/mwenv: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable netware/BUILD/nwbootstrap: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable netware/my_manage.c: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable netware/mysql_fix_privilege_tables.pl: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable netware/mysql_test_run.c: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable netware/static_init_db.sql: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable scripts/make_binary_distribution.sh: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable sql/filesort.cc: Changed prototype of killed_ptr() to make it more portable sql/ha_myisam.cc: Changed prototype of killed_ptr() to make it more portable sql/mysqld.cc: Fixed some typos for Netware sql/sql_bitmap.h: Applied patches for Netware sql/sql_class.h: Changed prototype of killed_ptr() to make it more portable sql/sql_insert.cc: safety fix strings/my_strtoll10.c: Added comment
22 years ago
Changed prototype of killed_ptr() to make it more portable Applied patches for Netware innobase/include/os0thread.h: Applied patches for Netware innobase/os/os0thread.c: Applied patches for Netware libmysql/libmysql.c: Applied patches for Netware libmysql/libmysql.def: Applied patches for Netware myisam/myisamchk.c: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable myisam/myisamdef.h: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable mysql-test/t/rpl_relayspace-slave.opt: Applied patches for Netware mysys/my_pthread.c: Applied patches for Netware mysys/my_static.h: Portability fix netware/BUILD/compile-linux-tools: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable netware/BUILD/mwenv: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable netware/BUILD/nwbootstrap: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable netware/my_manage.c: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable netware/mysql_fix_privilege_tables.pl: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable netware/mysql_test_run.c: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable netware/static_init_db.sql: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable scripts/make_binary_distribution.sh: Applied patches for Netware Changed prototype of killed_ptr() to make it more portable sql/filesort.cc: Changed prototype of killed_ptr() to make it more portable sql/ha_myisam.cc: Changed prototype of killed_ptr() to make it more portable sql/mysqld.cc: Fixed some typos for Netware sql/sql_bitmap.h: Applied patches for Netware sql/sql_class.h: Changed prototype of killed_ptr() to make it more portable sql/sql_insert.cc: safety fix strings/my_strtoll10.c: Added comment
22 years ago
  1. /*
  2. Copyright (c) 2003 Novell, Inc. All Rights Reserved.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. */
  15. #include <stdio.h>
  16. #include <errno.h>
  17. #include <dirent.h>
  18. #include <string.h>
  19. #include <screen.h>
  20. #include <proc.h>
  21. #include <ctype.h>
  22. #include <sys/stat.h>
  23. #include <fcntl.h>
  24. #include <assert.h>
  25. #include "my_manage.h"
  26. /******************************************************************************
  27. macros
  28. ******************************************************************************/
  29. /******************************************************************************
  30. global variables
  31. ******************************************************************************/
  32. /******************************************************************************
  33. functions
  34. ******************************************************************************/
  35. /******************************************************************************
  36. init_args()
  37. Init an argument list.
  38. ******************************************************************************/
  39. void init_args(arg_list_t *al)
  40. {
  41. ASSERT(al != NULL);
  42. al->argc = 0;
  43. al->size = ARG_BUF;
  44. al->argv = malloc(al->size * sizeof(char *));
  45. ASSERT(al->argv != NULL);
  46. return;
  47. }
  48. /******************************************************************************
  49. add_arg()
  50. Add an argument to a list.
  51. ******************************************************************************/
  52. void add_arg(arg_list_t *al, const char *format, ...)
  53. {
  54. va_list ap;
  55. char temp[PATH_MAX];
  56. ASSERT(al != NULL);
  57. // increase size
  58. if (al->argc >= al->size)
  59. {
  60. al->size += ARG_BUF;
  61. al->argv = realloc(al->argv, al->size * sizeof(char *));
  62. ASSERT(al->argv != NULL);
  63. }
  64. if (format)
  65. {
  66. va_start(ap, format);
  67. vsprintf(temp, format, ap);
  68. va_end(ap);
  69. al->argv[al->argc] = malloc(strlen(temp)+1);
  70. ASSERT(al->argv[al->argc] != NULL);
  71. strcpy(al->argv[al->argc], temp);
  72. ++(al->argc);
  73. }
  74. else
  75. {
  76. al->argv[al->argc] = NULL;
  77. }
  78. return;
  79. }
  80. /******************************************************************************
  81. free_args()
  82. Free an argument list.
  83. ******************************************************************************/
  84. void free_args(arg_list_t *al)
  85. {
  86. int i;
  87. ASSERT(al != NULL);
  88. for(i = 0; i < al->argc; i++)
  89. {
  90. ASSERT(al->argv[i] != NULL);
  91. free(al->argv[i]);
  92. al->argv[i] = NULL;
  93. }
  94. free(al->argv);
  95. al->argc = 0;
  96. al->argv = NULL;
  97. return;
  98. }
  99. /******************************************************************************
  100. sleep_until_file_deleted()
  101. Sleep until the given file is no longer found.
  102. ******************************************************************************/
  103. int sleep_until_file_deleted(char *pid_file)
  104. {
  105. struct stat buf;
  106. int i, err;
  107. for(i = 0; (i < TRY_MAX) && (err = !stat(pid_file, &buf)); i++) sleep(1);
  108. if (err != 0) err = errno;
  109. return err;
  110. }
  111. /******************************************************************************
  112. sleep_until_file_exists()
  113. Sleep until the given file exists.
  114. ******************************************************************************/
  115. int sleep_until_file_exists(char *pid_file)
  116. {
  117. struct stat buf;
  118. int i, err;
  119. for(i = 0; (i < TRY_MAX) && (err = stat(pid_file, &buf)); i++) sleep(1);
  120. if (err != 0) err = errno;
  121. return err;
  122. }
  123. /******************************************************************************
  124. wait_for_server_start()
  125. Wait for the server on the given port to start.
  126. ******************************************************************************/
  127. int wait_for_server_start(char *bin_dir, char *user, char *password, int port,char *tmp_dir)
  128. {
  129. arg_list_t al;
  130. int err, i;
  131. char mysqladmin_file[PATH_MAX];
  132. char trash[PATH_MAX];
  133. // mysqladmin file
  134. snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir);
  135. snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir);
  136. // args
  137. init_args(&al);
  138. add_arg(&al, "%s", mysqladmin_file);
  139. add_arg(&al, "--no-defaults");
  140. add_arg(&al, "--port=%u", port);
  141. add_arg(&al, "--user=%s", user);
  142. add_arg(&al, "--password=%s", password);
  143. add_arg(&al, "--silent");
  144. #ifdef NOT_USED
  145. add_arg(&al, "-O");
  146. add_arg(&al, "connect_timeout=10");
  147. add_arg(&al, "-w");
  148. #endif
  149. add_arg(&al, "--host=localhost");
  150. add_arg(&al, "ping");
  151. // NetWare does not support the connect timeout in the TCP/IP stack
  152. // -- we will try the ping multiple times
  153. for(i = 0; (i < TRY_MAX)
  154. && (err = spawn(mysqladmin_file, &al, TRUE, NULL,
  155. trash, NULL)); i++) sleep(1);
  156. // free args
  157. free_args(&al);
  158. return err;
  159. }
  160. /******************************************************************************
  161. spawn()
  162. Spawn the given path with the given arguments.
  163. ******************************************************************************/
  164. int spawn(char *path, arg_list_t *al, int join, char *input,
  165. char *output, char *error)
  166. {
  167. pid_t pid;
  168. int result = 0;
  169. wiring_t wiring = { FD_UNUSED, FD_UNUSED, FD_UNUSED };
  170. unsigned long flags = PROC_CURRENT_SPACE | PROC_INHERIT_CWD;
  171. // open wiring
  172. if (input)
  173. wiring.infd = open(input, O_RDONLY);
  174. if (output)
  175. wiring.outfd = open(output, O_WRONLY | O_CREAT | O_TRUNC);
  176. if (error)
  177. wiring.errfd = open(error, O_WRONLY | O_CREAT | O_TRUNC);
  178. // procve requires a NULL
  179. add_arg(al, NULL);
  180. // go
  181. pid = procve(path, flags, NULL, &wiring, NULL, NULL, 0,
  182. NULL, (const char **)al->argv);
  183. if (pid == -1)
  184. {
  185. result = -1;
  186. }
  187. else if (join)
  188. {
  189. waitpid(pid, &result, 0);
  190. }
  191. // close wiring
  192. if (wiring.infd != -1)
  193. close(wiring.infd);
  194. if (wiring.outfd != -1)
  195. close(wiring.outfd);
  196. if (wiring.errfd != -1)
  197. close(wiring.errfd);
  198. return result;
  199. }
  200. /******************************************************************************
  201. stop_server()
  202. Stop the server with the given port and pid file.
  203. ******************************************************************************/
  204. int stop_server(char *bin_dir, char *user, char *password, int port,
  205. char *pid_file,char *tmp_dir)
  206. {
  207. arg_list_t al;
  208. int err, i, argc = 0;
  209. char mysqladmin_file[PATH_MAX];
  210. char trash[PATH_MAX];
  211. // mysqladmin file
  212. snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir);
  213. snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir);
  214. // args
  215. init_args(&al);
  216. add_arg(&al, "%s", mysqladmin_file);
  217. add_arg(&al, "--no-defaults");
  218. add_arg(&al, "--port=%u", port);
  219. add_arg(&al, "--user=%s", user);
  220. add_arg(&al, "--password=%s", password);
  221. add_arg(&al, "-O");
  222. add_arg(&al, "shutdown_timeout=20");
  223. add_arg(&al, "shutdown");
  224. // spawn
  225. if ((err = spawn(mysqladmin_file, &al, TRUE, NULL,
  226. trash, NULL)) == 0)
  227. {
  228. sleep_until_file_deleted(pid_file);
  229. }
  230. else
  231. {
  232. pid_t pid = get_server_pid(pid_file);
  233. // shutdown failed - kill server
  234. kill_server(pid);
  235. sleep(TRY_MAX);
  236. // remove pid file if possible
  237. err = remove(pid_file);
  238. }
  239. // free args
  240. free_args(&al);
  241. return err;
  242. }
  243. /******************************************************************************
  244. get_server_pid()
  245. Get the VM id with the given pid file.
  246. ******************************************************************************/
  247. pid_t get_server_pid(char *pid_file)
  248. {
  249. char buf[PATH_MAX];
  250. int fd, err;
  251. char *p;
  252. pid_t id;
  253. // discover id
  254. fd = open(pid_file, O_RDONLY);
  255. err = read(fd, buf, PATH_MAX);
  256. close(fd);
  257. if (err > 0)
  258. {
  259. // terminate string
  260. if ((p = strchr(buf, '\n')) != NULL)
  261. {
  262. *p = NULL;
  263. // check for a '\r'
  264. if ((p = strchr(buf, '\r')) != NULL)
  265. {
  266. *p = NULL;
  267. }
  268. }
  269. else
  270. {
  271. buf[err] = NULL;
  272. }
  273. id = strtol(buf, NULL, 0);
  274. }
  275. return id;
  276. }
  277. /******************************************************************************
  278. kill_server()
  279. Force a kill of the server with the given pid.
  280. ******************************************************************************/
  281. void kill_server(pid_t pid)
  282. {
  283. if (pid > 0)
  284. {
  285. // destroy vm
  286. NXVmDestroy(pid);
  287. }
  288. }
  289. /******************************************************************************
  290. del_tree()
  291. Delete the directory and subdirectories.
  292. ******************************************************************************/
  293. void del_tree(char *dir)
  294. {
  295. DIR *parent = opendir(dir);
  296. DIR *entry;
  297. char temp[PATH_MAX];
  298. if (parent == NULL)
  299. {
  300. return;
  301. }
  302. while((entry = readdir(parent)) != NULL)
  303. {
  304. // create long name
  305. snprintf(temp, PATH_MAX, "%s/%s", dir, entry->d_name);
  306. if (entry->d_name[0] == '.')
  307. {
  308. // Skip
  309. }
  310. else if (S_ISDIR(entry->d_type))
  311. {
  312. // delete subdirectory
  313. del_tree(temp);
  314. }
  315. else
  316. {
  317. // remove file
  318. remove(temp);
  319. }
  320. }
  321. // remove directory
  322. rmdir(dir);
  323. }
  324. /******************************************************************************
  325. removef()
  326. ******************************************************************************/
  327. int removef(const char *format, ...)
  328. {
  329. va_list ap;
  330. char path[PATH_MAX];
  331. va_start(ap, format);
  332. vsnprintf(path, PATH_MAX, format, ap);
  333. va_end(ap);
  334. return remove(path);
  335. }
  336. /******************************************************************************
  337. get_basedir()
  338. ******************************************************************************/
  339. void get_basedir(char *argv0, char *basedir)
  340. {
  341. char temp[PATH_MAX];
  342. char *p;
  343. ASSERT(argv0 != NULL);
  344. ASSERT(basedir != NULL);
  345. strcpy(temp, strlwr(argv0));
  346. while((p = strchr(temp, '\\')) != NULL) *p = '/';
  347. if ((p = strindex(temp, "/bin/")) != NULL)
  348. {
  349. *p = NULL;
  350. strcpy(basedir, temp);
  351. }
  352. }