int read_params() { /* read our parameters */ char* value = NULL; scr_param_init(); /* set file copy buffer size (file chunk size) */ if ((value = scr_param_get("SCR_FILE_BUF_SIZE")) != NULL) { scr_file_buf_size = atoi(value); } /* set number of secs to sleep between reading file */ if ((value = scr_param_get("SCR_TRANSFER_SECS")) != NULL) { float secs = 0.0; sscanf(value, "%f", &secs); scr_transfer_secs = (double) secs; } scr_param_finalize(); return SCR_SUCCESS; }
/* initialize the logging */ int scr_log_init() { int rc = SCR_SUCCESS; /* read in parameters */ char* value = NULL; scr_param_init(); /* check whether SCR logging DB is enabled */ if ((value = scr_param_get("SCR_DB_ENABLE")) != NULL) { scr_db_enable = atoi(value); } /* read in the debug level for database log messages */ if ((value = scr_param_get("SCR_DB_DEBUG")) != NULL) { scr_db_debug = atoi(value); } /* SCR log DB connection parameters */ if ((value = scr_param_get("SCR_DB_HOST")) != NULL) { scr_db_host = strdup(value); } if ((value = scr_param_get("SCR_DB_USER")) != NULL) { scr_db_user = strdup(value); } if ((value = scr_param_get("SCR_DB_PASS")) != NULL) { scr_db_pass = strdup(value); } if ((value = scr_param_get("SCR_DB_NAME")) != NULL) { scr_db_name = strdup(value); } scr_param_finalize(); /* connect to the database, if enabled */ if (scr_db_enable) { if (scr_mysql_connect() != SCR_SUCCESS) { scr_err("Failed to connect to SCR logging database, disabling database logging @ %s:%d", __FILE__, __LINE__ ); scr_db_enable = 0; rc = SCR_FAILURE; } } return rc; }
int main (int argc, char *argv[]) { int rc = 0; /* process command line arguments */ struct arglist args; if (!processArgs(argc, argv, &args)) { scr_err("scr_log_event: Failed to process args @ %s:%d", __FILE__, __LINE__ ); return 1; } char* value = NULL; /* read in job parameters (if user didn't specify them) */ if (args.username == NULL) { if ((value = getenv("USER")) != NULL) { args.username = strdup(value); } } if (args.jobname == NULL) { if ((value = getenv("SCR_JOB_NAME")) != NULL) { args.jobname = strdup(value); } } if (args.start == 0) { args.start = scr_log_seconds(); } /* read in log parameters */ scr_param_init(); if ((value = scr_param_get("SCR_LOG_ENABLE")) != NULL) { scr_log_enable = atoi(value); } scr_param_finalize(); if (scr_log_enable) { /* init logging */ if (scr_log_init() == SCR_SUCCESS) { /* register job */ if (args.username != NULL && args.jobname != NULL) { if (scr_log_job(args.username, args.jobname, args.start) != SCR_SUCCESS) { scr_err("scr_log_event: Failed to register job, disabling logging @ %s:%d", __FILE__, __LINE__ ); scr_log_enable = 0; rc = 1; } } else { scr_err("scr_log_event: Missing username, jobname, or start time, disabling logging @ %s:%d", __FILE__, __LINE__ ); scr_log_enable = 0; rc = 1; } } else { scr_err("scr_log_event: Failed to initialize SCR logging, disabling logging @ %s:%d", __FILE__, __LINE__ ); scr_log_enable = 0; rc = 1; } } if (scr_log_enable) { if (scr_log_event(args.event_type, args.event_note, args.event_dset, args.event_start, args.event_secs) != SCR_SUCCESS) { rc = 1; } } if (scr_log_enable) { scr_log_finalize(); } return rc; }