143{
144
147
150
151
153
155
157 printf(
"Error: trying to use a remote connection to host \"%s\". odbinit must run locally. Sorry.\n",
host_name);
158 exit(1);
159 }
160
166
167
168 for (
int i = 1;
i <
argc;
i++) {
170
185 } else {
187 }
188 }
189
191
192#ifndef NO_LOCAL_ROUTINES
193
195 printf(
"Creating a new exptab file in the current directory...\n");
196
200 printf(
"Error: exptab already exists in the current directory. Sorry...\n");
201 exit(1);
202 }
203
206 }
208 printf(
"Error: experiment name \"%s\" should not contain a space character. Sorry...\n",
exp_name);
209 exit(1);
210 }
213 printf(
"Error: env.variable PWD is not defined or is empty. Sorry...\n");
214 exit(1);
215 }
217 printf(
"Error: env.variable PWD value \"%s\" should not contain a space character. Sorry...\n",
pwd);
218 exit(1);
219 }
220 const char* user =
getenv(
"USER");
221 if (!user ||
strlen(user)<1) {
222 printf(
"Error: env.variable USER is not defined or is empty. Sorry...\n");
223 exit(1);
224 }
226 printf(
"Error: env.variable USER value \"%s\" should not contain a space character. Sorry...\n", user);
227 exit(1);
228 }
229 printf(
"Experiment name [%s], experiment directory [%s], username [%s]\n",
exp_name,
pwd, user);
230
234 exit(1);
235 }
236
239
241 printf(
"Please define env.variable MIDAS_EXPTAB=%s/%s\n",
pwd,
"exptab");
244 exit(0);
245 }
246
248 printf(
"Creating a new environment settings file in the current directory...\n");
249
250
251
255 printf(
"Error: env.sh already exists in the current directory. Sorry...\n");
256 exit(1);
257 }
258
262 printf(
"Error: env.csh already exists in the current directory. Sorry...\n");
263 exit(1);
264 }
265
266
267
270 printf(
"Error: env.variable PWD is not defined or is empty. Sorry...\n");
271 exit(1);
272 }
273
278
279
280
282
283 if (
argv0[0] !=
'/') {
285 printf(
"Please run odbinit using the full path, i.e. run $HOME/packages/midas/linux/bin/odbinit\n");
288 exit(1);
289 }
290
291
292
294
295 if (
argv0[0] ==
'/') {
297 } else {
301 }
302
306 }
309 }
312 }
313
315
316
317
318 std::string path;
319
320 {
321 if (
argv0[0] ==
'/') {
323 } else {
325 path += "/";
327 }
328
329 std::vector<std::string>
aa =
split(
"/", path);
332 }
333
335 }
336
338
339
340
344 exit(1);
345 }
346
350 exit(1);
351 }
352
355
358
361
362 fprintf(
fpb,
"export PATH=$PATH:\"%s\"\n", path.c_str());
363 fprintf(
fpc,
"setenv PATH $PATH\\:\"%s\"\n", path.c_str());
364
365 fprintf(
fpb,
"# define mserver connection\n");
367 fprintf(
fpb,
"%s) unset MIDAS_SERVER_HOST ;;\n", hostname.c_str());
368 fprintf(
fpb,
"*) export MIDAS_SERVER_HOST=%s ;;\n", hostname.c_str());
370
371 fprintf(
fpc,
"# define mserver connection\n");
377 fprintf(
fpc,
"setenv MIDAS_SERVER_HOST %s\n", hostname.c_str());
379
382
385
387 printf(
"Please source env.sh or env.csh\n");
390 exit(0);
391 }
392
393
394
395 printf(
"Checking MIDASSYS...");
397
400 printf(
"Error: Env.variable MIDASSYS is not defined.\n");
403 printf(
"Please run odbinit --env\n");
406 exit(1);
407 }
408
410
413
415
417 printf(
"Error: cm_list_experiments() status %d\n",
status);
419 printf(
"Cannot get the list of experiments, maybe the exptab file is missing.\n");
421 printf(
"To create a new exptab file in the current directory, run odbinit --exptab -e new_experiment_name\n");
424 exit(1);
425 }
426
428
430 printf(
"Cannot get the name of the exptab file. Sorry...\n");
431 exit(1);
432 }
433
435
442 printf(
" <-- selected experiment");
445 }
447 }
448
450 printf(
"Specified experiment \"%s\" not found in exptab. Sorry...\n",
exp_name);
451 exit(1);
452 }
453
456
458
460 printf(
"Specified experiment \"%s\" not found in exptab, cm_get_exptab() returned %d. Sorry...\n",
exp_name,
status);
461 exit(1);
462 }
463
465 printf(
"Checking exptab... selected experiment \"%s\", experiment directory \"%s\"\n",
exp_name,
exp_dir.c_str());
466
470
472
473 {
474 printf(
"Checking experiment directory \"%s\"\n",
exp_dir.c_str());
475
476#ifdef S_ISDIR
479
480 if (v != 0) {
483 exit(1);
484 }
485
487 printf(
"Invalid experiment directory \"%s\" is not a directory\n",
exp_dir.c_str());
489 exit(1);
490 }
491#else
492#error No support for stat() and S_ISDIR on this system!
493#endif
494 }
495
496 std::string odb_path;
497
498 {
499 std::string path;
501 path += ".ODB.SHM";
502
506 printf(
"Found existing ODB save file: \"%s\"\n", path.c_str());
508
509
510
511 odb_path = path;
512 } else {
513 printf(
"Looks like this experiment ODB is already initialized.\n");
514 printf(
"To create new empty ODB, please rerun odbinit with the \"--cleanup\" option.\n");
515 exit(1);
516 }
517 } else {
518 printf(
"Good: no ODB save file\n");
519 }
520 }
521
523 printf(
"Checking shared memory...\n");
524
525 {
526 printf(
"Deleting old ODB shared memory...\n");
530 printf(
"Good: no ODB shared memory\n");
532 printf(
"Deleted existing ODB shared memory, please check that all MIDAS programs are stopped and try again.\n");
533 exit(1);
534 } else {
536 printf(
"Please check that all MIDAS programs are stopped and try again.\n");
537 exit(1);
538 }
539 }
540 }
541
542 {
543 printf(
"Deleting old ODB semaphore...\n");
549 }
550 }
551
552 if (odb_path.length() > 0 &&
cleanup) {
558 printf(
"Preserving old ODB save file \"%s\" to \"%s\"\n", odb_path.c_str(),
path1.c_str());
564 exit(1);
565 }
566 }
567 }
568
570
571 {
572 printf(
"Checking ODB size...\n");
573
575
577
581 path1 +=
".ODB_SIZE.TXT";
582
583 printf(
"ODB size file is \"%s\"\n",
path1.c_str());
584
587 printf(
"ODB size file \"%s\" does not exist, creating it...\n",
path1.c_str());
592 exit(1);
593 }
595 {
598 }
599 else
600 {
602 }
604
607 printf(
"Creation of ODB size file \"%s\" somehow failed.\n",
path1.c_str());
609 exit(1);
610 }
611 }
612
615 {
616 char buf[256];
617 char *s =
fgets(buf,
sizeof(buf),
fp);
618 if (s) {
621 }
622 }
624
626
629
632 printf(
"1) to create ODB with old size, please try again without the \"-s\" switch.\n");
633 printf(
"2) to create ODB with new size, please delete the file \"%s\" and try again.\n",
path1.c_str());
634 exit(1);
635 }
636 }
640
641
642 {
644 printf(
"Creating ODB...\n");
646 printf(
"Creating ODB... db_open_database() status %d\n",
status);
648 printf(
"Something went wrong... continuing...\n");
649 }
650 printf(
"Saving ODB...\n");
652 printf(
"Saving ODB... db_close_database() status %d\n",
status);
654 printf(
"Something went wrong... continuing...\n");
655 }
656 }
657
658 printf(
"Connecting to experiment...\n");
659
661
663 printf(
"Error: cm_connect_experiment() status %d\n",
status);
665 exit(1);
666 }
667
670
672
673 {
679 printf(
"Checking experiment name... status %d, found \"%s\"\n",
status, buf);
680
681
682 }
683
684 printf(
"Disconnecting from experiment...\n");
686
689
690#else
691 printf(
"this version of odbinit is built with NO_LOCAL_ROUTINES and it will not work. odbinit only works locally!\n");
692#endif
693
694 return 0;
695}
INT cm_set_path(const char *path)
INT cm_get_experiment_database(HNDLE *hDB, HNDLE *hKeyClient)
INT cm_list_experiments_local(STRING_LIST *exp_names)
INT cm_connect_experiment1(const char *host_name, const char *default_exp_name, const char *client_name, void(*func)(char *), INT odb_size, DWORD watchdog_timeout)
INT cm_disconnect_experiment(void)
int cm_get_exptab(const char *expname, std::string *dir, std::string *user)
std::string cm_get_exptab_filename()
INT cm_get_environment(char *host_name, int host_name_size, char *exp_name, int exp_name_size)
INT cm_set_experiment_name(const char *name)
std::string ss_gethostname()
INT ss_suspend_init_odb_port()
INT ss_semaphore_create(const char *name, HNDLE *semaphore_handle)
INT ss_shm_delete(const char *name)
INT ss_semaphore_delete(HNDLE semaphore_handle, INT destroy_flag)
INT cm_msg_flush_buffer()
BOOL equal_ustring(const char *str1, const char *str2)
INT db_get_value(HNDLE hDB, HNDLE hKeyRoot, const char *key_name, void *data, INT *buf_size, DWORD type, BOOL create)
INT db_open_database(const char *xdatabase_name, INT database_size, HNDLE *hDB, const char *client_name)
INT db_close_database(HNDLE hDB)
char exp_name[NAME_LENGTH]
char host_name[HOST_NAME_LENGTH]
#define DEFAULT_WATCHDOG_TIMEOUT
std::vector< std::string > STRING_LIST
static std::string join(const char *sep, const std::vector< std::string > &v)
static std::string to_string(int v)
static std::vector< std::string > remove_dot_dot(const std::vector< std::string > &v)
int DecodeSize(const char *s)
std::pair< double, std::string > HumanUnits(int odb_size)
static std::vector< std::string > split(const char *sep, const std::string &s)