void GDMonoLog::initialize() { #ifdef DEBUG_ENABLED const char *log_level = "debug"; #else const char *log_level = "warning"; #endif String logs_dir = GodotSharpDirs::get_mono_logs_dir(); if (_try_create_logs_dir(logs_dir)) { _delete_old_log_files(logs_dir); log_file_path = logs_dir.plus_file(String::num_int64(OS::get_singleton()->get_unix_time()) + ".txt"); _open_log_file(log_file_path); } mono_trace_set_level_string(log_level); log_level_id = log_level_get_id(log_level); if (log_file) { print_verbose("Mono: Logfile is " + log_file_path); mono_trace_set_log_handler(mono_log_callback, this); } else { OS::get_singleton()->printerr("Mono: No log file, using default log handler\n"); } }
// // Console window // void ConsoleTabWindow::print(TCHAR *buf, BOOL force_display) { int cr; TCHAR *p; if (force_display) goto display; if (_filesave) { if (_logfile == INVALID_HANDLE_VALUE && !_open_log_file()) { _filesave = FALSE; _set_check(IDC_CONS_FILESAVE, _filesave); EnableWindow(_filename_edit, _filesave); goto display; } DWORD cnt; char c; for (int i = 0; *buf != TEXT('\0'); buf++) { c = *buf & 0x7f; WriteFile(_logfile, &c, 1, &cnt, 0); } FlushFileBuffers(_logfile); return; } display: // count number of '\n' for (cr = 0, p = buf; p = wcschr(p, TEXT('\n')); cr++, p++) continue; // total length of new buffer ('\n' -> "\r\n" + '\0') size_t sz = (wcslen(buf) + cr + 1) * sizeof(TCHAR); p = reinterpret_cast <TCHAR *>(malloc(sz)); if (p == NULL) return; // convert newlines TCHAR *d = p; while (*buf != TEXT('\0')) { TCHAR c = *buf++; if (c == TEXT('\n')) *d++ = TEXT('\r'); *d++ = c; } *d = TEXT('\0'); // append the text and scroll int end = Edit_GetTextLength(_edit); Edit_SetSel(_edit, end, end); Edit_ReplaceSel(_edit, p); Edit_ScrollCaret(_edit); UpdateWindow(_edit); free(p); }
static int _log_enabled(_log_iterator *it) { if (it->config == &config_file) { _open_log_file(it); // puts initial INFO message(s) at head of log file if (_log_file == NO_FILE) return 0; } else if (it->config == &config.log.console) { _open_log_stderr(); if (logfile_stderr == NULL || logfile_stderr == NO_FILE) return 0; } return 1; }
extern List filetxt_jobacct_process_get_jobs(slurmdb_job_cond_t *job_cond) { char line[BUFFER_SIZE]; char *f[MAX_RECORD_FIELDS+1]; /* End list with null entry and, possibly, more data than we expected */ char *fptr = NULL, *filein = NULL; int i; FILE *fd = NULL; int lc = 0; int rec_type = -1; int job_id = 0, step_id = 0, uid = 0, gid = 0; filetxt_job_rec_t *filetxt_job = NULL; slurmdb_selected_step_t *selected_step = NULL; char *object = NULL; ListIterator itr = NULL, itr2 = NULL; int show_full = 0; List ret_job_list = list_create(slurmdb_destroy_job_rec); List job_list = list_create(_destroy_filetxt_job_rec); filein = slurm_get_accounting_storage_loc(); if (job_cond) { if (!job_cond->duplicates) itr2 = list_iterator_create(ret_job_list); } fd = _open_log_file(filein); while (fgets(line, BUFFER_SIZE, fd)) { lc++; fptr = line; /* break the record into NULL- terminated strings */ for (i = 0; i < MAX_RECORD_FIELDS; i++) { f[i] = fptr; fptr = strstr(fptr, " "); if (fptr == NULL) { fptr = strstr(f[i], "\n"); if (fptr) *fptr = 0; break; } else { *fptr++ = 0; } } if (i < MAX_RECORD_FIELDS) i++; f[i] = 0; if (i < HEADER_LENGTH) { continue; } rec_type = atoi(f[F_RECTYPE]); job_id = atoi(f[F_JOB]); uid = atoi(f[F_UID]); gid = atoi(f[F_GID]); if (rec_type == JOB_STEP) step_id = atoi(f[F_JOBSTEP]); else step_id = NO_VAL; if (!job_cond) { show_full = 1; goto no_cond; } if (job_cond->userid_list && list_count(job_cond->userid_list)) { itr = list_iterator_create(job_cond->userid_list); while((object = list_next(itr))) { if (atoi(object) == uid) { list_iterator_destroy(itr); goto founduid; } } list_iterator_destroy(itr); continue; /* no match */ } founduid: if (job_cond->groupid_list && list_count(job_cond->groupid_list)) { itr = list_iterator_create(job_cond->groupid_list); while((object = list_next(itr))) { if (atoi(object) == gid) { list_iterator_destroy(itr); goto foundgid; } } list_iterator_destroy(itr); continue; /* no match */ } foundgid: if ((rec_type == JOB_START) && job_cond->jobname_list && list_count(job_cond->jobname_list)) { itr = list_iterator_create(job_cond->jobname_list); while((object = list_next(itr))) { if (!strcasecmp(f[F_JOBNAME], object)) { list_iterator_destroy(itr); goto foundjobname; } } list_iterator_destroy(itr); continue; /* no match */ } foundjobname: if (job_cond->step_list && list_count(job_cond->step_list)) { itr = list_iterator_create(job_cond->step_list); while((selected_step = list_next(itr))) { if (selected_step->jobid != job_id) continue; /* job matches; does the step? */ if (selected_step->stepid == NO_VAL) { show_full = 1; list_iterator_destroy(itr); goto foundjob; } else if (rec_type != JOB_STEP || selected_step->stepid == step_id) { list_iterator_destroy(itr); goto foundjob; } } list_iterator_destroy(itr); continue; /* no match */ } else { show_full = 1; } foundjob: 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)) { list_iterator_destroy(itr); goto foundp; } list_iterator_destroy(itr); continue; /* no match */ } foundp: no_cond: /* Build suitable tables with all the data */ switch(rec_type) { case JOB_START: if (i < F_JOB_ACCOUNT) { error("Bad data on a Job Start"); _show_rec(f); } else _process_start(job_list, f, lc, show_full, i); break; case JOB_STEP: if (i < F_MAX_VSIZE) { error("Bad data on a Step entry"); _show_rec(f); } else _process_step(job_list, f, lc, show_full, i); break; case JOB_SUSPEND: if (i < F_JOB_REQUID) { error("Bad data on a Suspend entry"); _show_rec(f); } else _process_suspend(job_list, f, lc, show_full, i); break; case JOB_TERMINATED: if (i < F_JOB_REQUID) { error("Bad data on a Job Term"); _show_rec(f); } else _process_terminated(job_list, f, lc, show_full, i); break; default: debug("Invalid record at line %d of input file", lc); _show_rec(f); break; } } if (ferror(fd)) { perror(filein); exit(1); } fclose(fd); itr = list_iterator_create(job_list); while((filetxt_job = list_next(itr))) { slurmdb_job_rec_t *slurmdb_job = _slurmdb_create_job_rec(filetxt_job, job_cond); if (slurmdb_job) { slurmdb_job_rec_t *curr_job = NULL; if (itr2) { list_iterator_reset(itr2); while((curr_job = list_next(itr2))) { if (curr_job->jobid == slurmdb_job->jobid) { list_delete_item(itr2); info("removing job %d", slurmdb_job->jobid); break; } } } list_append(ret_job_list, slurmdb_job); } } if (itr2) list_iterator_destroy(itr2); list_iterator_destroy(itr); list_destroy(job_list); xfree(filein); return ret_job_list; }
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; }
extern List filetxt_jobcomp_process_get_jobs(slurmdb_job_cond_t *job_cond) { char line[BUFFER_SIZE]; char *fptr = NULL, *filein = NULL; int jobid = 0; char *partition = NULL; FILE *fd = NULL; int lc = 0; jobcomp_job_rec_t *job = NULL; slurmdb_selected_step_t *selected_step = NULL; char *selected_part = NULL; ListIterator itr = NULL; List job_info_list = NULL; filetxt_jobcomp_info_t *jobcomp_info = NULL; List job_list = list_create(jobcomp_destroy_job); int fdump_flag = 0; /* we grab the fdump only for the filetxt plug through the FDUMP_FLAG on the job_cond->duplicates variable. We didn't add this extra field to the structure since it only applies to this plugin. */ if(job_cond) { fdump_flag = job_cond->duplicates & FDUMP_FLAG; job_cond->duplicates &= (~FDUMP_FLAG); } filein = slurm_get_jobcomp_loc(); fd = _open_log_file(filein); while (fgets(line, BUFFER_SIZE, fd)) { lc++; fptr = line; /* break the record into NULL- terminated strings */ if(job_info_list) list_destroy(job_info_list); jobid = 0; partition = NULL; job_info_list = list_create(_destroy_filetxt_jobcomp_info); while(fptr) { jobcomp_info = xmalloc(sizeof(filetxt_jobcomp_info_t)); list_append(job_info_list, jobcomp_info); jobcomp_info->name = fptr; fptr = strstr(fptr, "="); *fptr++ = 0; jobcomp_info->val = fptr; fptr = strstr(fptr, " "); if(!strcasecmp("JobId", jobcomp_info->name)) jobid = atoi(jobcomp_info->val); else if(!strcasecmp("Partition", jobcomp_info->name)) partition = jobcomp_info->val; if(!fptr) { fptr = strstr(jobcomp_info->val, "\n"); if (fptr) *fptr = 0; break; } else { *fptr++ = 0; if(*fptr == '\n') { *fptr = 0; break; } } } if (job_cond->step_list && list_count(job_cond->step_list)) { if(!jobid) continue; itr = list_iterator_create(job_cond->step_list); while((selected_step = list_next(itr))) { if (selected_step->jobid == jobid) continue; /* job matches */ list_iterator_destroy(itr); goto foundjob; } list_iterator_destroy(itr); continue; /* no match */ } foundjob: if (job_cond->partition_list && list_count(job_cond->partition_list)) { if(!partition) continue; itr = list_iterator_create(job_cond->partition_list); while((selected_part = list_next(itr))) if (!strcasecmp(selected_part, partition)) { list_iterator_destroy(itr); goto foundp; } list_iterator_destroy(itr); continue; /* no match */ } foundp: if (fdump_flag) { _do_fdump(job_info_list, lc); continue; } job = _parse_line(job_info_list); if(job) list_append(job_list, job); } if(job_info_list) list_destroy(job_info_list); if (ferror(fd)) { perror(filein); xfree(filein); exit(1); } fclose(fd); xfree(filein); return job_list; }
extern List filetxt_jobcomp_process_get_jobs(slurmdb_job_cond_t *job_cond) { char line[BUFFER_SIZE]; char *fptr = NULL, *filein = NULL; int jobid = 0; char *partition = NULL; FILE *fd = NULL; int lc = 0; jobcomp_job_rec_t *job = NULL; slurmdb_selected_step_t *selected_step = NULL; char *selected_part = NULL; ListIterator itr = NULL; List job_info_list = NULL; filetxt_jobcomp_info_t *jobcomp_info = NULL; List job_list = list_create(jobcomp_destroy_job); filein = slurm_get_jobcomp_loc(); fd = _open_log_file(filein); while (fgets(line, BUFFER_SIZE, fd)) { lc++; fptr = line; /* break the record into NULL- terminated strings */ if (job_info_list) list_destroy(job_info_list); jobid = 0; partition = NULL; job_info_list = list_create(_destroy_filetxt_jobcomp_info); while(fptr) { jobcomp_info = xmalloc(sizeof(filetxt_jobcomp_info_t)); list_append(job_info_list, jobcomp_info); jobcomp_info->name = fptr; fptr = strstr(fptr, "="); *fptr++ = 0; jobcomp_info->val = fptr; fptr = strstr(fptr, " "); if (!strcasecmp("JobId", jobcomp_info->name)) jobid = atoi(jobcomp_info->val); else if (!strcasecmp("Partition", jobcomp_info->name)) partition = jobcomp_info->val; if (!fptr) { fptr = strstr(jobcomp_info->val, "\n"); if (fptr) *fptr = 0; break; } else { *fptr++ = 0; if (*fptr == '\n') { *fptr = 0; break; } } } if (job_cond->step_list && list_count(job_cond->step_list)) { if (!jobid) continue; itr = list_iterator_create(job_cond->step_list); while((selected_step = list_next(itr))) { if (selected_step->jobid == jobid) continue; /* job matches */ list_iterator_destroy(itr); goto foundjob; } list_iterator_destroy(itr); continue; /* no match */ } foundjob: if (job_cond->partition_list && list_count(job_cond->partition_list)) { if (!partition) continue; itr = list_iterator_create(job_cond->partition_list); while((selected_part = list_next(itr))) if (!strcasecmp(selected_part, partition)) { list_iterator_destroy(itr); goto foundp; } list_iterator_destroy(itr); continue; /* no match */ } foundp: job = _parse_line(job_info_list); if (job) list_append(job_list, job); } if (job_info_list) list_destroy(job_info_list); if (ferror(fd)) { perror(filein); xfree(filein); exit(1); } fclose(fd); xfree(filein); return job_list; }