static char *_make_archive_name(time_t period_start, time_t period_end, char *cluster_name, char *arch_dir, char *arch_type, uint32_t archive_period) { struct tm time_tm; char start_char[32]; char end_char[32]; localtime_r((time_t *)&period_start, &time_tm); time_tm.tm_sec = 0; time_tm.tm_min = 0; /* set up the start time based off the period we are purging */ if(SLURMDB_PURGE_IN_HOURS(archive_period)) { } else if(SLURMDB_PURGE_IN_DAYS(archive_period)) { time_tm.tm_hour = 0; } else { time_tm.tm_hour = 0; time_tm.tm_mday = 1; } snprintf(start_char, sizeof(start_char), "%4.4u-%2.2u-%2.2u" "T%2.2u:%2.2u:%2.2u", (time_tm.tm_year + 1900), (time_tm.tm_mon+1), time_tm.tm_mday, time_tm.tm_hour, time_tm.tm_min, time_tm.tm_sec); localtime_r((time_t *)&period_end, &time_tm); snprintf(end_char, sizeof(end_char), "%4.4u-%2.2u-%2.2u" "T%2.2u:%2.2u:%2.2u", (time_tm.tm_year + 1900), (time_tm.tm_mon+1), time_tm.tm_mday, time_tm.tm_hour, time_tm.tm_min, time_tm.tm_sec); /* write the buffer to file */ return xstrdup_printf("%s/%s_%s_archive_%s_%s", arch_dir, cluster_name, arch_type, start_char, end_char); }
extern time_t archive_setup_end_time(time_t last_submit, uint32_t purge) { struct tm time_tm; int16_t units; if(purge == NO_VAL) { error("Invalid purge set"); return 0; } units = SLURMDB_PURGE_GET_UNITS(purge); if(units < 0) { error("invalid units from purge '%d'", units); return 0; } /* use localtime to avoid any daylight savings issues */ if(!localtime_r(&last_submit, &time_tm)) { error("Couldn't get localtime from first " "suspend start %ld", (long)last_submit); return 0; } time_tm.tm_sec = 0; time_tm.tm_min = 0; if(SLURMDB_PURGE_IN_HOURS(purge)) time_tm.tm_hour -= units; else if(SLURMDB_PURGE_IN_DAYS(purge)) { time_tm.tm_hour = 0; time_tm.tm_mday -= units; } else if(SLURMDB_PURGE_IN_MONTHS(purge)) { time_tm.tm_hour = 0; time_tm.tm_mday = 1; time_tm.tm_mon -= units; } else { errno = EINVAL; error("No known unit given for purge, " "we are guessing mistake and returning error"); return 0; } time_tm.tm_isdst = -1; return (mktime(&time_tm) - 1); }
static char *_make_archive_name(time_t period_start, time_t period_end, char *cluster_name, char *arch_dir, char *arch_type, uint32_t archive_period) { struct tm time_tm; char start_char[32]; char end_char[32]; char name[PATH_MAX]; char fullname[PATH_MAX]; struct stat buf; uint32_t num = 2; uint32_t size_left = PATH_MAX - 1; uint32_t size; slurm_localtime_r((time_t *)&period_start, &time_tm); time_tm.tm_sec = 0; time_tm.tm_min = 0; /* set up the start time based off the period we are purging */ if (SLURMDB_PURGE_IN_HOURS(archive_period)) { } else if (SLURMDB_PURGE_IN_DAYS(archive_period)) { time_tm.tm_hour = 0; } else { time_tm.tm_hour = 0; time_tm.tm_mday = 1; } snprintf(start_char, sizeof(start_char), "%4.4u-%2.2u-%2.2u" "T%2.2u:%2.2u:%2.2u", (time_tm.tm_year + 1900), (time_tm.tm_mon+1), time_tm.tm_mday, time_tm.tm_hour, time_tm.tm_min, time_tm.tm_sec); slurm_localtime_r((time_t *)&period_end, &time_tm); snprintf(end_char, sizeof(end_char), "%4.4u-%2.2u-%2.2u" "T%2.2u:%2.2u:%2.2u", (time_tm.tm_year + 1900), (time_tm.tm_mon+1), time_tm.tm_mday, time_tm.tm_hour, time_tm.tm_min, time_tm.tm_sec); size = snprintf(name, size_left, "%s/%s_%s_archive_%s_%s", arch_dir, cluster_name, arch_type, start_char, end_char); if (size >= size_left) { fatal("%s: file name would be larger than the max allowed file length of %u bytes, cannot archive file. This should never happen.", __func__, PATH_MAX); } size_left -= size; /* If the file already exists, generate a new file name. */ strncpy(fullname, name, PATH_MAX); while (!stat(fullname, &buf)) { size = snprintf(fullname, size_left, "%s.%u", name, num++); if (size >= size_left) { error("%s: file name would be larger than the max allowed file lenght of %u bytes, cannot archive file. This should never happen.", __func__, PATH_MAX); return NULL; } } return xstrdup(fullname); }