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.

475 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, "--connect_timeout=10");
  146. add_arg(&al, "-w");
  147. #endif
  148. add_arg(&al, "--host=localhost");
  149. add_arg(&al, "ping");
  150. // NetWare does not support the connect timeout in the TCP/IP stack
  151. // -- we will try the ping multiple times
  152. for(i = 0; (i < TRY_MAX)
  153. && (err = spawn(mysqladmin_file, &al, TRUE, NULL,
  154. trash, NULL)); i++) sleep(1);
  155. // free args
  156. free_args(&al);
  157. return err;
  158. }
  159. /******************************************************************************
  160. spawn()
  161. Spawn the given path with the given arguments.
  162. ******************************************************************************/
  163. int spawn(char *path, arg_list_t *al, int join, char *input,
  164. char *output, char *error)
  165. {
  166. pid_t pid;
  167. int result = 0;
  168. wiring_t wiring = { FD_UNUSED, FD_UNUSED, FD_UNUSED };
  169. unsigned long flags = PROC_CURRENT_SPACE | PROC_INHERIT_CWD;
  170. // open wiring
  171. if (input)
  172. wiring.infd = open(input, O_RDONLY);
  173. if (output)
  174. wiring.outfd = open(output, O_WRONLY | O_CREAT | O_TRUNC);
  175. if (error)
  176. wiring.errfd = open(error, O_WRONLY | O_CREAT | O_TRUNC);
  177. // procve requires a NULL
  178. add_arg(al, NULL);
  179. // go
  180. pid = procve(path, flags, NULL, &wiring, NULL, NULL, 0,
  181. NULL, (const char **)al->argv);
  182. if (pid == -1)
  183. {
  184. result = -1;
  185. }
  186. else if (join)
  187. {
  188. waitpid(pid, &result, 0);
  189. }
  190. // close wiring
  191. if (wiring.infd != -1)
  192. close(wiring.infd);
  193. if (wiring.outfd != -1)
  194. close(wiring.outfd);
  195. if (wiring.errfd != -1)
  196. close(wiring.errfd);
  197. return result;
  198. }
  199. /******************************************************************************
  200. stop_server()
  201. Stop the server with the given port and pid file.
  202. ******************************************************************************/
  203. int stop_server(char *bin_dir, char *user, char *password, int port,
  204. char *pid_file,char *tmp_dir)
  205. {
  206. arg_list_t al;
  207. int err, i, argc = 0;
  208. char mysqladmin_file[PATH_MAX];
  209. char trash[PATH_MAX];
  210. // mysqladmin file
  211. snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir);
  212. snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir);
  213. // args
  214. init_args(&al);
  215. add_arg(&al, "%s", mysqladmin_file);
  216. add_arg(&al, "--no-defaults");
  217. add_arg(&al, "--port=%u", port);
  218. add_arg(&al, "--user=%s", user);
  219. add_arg(&al, "--password=%s", password);
  220. add_arg(&al, "--shutdown_timeout=20");
  221. add_arg(&al, "shutdown");
  222. // spawn
  223. if ((err = spawn(mysqladmin_file, &al, TRUE, NULL,
  224. trash, NULL)) == 0)
  225. {
  226. sleep_until_file_deleted(pid_file);
  227. }
  228. else
  229. {
  230. pid_t pid = get_server_pid(pid_file);
  231. // shutdown failed - kill server
  232. kill_server(pid);
  233. sleep(TRY_MAX);
  234. // remove pid file if possible
  235. err = remove(pid_file);
  236. }
  237. // free args
  238. free_args(&al);
  239. return err;
  240. }
  241. /******************************************************************************
  242. get_server_pid()
  243. Get the VM id with the given pid file.
  244. ******************************************************************************/
  245. pid_t get_server_pid(char *pid_file)
  246. {
  247. char buf[PATH_MAX];
  248. int fd, err;
  249. char *p;
  250. pid_t id;
  251. // discover id
  252. fd = open(pid_file, O_RDONLY);
  253. err = read(fd, buf, PATH_MAX);
  254. close(fd);
  255. if (err > 0)
  256. {
  257. // terminate string
  258. if ((p = strchr(buf, '\n')) != NULL)
  259. {
  260. *p = NULL;
  261. // check for a '\r'
  262. if ((p = strchr(buf, '\r')) != NULL)
  263. {
  264. *p = NULL;
  265. }
  266. }
  267. else
  268. {
  269. buf[err] = NULL;
  270. }
  271. id = strtol(buf, NULL, 0);
  272. }
  273. return id;
  274. }
  275. /******************************************************************************
  276. kill_server()
  277. Force a kill of the server with the given pid.
  278. ******************************************************************************/
  279. void kill_server(pid_t pid)
  280. {
  281. if (pid > 0)
  282. {
  283. // destroy vm
  284. NXVmDestroy(pid);
  285. }
  286. }
  287. /******************************************************************************
  288. del_tree()
  289. Delete the directory and subdirectories.
  290. ******************************************************************************/
  291. void del_tree(char *dir)
  292. {
  293. DIR *parent = opendir(dir);
  294. DIR *entry;
  295. char temp[PATH_MAX];
  296. if (parent == NULL)
  297. {
  298. return;
  299. }
  300. while((entry = readdir(parent)) != NULL)
  301. {
  302. // create long name
  303. snprintf(temp, PATH_MAX, "%s/%s", dir, entry->d_name);
  304. if (entry->d_name[0] == '.')
  305. {
  306. // Skip
  307. }
  308. else if (S_ISDIR(entry->d_type))
  309. {
  310. // delete subdirectory
  311. del_tree(temp);
  312. }
  313. else
  314. {
  315. // remove file
  316. remove(temp);
  317. }
  318. }
  319. // remove directory
  320. rmdir(dir);
  321. }
  322. /******************************************************************************
  323. removef()
  324. ******************************************************************************/
  325. int removef(const char *format, ...)
  326. {
  327. va_list ap;
  328. char path[PATH_MAX];
  329. va_start(ap, format);
  330. vsnprintf(path, PATH_MAX, format, ap);
  331. va_end(ap);
  332. return remove(path);
  333. }
  334. /******************************************************************************
  335. get_basedir()
  336. ******************************************************************************/
  337. void get_basedir(char *argv0, char *basedir)
  338. {
  339. char temp[PATH_MAX];
  340. char *p;
  341. ASSERT(argv0 != NULL);
  342. ASSERT(basedir != NULL);
  343. strcpy(temp, strlwr(argv0));
  344. while((p = strchr(temp, '\\')) != NULL) *p = '/';
  345. if ((p = strindex(temp, "/bin/")) != NULL)
  346. {
  347. *p = NULL;
  348. strcpy(basedir, temp);
  349. }
  350. }