static void _reconfigure(GtkToggleAction *action) { char *temp = NULL; if (!slurm_reconfigure()) temp = g_strdup_printf( "Reconfigure sent to slurm successfully"); else temp = g_strdup_printf("Problem with reconfigure request"); display_edit_note(temp); g_free(temp); }
/* main is used here for module testing purposes only */ int main (int argc, char *argv[]) { int i, count, error_code; if (argc < 2) count = 1; else count = atoi (argv[1]); for (i = 0; i < count; i++) { error_code = slurm_reconfigure (); if (error_code != 0) { slurm_perror ("slurm_reconfigure"); return (1); } } return (0); }
extern int filetxt_jobacct_process_archive(slurmdb_archive_cond_t *arch_cond) { char line[BUFFER_SIZE], *f[EXPIRE_READ_LENGTH], *fptr = NULL, *logfile_name = NULL, *old_logfile_name = NULL, *filein = NULL, *object = NULL; int file_err=0, new_file, i = 0, rc = SLURM_ERROR; expired_rec_t *exp_rec = NULL; expired_rec_t *exp_rec2 = NULL; List keep_list = list_create(_destroy_exp); List exp_list = list_create(_destroy_exp); List other_list = list_create(_destroy_exp); struct stat statbuf; mode_t prot = 0600; uid_t uid; gid_t gid; FILE *expired_logfile = NULL, *new_logfile = NULL; FILE *fd = NULL; int lc=0; int rec_type = -1; ListIterator itr = NULL; ListIterator itr2 = NULL; slurmdb_job_cond_t *job_cond = NULL; /* Figure out our expiration date */ time_t expiry; if (!arch_cond || !arch_cond->job_cond) { error("no job_cond was given for archive"); return SLURM_ERROR; } job_cond = arch_cond->job_cond; if (!arch_cond->archive_script) filein = slurm_get_accounting_storage_loc(); else filein = arch_cond->archive_script; expiry = time(NULL) - job_cond->usage_end; debug("Purging jobs completed prior to %d", (int)expiry); /* Open the current or specified logfile, or quit */ fd = _open_log_file(filein); if (stat(filein, &statbuf)) { perror("stat'ing logfile"); goto finished; } if ((statbuf.st_mode & S_IFLNK) == S_IFLNK) { error("%s is a symbolic link; --expire requires " "a hard-linked file name", filein); goto finished; } if (!(statbuf.st_mode & S_IFREG)) { error("%s is not a regular file; --expire " "only works on accounting log files", filein); goto finished; } prot = statbuf.st_mode & 0777; gid = statbuf.st_gid; uid = statbuf.st_uid; old_logfile_name = _prefix_filename(filein, ".old."); if (stat(old_logfile_name, &statbuf)) { if (errno != ENOENT) { fprintf(stderr,"Error checking for %s: ", old_logfile_name); perror(""); goto finished; } } else { error("Warning! %s exists -- please remove " "or rename it before proceeding", old_logfile_name); goto finished; } /* create our initial buffer */ while (fgets(line, BUFFER_SIZE, fd)) { lc++; fptr = line; /* break the record into NULL- terminated strings */ exp_rec = xmalloc(sizeof(expired_rec_t)); exp_rec->line = xstrdup(line); for (i = 0; i < EXPIRE_READ_LENGTH; i++) f[i] = fptr; /* Initialization for bad data read */ for (i = 0; i < EXPIRE_READ_LENGTH; i++) { f[i] = fptr; fptr = strstr(fptr, " "); if (fptr == NULL) break; else *fptr++ = 0; } exp_rec->job = atoi(f[F_JOB]); exp_rec->job_submit = atoi(f[F_JOB_SUBMIT]); rec_type = atoi(f[F_RECTYPE]); /* Odd, but complain some other time */ if (rec_type == JOB_TERMINATED) { if (expiry < atoi(f[F_TIMESTAMP])) { list_append(keep_list, exp_rec); continue; } if ((rec_type == JOB_START) && job_cond->partition_list && list_count(job_cond->partition_list)) { itr = list_iterator_create( job_cond->partition_list); while((object = list_next(itr))) if (!strcasecmp(f[F_PARTITION], object)) break; list_iterator_destroy(itr); if (!object) continue; /* no match */ } list_append(exp_list, exp_rec); debug2("Selected: %8d %d", exp_rec->job, (int)exp_rec->job_submit); } else { list_append(other_list, exp_rec); } } if (!list_count(exp_list)) { debug3("No job records were purged."); goto finished; } logfile_name = xmalloc(strlen(filein)+sizeof(".expired")); sprintf(logfile_name, "%s.expired", filein); new_file = stat(logfile_name, &statbuf); if ((expired_logfile = fopen(logfile_name, "a"))==NULL) { error("Error while opening %s", logfile_name); perror(""); xfree(logfile_name); goto finished; } if (new_file) { /* By default, the expired file looks like the log */ chmod(logfile_name, prot); if (chown(logfile_name, uid, gid) == -1) error("Couldn't change ownership of %s to %u:%u", logfile_name, uid, gid); } xfree(logfile_name); logfile_name = _prefix_filename(filein, ".new."); if ((new_logfile = fopen(logfile_name, "w"))==NULL) { error("Error while opening %s", logfile_name); perror(""); fclose(expired_logfile); goto finished; } chmod(logfile_name, prot); /* preserve file protection */ if (chown(logfile_name, uid, gid) == -1)/* and ownership */ error("2 Couldn't change ownership of %s to %u:%u", logfile_name, uid, gid); /* Use line buffering to allow us to safely write * to the log file at the same time as slurmctld. */ if (setvbuf(new_logfile, NULL, _IOLBF, 0)) { perror("setvbuf()"); fclose(expired_logfile); goto finished2; } list_sort(exp_list, (ListCmpF) _cmp_jrec); list_sort(keep_list, (ListCmpF) _cmp_jrec); /* if (params->opt_verbose > 2) { */ /* error("--- contents of exp_list ---"); */ /* itr = list_iterator_create(exp_list); */ /* while((exp_rec = list_next(itr))) */ /* error("%d", exp_rec->job); */ /* error("---- end of exp_list ---"); */ /* list_iterator_destroy(itr); */ /* } */ /* write the expired file */ itr = list_iterator_create(exp_list); while((exp_rec = list_next(itr))) { itr2 = list_iterator_create(other_list); while((exp_rec2 = list_next(itr2))) { if ((exp_rec2->job != exp_rec->job) || (exp_rec2->job_submit != exp_rec->job_submit)) continue; if (fputs(exp_rec2->line, expired_logfile)<0) { perror("writing expired_logfile"); list_iterator_destroy(itr2); list_iterator_destroy(itr); fclose(expired_logfile); goto finished2; } list_remove(itr2); _destroy_exp(exp_rec2); } list_iterator_destroy(itr2); if (fputs(exp_rec->line, expired_logfile)<0) { perror("writing expired_logfile"); list_iterator_destroy(itr); fclose(expired_logfile); goto finished2; } } list_iterator_destroy(itr); fclose(expired_logfile); /* write the new log */ itr = list_iterator_create(keep_list); while((exp_rec = list_next(itr))) { itr2 = list_iterator_create(other_list); while((exp_rec2 = list_next(itr2))) { if (exp_rec2->job != exp_rec->job) continue; if (fputs(exp_rec2->line, new_logfile)<0) { perror("writing keep_logfile"); list_iterator_destroy(itr2); list_iterator_destroy(itr); goto finished2; } list_remove(itr2); _destroy_exp(exp_rec2); } list_iterator_destroy(itr2); if (fputs(exp_rec->line, new_logfile)<0) { perror("writing keep_logfile"); list_iterator_destroy(itr); goto finished2; } } list_iterator_destroy(itr); /* write records in other_list to new log */ itr = list_iterator_create(other_list); while((exp_rec = list_next(itr))) { if (fputs(exp_rec->line, new_logfile)<0) { perror("writing keep_logfile"); list_iterator_destroy(itr); goto finished2; } } list_iterator_destroy(itr); if (rename(filein, old_logfile_name)) { perror("renaming logfile to .old."); goto finished2; } if (rename(logfile_name, filein)) { perror("renaming new logfile"); /* undo it? */ if (!rename(old_logfile_name, filein)) error("Please correct the problem " "and try again"); else error("SEVERE ERROR: Current accounting " "log may have been renamed %s;\n" "please rename it to \"%s\" if necessary, " "and try again", old_logfile_name, filein); goto finished2; } fflush(new_logfile); /* Flush the buffers before forking */ fflush(fd); file_err = slurm_reconfigure(); if (file_err) { file_err = 1; error("Error: Attempt to reconfigure SLURM failed."); if (rename(old_logfile_name, filein)) { perror("renaming logfile from .old."); goto finished2; } } if (fseek(fd, 0, SEEK_CUR)) { /* clear EOF */ perror("looking for late-arriving records"); goto finished2; } /* reopen new logfile in append mode, since slurmctld may write it */ if (freopen(filein, "a", new_logfile) == NULL) { perror("reopening new logfile"); goto finished2; } while (fgets(line, BUFFER_SIZE, fd)) { if (fputs(line, new_logfile)<0) { perror("writing final records"); goto finished2; } } rc = SLURM_SUCCESS; printf("%d jobs expired.\n", list_count(exp_list)); finished2: fclose(new_logfile); if (!file_err) { if (unlink(old_logfile_name) == -1) error("Unable to unlink old logfile %s: %m", old_logfile_name); } finished: xfree(filein); fclose(fd); list_destroy(exp_list); list_destroy(keep_list); list_destroy(other_list); xfree(old_logfile_name); xfree(logfile_name); return rc; }