/** @return Tcl error code */ static int log_setup(int rank) { log_init(); log_normalize(); // Did the user disable logging? int enabled; getenv_integer("TURBINE_LOG", 1, &enabled); if (enabled) { // Should we use a specific log file? char* filename = getenv("TURBINE_LOG_FILE"); if (filename != NULL && strlen(filename) > 0) { bool b = log_file_set(filename); if (!b) { printf("Could not set log file: %s", filename); return TCL_ERROR; } } // Should we prepend the MPI rank (emulate "mpiexec -l")? int log_rank_enabled; getenv_integer("TURBINE_LOG_RANKS", 0, &log_rank_enabled); if (log_rank_enabled) log_rank_set(rank); } else log_enabled(false); return TCL_OK; }
int main (int argc, char **argv) { log_params_set (EUCAWARN, 0, 0); // set log level log_prefix_set ("L "); // only print log level log_file_set (NULL); // log output goes to STANDARD_FILESTREAM char * component = NULL; int opt; while ((opt = getopt (argc, argv, "c:")) != -1) { switch (opt) { case 'c': component = optarg; break; case 'h': default: usage (argv[0]); return 1; } } if (argv[optind]==NULL) { logprintfl (EUCAERROR, "no fault ID is specified (try -h for usage)\n"); return 1; } int ndigits = 0; for (char * c = argv[optind]; * c != '\0'; c++, ndigits++) { if ( ! isdigit (* c)) { logprintfl (EUCAERROR, "invalid fault ID (must be a number)\n"); return 1; } } if (ndigits < 4) { logprintfl (EUCAERROR, "invalid fault ID (must be a 4-digit number)\n"); return 1; } int nfaults = init_eucafaults (component); if (nfaults < 1) { logprintfl (EUCAERROR, "failed to locate fault information (is $EUCALYPTUS set?)\n"); return 1; } // place variable-and-value pairs from command line into the map char_map ** m = NULL; for (int opt = optind + 1; opt < argc; opt++) { logprintfl (EUCADEBUG, "argv[opt]: %s\n", argv[opt]); if ((opt - optind + 1) % 2) { logprintfl (EUCADEBUG, "...now have two, calling c_varmap_alloc()\n"); m = c_varmap_alloc (m, argv[opt - 1], argv[opt]); } } int ret = 0; if (log_eucafault_map (argv[optind], (const char_map **)m) == FALSE) { ret = 1; } if (m) c_varmap_free (m); return ret; }
//! //! Main entry point of the application //! //! @param[in] argc the number of parameter passed on the command line //! @param[in] argv the list of arguments //! //! @return Always return 0 or exit(1) on failure //! int main(int argc, char **argv) { char *sc_hostport = NULL; char *command = NULL; char *ip = NULL; char *instance_id = NULL; char *iqn = NULL; int ch = 0; log_file_set(NULL, NULL); log_params_set(EUCA_LOG_ALL, 0, 1); while ((ch = getopt(argc, argv, "hn:h:s:i:")) != -1) { switch (ch) { case 's': sc_hostport = optarg; break; case 'i': instance_id = optarg; break; case 'h': usage(); // will exit break; case '?': default: fprintf(stderr, "ERROR: unknown parameter (try -h)\n"); exit(1); } } argc -= optind; argv += optind; if (argc > 0) { command = argv[0]; if (argc > 1) { fprintf(stderr, "WARNING: too many parameters (%d), using first one as command\n", argc); for (int i = 0; i <= argc; i++) { if (argv[i]) fprintf(stderr, "%d = %s\n", i, argv[i]); } } } else { fprintf(stderr, "ERROR: command not specified (try -h)\n"); exit(1); } char configFile[BUFSIZE], policyFile[BUFSIZE]; char *euca_home; char sc_url[BUFSIZE]; euca_home = getenv("EUCALYPTUS"); if (!euca_home) { euca_home = ""; } snprintf(configFile, BUFSIZE, EUCALYPTUS_CONF_LOCATION, euca_home); snprintf(policyFile, BUFSIZE, EUCALYPTUS_POLICIES_DIR "/sc-client-policy.xml", euca_home); snprintf(sc_url, BUFSIZE, "http://%s/services/Storage", sc_hostport); char *instances_path; int rc; rc = get_conf_var(configFile, INSTANCE_PATH, &instances_path); char *instance_path = find_instance_path(instances_path, instance_id); eucaVolume volumes[EUCA_MAX_VOLUMES]; char instance_xml[BUFSIZE]; snprintf(instance_xml, BUFSIZE, "%s/instance.xml", instance_path); loop_through_volumes(instance_xml, volumes); ip = find_ip_addr(); iqn = find_local_iqn(); printf("Found local iqn=%s and local ip=%s\n", iqn, ip); for(int i = 0; i < EUCA_MAX_VOLUMES; i++){ if(strlen(volumes[i].state) == 0 || strcmp(volumes[i].state, VOL_STATE_ATTACHED)) continue; printf("Performing operation on volume %d\nid=%s\ntoken=%s\ndevice=%s\nconnectionstring=%s\nbus=%s\nserial=%s\n", i, volumes[i].id, volumes[i].attachment_token, volumes[i].device, volumes[i].connection_string, volumes[i].bus, volumes[i].serial); /***********************************************************/ if (!strcmp(command, "ConnectVolumes")) { CHECK_PARAM(ip, "ip"); CHECK_PARAM(iqn, "iqn"); CHECK_PARAM(sc_hostport, "sc host and port"); setup_iscsi(euca_home, configFile); euca_init_cert(); char *libvirt_xml = NULL; ebs_volume_data *vol_data = NULL; if (connect_ebs_volume(volumes[i].id, volumes[i].serial, volumes[i].bus, sc_url, volumes[i].attachment_token, 1, policyFile, ip, iqn, &libvirt_xml, &vol_data) != EUCA_OK) { fprintf(stderr, "Error connecting ebs volume %s\n", volumes[i].id); exit(1); } /***********************************************************/ } else if (!strcmp(command, "DisconnectVolumes")) { CHECK_PARAM(ip, "ip"); CHECK_PARAM(iqn, "iqn"); CHECK_PARAM(sc_hostport, "sc host and port"); setup_iscsi(euca_home, configFile); euca_init_cert(); if (disconnect_ebs_volume(sc_url, 1, policyFile, volumes[i].attachment_token, volumes[i].connection_string, ip, iqn) != EUCA_OK) { fprintf(stderr, "Error disconnecting ebs volume %s.\n", volumes[i].id); exit(1); } /***********************************************************/ } else { fprintf(stderr, "ERROR: command %s unknown (try -h)\n", command); exit(1); } } _exit(0); }
//! //! Set the log file, log level and log roll number //! //! @param[in] file the log file name string //! @param[in] log_level_in the log level to set //! @param[in] log_roll_number_in the log rolling number to set //! //! @return the result of the log_file_set() call. //! //! @see log_file_set() //! @see log_params_set() //! //! @pre The given values must be valid. //! //! @post The values are set and log_max_size_bytes will be set to MAXLOGFILESIZE //! //! @todo legacy function, to be removed when no longer in use //! int logfile(const char *file, int log_level_in, int log_roll_number_in) { log_params_set(log_level_in, log_roll_number_in, MAXLOGFILESIZE); return log_file_set(file); }
int main(int argc, char **argv) { /* Run main garbage collector when quiting the daemon */ gc_attach(main_gc); /* Catch all exit signals for gc */ gc_catch(); loglevel = LOG_INFO; log_file_disable(); log_shell_enable(); char *logfile = malloc(strlen(LOG_FILE)+1); strcpy(logfile, LOG_FILE); log_file_set(logfile); sfree((void *)&logfile); prevMessage = malloc(4); memset(prevMessage, '\0', 4); progname = malloc(14); strcpy(progname, "splash-daemon"); struct socket_callback_t socket_callback; struct options_t *options = NULL; char *args = NULL; char buffer[BUFFER_SIZE]; int f; options_add(&options, 'H', "help", no_value, 0, NULL); options_add(&options, 'V', "version", no_value, 0, NULL); options_add(&options, 'D', "nodaemon", no_value, 0, NULL); while (1) { int c; c = options_parse(&options, argc, argv, 1, &args); if (c == -1) break; switch(c) { case 'H': printf("Usage: %s [options]\n", progname); printf("\t -H --help\t\tdisplay usage summary\n"); printf("\t -V --version\t\tdisplay version\n"); printf("\t -S --settings\t\tsettings file\n"); printf("\t -D --nodaemon\t\tdo not daemonize and\n"); printf("\t\t\t\tshow debug information\n"); return (EXIT_SUCCESS); break; case 'V': printf("%s %s\n", progname, "1.0"); return (EXIT_SUCCESS); break; case 'D': nodaemon=1; break; default: printf("Usage: %s [options]\n", progname); return (EXIT_FAILURE); break; } } options_delete(options); pid_file = malloc(sizeof(PID_FILE)+1); strcpy(pid_file, PID_FILE); template_file = malloc(14); strcpy(template_file, "template.json"); if((f = open(pid_file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) != -1) { if(read(f, buffer, BUFFER_SIZE) != -1) { //If the file is empty, create a new process if(!atoi(buffer)) { running = 0; } else { //Check if the process is running kill(atoi(buffer), 0); //If not, create a new process if(errno == ESRCH) { running = 0; } } } } else { logprintf(LOG_ERR, "could not open / create pid_file %s", pid_file); return EXIT_FAILURE; } close(f); if(nodaemon == 1 || running == 1) { log_level_set(LOG_DEBUG); } if(running == 1) { nodaemon=1; logprintf(LOG_NOTICE, "already active (pid %d)", atoi(buffer)); return EXIT_FAILURE; } if(nodaemon == 0) { deamonize(); socket_start(PORT); fb_init(); } else { socket_start(PORT); } if(template_read(template_file) == EXIT_FAILURE) { logprintf(LOG_NOTICE, "failed to read template file %s", template_file); main_gc(); return EXIT_FAILURE; } if(nodaemon == 1) { //template_print(); } //initialise all socket_clients and handshakes to 0 so not checked memset(socket_clients, 0, sizeof(socket_clients)); socket_callback.client_disconnected_callback = NULL; socket_callback.client_connected_callback = NULL; socket_callback.client_data_callback = &socket_parse_data; main_draw(); /* Make sure the server part is non-blocking by creating a new thread */ pthread_create(&pth, NULL, &update_progress, (void *)NULL); socket_wait((void *)&socket_callback); while(main_loop) { sleep(1); } return EXIT_FAILURE; }
int logfile(char *file, int log_level_in, int log_roll_number_in) // TODO: legacy function, to be removed when no longer in use { log_params_set (log_level_in, log_roll_number_in, 0); return log_file_set (file); }