* University of Maryland at College Park
*/
/*
- * $Id: infofile.c,v 1.44.4.4 1999/11/10 14:36:10 oliva Exp $
+ * $Id: infofile.c,v 1.44.4.4.8.5 2005/09/30 19:13:36 martinea Exp $
*
* manage current info file
*/
perf_t *pp;
char *s;
int ch;
+ int nb_history;
+ int i;
/* get version: command: lines */
else if (strncmp(line,"last_level:",11) == 0) {
break; /* normal */
}
+ else if (strncmp(line,"history:",8) == 0) {
+ break; /* normal */
+ }
memset(&onestat, 0, sizeof(onestat));
s = line;
if(rc > 2) return -2;
rc = 0;
- if((line = agets(infof)) == NULL) return -1;
+ nb_history = 0;
+ for(i=0;i<=NB_HISTORY;i++) {
+ info->history[i].level = -2;
+ }
+ for(rc = -2; (line = agets(infof)) != NULL; free(line)) {
+ history_t onehistory; /* one history record */
+ long date;
+
+ if(line[0] == '/' && line[1] == '/') {
+ info->history[nb_history].level = -2;
+ rc = 0;
+ amfree(line);
+ return 0; /* normal end of record */
+ }
+
+ memset(&onehistory, 0, sizeof(onehistory));
+
+ s = line;
+ ch = *s++;
+
+#define sc "history:"
+ if(strncmp(line, sc, sizeof(sc)-1) != 0) {
+ break;
+ }
+ s += sizeof(sc)-1;
+ ch = s[-1];
+#undef sc
+
+ skip_whitespace(s, ch);
+ if(ch == '\0' || sscanf((s - 1), "%d", &onehistory.level) != 1) {
+ break;
+ }
+ skip_integer(s, ch);
+
+ skip_whitespace(s, ch);
+ if(ch == '\0' || sscanf((s - 1), "%ld", &onehistory.size) != 1) {
+ break;
+ }
+ skip_integer(s, ch);
+
+ skip_whitespace(s, ch);
+ if(ch == '\0' || sscanf((s - 1), "%ld", &onehistory.csize) != 1) {
+ break;
+ }
+ skip_integer(s, ch);
+
+ skip_whitespace(s, ch);
+ if(ch == '\0' || sscanf((s - 1), "%ld", &date) != 1) {
+ break;
+ }
+ skip_integer(s, ch);
+
+ onehistory.date = date; /* time_t not guarranteed to be long */
+
+ onehistory.secs = -1;
+ skip_whitespace(s, ch);
+ if(ch != '\0') {
+ if(sscanf((s - 1), "%ld", &onehistory.secs) != 1) {
+ break;
+ }
+ skip_integer(s, ch);
+ }
+
+ info->history[nb_history++] = onehistory;
+ }
+
+ if((line = agets(infof)) == NULL) return -1; /* // line */
amfree(line);
return rc;
}
fprintf(infof, "last_level: %d %d\n", info->last_level, info->consecutive_runs);
+
+ for(i=0;info->history[i].level > -1;i++) {
+ fprintf(infof, "history: %d %ld %ld %ld %ld\n",info->history[i].level,
+ info->history[i].size, info->history[i].csize,
+ info->history[i].date, info->history[i].secs);
+ }
fprintf(infof, "//\n");
return 0;
info->last_level = -1;
info->consecutive_runs = -1;
+ for(i=0;i<=NB_HISTORY;i++) {
+ info->history[i].level = -2;
+ info->history[i].size = 0;
+ info->history[i].csize = 0;
+ info->history[i].date = 0;
+ }
return;
}
char *argv[];
{
int i;
- int fd;
unsigned long malloc_hist_1, malloc_size_1;
unsigned long malloc_hist_2, malloc_size_2;
- for(fd = 3; fd < FD_SETSIZE; fd++) {
- /*
- * Make sure nobody spoofs us with a lot of extra open files
- * that would cause an open we do to get a very high file
- * descriptor, which in turn might be used as an index into
- * an array (e.g. an fd_set).
- */
- close(fd);
- }
+ safe_fd(-1, 0);
set_pname("infofile");