18 #ifndef atrt_config_hpp
19 #define atrt_config_hpp
21 #include <ndb_global.h>
23 #include <BaseString.hpp>
24 #include <NdbAutoPtr.hpp>
27 #include <CpcClient.hpp>
28 #include <Properties.hpp>
36 ERR_SERVERS_FAILED = 102,
37 ERR_MAX_TIME_ELAPSED = 103,
38 ERR_COMMAND_FAILED = 104,
39 ERR_FAILED_TO_START = 105
128 bool parse_args(
int argc,
char** argv);
129 bool setup_config(
atrt_config&,
const char * mysqld);
132 bool setup_files(
atrt_config&,
int setup,
int sshx);
138 bool remove_dir(
const char *,
bool incl =
true);
180 extern const char * g_cwd;
181 extern const char * g_my_cnf;
182 extern const char * g_user;
183 extern const char * g_basedir;
184 extern const char * g_prefix;
185 extern const char * g_prefix1;
186 extern int g_baseport;
188 extern int g_fix_nodeid;
189 extern int g_default_ports;
191 extern const char * g_clusters;
196 inline int lstat(
const char *
name,
struct stat *
buf) {
197 return stat(name, buf);
200 inline int S_ISREG(
int x) {
204 inline int S_ISDIR(
int x) {
212 static inline char* replace_chars(
char *str,
char from,
char to)
216 for(i = 0; str[
i]; i++) {
217 if(i && str[i]==from && str[i-1]!=
' ') {
226 replace_chars((
char*)bs.
c_str(), from,
to);
230 return replace_chars(bs, DIR_SEPARATOR[0]==
'/'?
'\\':
'/', DIR_SEPARATOR[0]);
233 return replace_chars(bs,
'\\',
'/');
235 static inline char* to_fwd_slashes(
char* bs) {
236 return replace_chars(bs,
'\\',
'/');
240 static inline char* replace_drive_letters(
const char* path) {
245 const char cygdrive[] =
"/cygdrive";
246 size_t cyglen = strlen(cygdrive), retval_len;
248 for(i = 0, count = 0; path[
i]; i++) {
249 count += path[
i] ==
':';
251 retval_len = strlen(path) + count * cyglen + 1;
252 retval = (
char*)malloc(retval_len);
254 for(i = j = 0; path[
i]; i++) {
255 if(path[i] && path[i+1]) {
256 if( (!i || isspace(path[i-1]) || ispunct(path[i-1])) && path[i+1] ==
':')
258 assert(path[i+2] ==
'/');
264 retval[j++] = path[
i];
271 static inline int sh(
const char *script){
274 g_logger.
debug(
"sh('%s')", script);
282 char tmp_path[MAX_PATH];
283 if (GetTempPath(
sizeof(tmp_path), tmp_path) == 0)
285 g_logger.
error(
"GetTempPath failed, error: %d", GetLastError());
289 char tmp_file[MAX_PATH];
290 if (GetTempFileName(tmp_path,
"sh_", 0, tmp_file) == 0)
292 g_logger.
error(
"GetTempFileName failed, error: %d", GetLastError());
296 FILE* fp = fopen(tmp_file,
"w");
299 g_logger.
error(
"Cannot open file '%s', error: %d", tmp_file, errno);
305 char* cygwin_script = replace_drive_letters(script);
306 g_logger.
debug(
" - cygwin_script: '%s' ", cygwin_script);
307 fprintf(fp,
"%s", cygwin_script);
315 command.
assfmt(
"sh %s", tmp_file);
316 g_logger.
debug(
" - running '%s' ", command.
c_str());
320 g_logger.
debug(
" - OK!");
322 g_logger.
warning(
"Running the command '%s' as '%s' failed, ret: %d",
332 return system(script);