/*
** Called after each artifact is processed
*/
static void rebuild_step_done(int rid){
  /* assert( bag_find(&bagDone, rid)==0 ); */
  bag_insert(&bagDone, rid);
  if( ttyOutput ){
    processCnt++;
    if (!g.fQuiet && totalSize>0) {
      percent_complete((processCnt*1000)/totalSize);
    }
  }
}
Exemple #2
0
void show_result(struct tup_entry *tent, int is_error, struct timespan *ts, const char *extra_text, int always_display)
{
	FILE *f;
	float tdiff = 0.0;

	job_time += tent->mtime;

	if(ts) {
		tdiff = timespan_seconds(ts);
	}

	sum++;
	if(sum > total) {
		fprintf(stderr, "tup internal error: progress bar is sized incorrectly.\n");
	}

	if(quiet && !always_display)
		return;

	if(is_error) {
		got_error = 1;
		f = stderr;
	} else {
		f = stdout;
	}
	clear_active(f);
	color_set(f);
	if(is_error) {
		fprintf(stderr, "* %s", color_error_mode());
	} else {
		printf(" ");
	}
	/* If we aren't going to show a progress bar, then %-complete here is
	 * helpful.
	 */
	if(total && !display_progress) fprintf(f, "%3i%% ", percent_complete());
	if(display_job_numbers) fprintf(f, "%i) ", sum);
	if(display_job_time && ts) {
		fprintf(f, "[%.3fs] ", tdiff);
	}

	if(extra_text)
		fprintf(f, "%s: ", extra_text);

	print_tup_entry(f, tent);
	fprintf(f, "\n");
	color_error_mode_clear();
}
Exemple #3
0
void show_progress(int active, enum TUP_NODE_TYPE type)
{
	int console_width = tup_option_get_int("display.width");
	if(total && display_progress && console_width >= 10) {
		/* -3 for the [] and leading space, and -6 for the " 100% " at
		 * the end.
		 */
		int max = console_width - 9;
		int fill;
		char buf[console_width + color_len + 1];
		int num_infos = 0;
		int i = 0;
		int x;
		int tmpmax;
		int offset;

		if(max > total)
			max = total;
		if(got_error)
			type = TUP_NODE_ROOT;

		clear_active(stdout);

		fill = max * sum / total;

		if(color_len) {
			memset(buf, ' ', sizeof(buf));
		} else {
			memset(buf, '.', fill);
			memset(buf+fill, ' ', sizeof(buf) - fill);
		}

		for(x=0; x<ARRAY_SIZE(infos); x++) {
			infos[x].len = 0;
		}

		if(total_time != -1) {
			infos[i].len = get_time_remaining(infos[i].text, sizeof(infos[i].text), job_time, total_time, 0);
		} else {
			infos[i].len = get_time_remaining(infos[i].text, sizeof(infos[i].text), sum, total, 1);
		}
		i++;

		infos[i].len = snprintf(infos[i].text, sizeof(infos[i].text), "Remaining=%i", total-sum);
		i++;

		if(active != -1) {
			infos[i].len = snprintf(infos[i].text, sizeof(infos[i].text), "Active=%i", active);
		} else {
			/* Override maxlen to disable "Active..." */
			infos[i].maxlen = 0;
		}
		i++;

		tmpmax = max;
		for(x=0; x<ARRAY_SIZE(infos); x++) {
			int spacing = 0;
			if(x)
				spacing = 1;
			if(tmpmax >= infos[x].maxlen + spacing) {
				tmpmax -= infos[x].maxlen + spacing;
				num_infos++;
			} else {
				break;
			}
		}
		offset = tmpmax / 2;
		for(x=0; x<num_infos; x++) {
			if(x)
				offset++;
			memcpy(buf + offset, infos[x].text, infos[x].len);
			offset += infos[x].maxlen;
		}

		color_set(stdout);
		printf(" [%s%s%.*s%s%.*s] %3i%%", color_type(type), color_append_reverse(), fill, buf, color_end(), max-fill, buf+fill, percent_complete());
		is_active = 1;
		fflush(stdout);
	}
}
/*
** Core function to rebuild the information in the derived tables of a
** fossil repository from the blobs. This function is shared between
** 'rebuild_database' ('rebuild') and 'reconstruct_cmd'
** ('reconstruct'), both of which have to regenerate this information
** from scratch.
**
** If the randomize parameter is true, then the BLOBs are deliberately
** extracted in a random order.  This feature is used to test the
** ability of fossil to accept records in any order and still
** construct a sane repository.
*/
int rebuild_db(int randomize, int doOut, int doClustering){
  Stmt s;
  int errCnt = 0;
  char *zTable;
  int incrSize;

  bag_init(&bagDone);
  ttyOutput = doOut;
  processCnt = 0;
  if (ttyOutput && !g.fQuiet) {
    percent_complete(0);
  }
  rebuild_update_schema();
  for(;;){
    zTable = db_text(0,
       "SELECT name FROM sqlite_master /*scan*/"
       " WHERE type='table'"
       " AND name NOT IN ('blob','delta','rcvfrom','user',"
                         "'config','shun','private','reportfmt',"
                         "'concealed','accesslog','modreq')"
       " AND name NOT GLOB 'sqlite_*'"
       " AND name NOT GLOB 'fx_*'"
    );
    if( zTable==0 ) break;
    db_multi_exec("DROP TABLE %Q", zTable);
    free(zTable);
  }
  db_multi_exec(zRepositorySchema2);
  ticket_create_table(0);
  shun_artifacts();

  db_multi_exec(
     "INSERT INTO unclustered"
     " SELECT rid FROM blob EXCEPT SELECT rid FROM private"
  );
  db_multi_exec(
     "DELETE FROM unclustered"
     " WHERE rid IN (SELECT rid FROM shun JOIN blob USING(uuid))"
  );
  db_multi_exec(
    "DELETE FROM config WHERE name IN ('remote-code', 'remote-maxid')"
  );

  /* The following should be count(*) instead of max(rid). max(rid) is
  ** an adequate approximation, however, and is much faster for large
  ** repositories. */
  totalSize = db_int(0, "SELECT max(rid) FROM blob");
  incrSize = totalSize/100;
  totalSize += incrSize*2;
  db_prepare(&s,
     "SELECT rid, size FROM blob /*scan*/"
     " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
     "   AND NOT EXISTS(SELECT 1 FROM delta WHERE rid=blob.rid)"
  );
  manifest_crosslink_begin();
  while( db_step(&s)==SQLITE_ROW ){
    int rid = db_column_int(&s, 0);
    int size = db_column_int(&s, 1);
    if( size>=0 ){
      Blob content;
      content_get(rid, &content);
      rebuild_step(rid, size, &content);
    }
  }
  db_finalize(&s);
  db_prepare(&s,
     "SELECT rid, size FROM blob"
     " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid)"
  );
  while( db_step(&s)==SQLITE_ROW ){
    int rid = db_column_int(&s, 0);
    int size = db_column_int(&s, 1);
    if( size>=0 ){
      if( !bag_find(&bagDone, rid) ){
        Blob content;
        content_get(rid, &content);
        rebuild_step(rid, size, &content);
      }
    }else{
      db_multi_exec("INSERT OR IGNORE INTO phantom VALUES(%d)", rid);
      rebuild_step_done(rid);
    }
  }
  db_finalize(&s);
  manifest_crosslink_end(MC_NONE);
  rebuild_tag_trunk();
  if( ttyOutput && !g.fQuiet && totalSize>0 ){
    processCnt += incrSize;
    percent_complete((processCnt*1000)/totalSize);
  }
  if( doClustering ) create_cluster();
  if( ttyOutput && !g.fQuiet && totalSize>0 ){
    processCnt += incrSize;
    percent_complete((processCnt*1000)/totalSize);
  }
  if(!g.fQuiet && ttyOutput ){
    percent_complete(1000);
    fossil_print("\n");
  }
  return errCnt;
}
Exemple #5
0
int main(int argc, char **argv) {
    pr_scoreboard_entry_t *score = NULL;
    pid_t mpid = 0;
    time_t uptime = 0;
    unsigned int count = 0, total = 0;
    int c = 0, res = 0;
    char *server_name = NULL;
    struct scoreboard_class classes[MAX_CLASSES];
    char *cp, *progname = *argv;
    const char *cmdopts = "S:c:f:ho:v";
    unsigned char verbose = FALSE;
    unsigned long outform = 0;

    memset(classes, 0, MAX_CLASSES * sizeof(struct scoreboard_class));

    cp = strrchr(progname, '/');
    if (cp != NULL)
        progname = cp+1;

    opterr = 0;
    while ((c =
#ifdef HAVE_GETOPT_LONG
                getopt_long(argc, argv, cmdopts, opts, NULL)
#else /* HAVE_GETOPT_LONG */
                getopt(argc, argv, cmdopts)
#endif /* HAVE_GETOPT_LONG */
           ) != -1) {
        switch (c) {
        case 'h':
            show_usage(progname, 0);

        case 'v':
            verbose = TRUE;
            break;

        case 'f':
            util_set_scoreboard(optarg);
            break;

        case 'c':
            config_filename = strdup(optarg);
            break;

        case 'o':
            /* Check the given outform parameter. */
            if (strcmp(optarg, "compat") == 0) {
                outform |= OF_COMPAT;
                break;

            } else if (strcmp(optarg, "oneline") == 0) {
                outform |= OF_ONELINE;
                break;
            }

            fprintf(stderr, "unknown outform value: '%s'\n", optarg);
            return 1;

        case 'S':
            server_name = strdup(optarg);
            break;

        case '?':
            fprintf(stderr, "unknown option: %c\n", (char) optopt);
            show_usage(progname, 1);
        }
    }

    /* First attempt to check the supplied/default scoreboard path.  If this is
     * incorrect, try the config file kludge.
     */
    if (check_scoreboard_file() < 0) {
        char *path;

        path = util_scan_config(config_filename, "ScoreboardFile");
        if (path) {
            util_set_scoreboard(path);
            free(path);
        }

        if (check_scoreboard_file() < 0) {
            fprintf(stderr, "%s: %s\n", util_get_scoreboard(), strerror(errno));
            fprintf(stderr, "(Perhaps you need to specify the ScoreboardFile with -f, or change\n");
            fprintf(stderr," the compile-time default directory?)\n");
            exit(1);
        }
    }

    count = 0;
    if ((res = util_open_scoreboard(O_RDONLY)) < 0) {
        switch (res) {
        case -1:
            fprintf(stderr, "unable to open scoreboard: %s\n", strerror(errno));
            return 1;

        case UTIL_SCORE_ERR_BAD_MAGIC:
            fprintf(stderr, "scoreboard is corrupted or old\n");
            return 1;

        case UTIL_SCORE_ERR_OLDER_VERSION:
            fprintf(stderr, "scoreboard version is too old\n");
            return 1;

        case UTIL_SCORE_ERR_NEWER_VERSION:
            fprintf(stderr, "scoreboard version is too new\n");
            return 1;
        }
    }

    mpid = util_scoreboard_get_daemon_pid();
    uptime = util_scoreboard_get_daemon_uptime();

    if (!mpid) {
        printf("inetd FTP daemon:\n");

    } else {
        printf("standalone FTP daemon [%u], up for %s\n", (unsigned int) mpid,
               show_uptime(uptime));
    }

    if (server_name)
        printf("ProFTPD Server '%s'\n", server_name);

    while ((score = util_scoreboard_entry_read()) != NULL) {
        int downloading = FALSE, uploading = FALSE;
        register unsigned int i = 0;

        /* If a ServerName was given, skip unless the scoreboard entry matches. */
        if (server_name &&
                strcmp(server_name, score->sce_server_label) != 0)
            continue;

        if (!count++) {
            if (total)
                printf("   -  %d user%s\n\n", total, total > 1 ? "s" : "");

            total = 0;
        }

        /* Tally up per-Class counters. */
        for (i = 0; i != MAX_CLASSES; i++) {
            if (classes[i].score_class == 0) {
                classes[i].score_class = strdup(score->sce_class);
                classes[i].score_count++;
                break;
            }

            if (strcasecmp(classes[i].score_class, score->sce_class) == 0) {
                classes[i].score_count++;
                break;
            }
        }

        total++;

        if (strcmp(score->sce_cmd, "RETR") == 0 ||
                strcmp(score->sce_cmd, "READ") == 0 ||
                strcmp(score->sce_cmd, "scp download") == 0) {
            downloading = TRUE;

        } else {
            if (strcmp(score->sce_cmd, "STOR") == 0 ||
                    strcmp(score->sce_cmd, "STOU") == 0 ||
                    strcmp(score->sce_cmd, "APPE") == 0 ||
                    strcmp(score->sce_cmd, "WRITE") == 0 ||
                    strcmp(score->sce_cmd, "scp upload") == 0) {
                uploading = TRUE;
            }
        }

        if (outform & OF_COMPAT) {
            if ((downloading || uploading) &&
                    score->sce_xfer_size > 0) {
                if (downloading) {
                    printf("%5d %-6s (%s%%) %s %s\n", (int) score->sce_pid,
                           show_time(&score->sce_begin_idle),
                           percent_complete(score->sce_xfer_size, score->sce_xfer_done),
                           score->sce_cmd, score->sce_cmd_arg);

                } else {
                    printf("%5d %-6s (n/a) %s %s\n", (int) score->sce_pid,
                           show_time(&score->sce_begin_idle), score->sce_cmd,
                           score->sce_cmd_arg);
                }

            } else {
                printf("%5d %-6s %s %s\n", (int) score->sce_pid,
                       show_time(&score->sce_begin_idle), score->sce_cmd,
                       score->sce_cmd_arg);
            }

            if (verbose) {
                if (score->sce_client_addr[0]) {
                    printf("             (host: %s [%s])\n", score->sce_client_name,
                           score->sce_client_addr);
                }

                if (score->sce_protocol[0]) {
                    printf("              (protocol: %s)\n", score->sce_protocol);
                }

                if (score->sce_cwd[0]) {
                    printf("              (cwd: %s)\n", score->sce_cwd);
                }

                if (score->sce_class[0]) {
                    printf("              (class: %s)\n", score->sce_class);
                }
            }

            continue;
        }

        /* Has the client authenticated yet, or not? */
        if (strcmp(score->sce_user, "(none)")) {

            /* Is the client idle? */
            if (strcmp(score->sce_cmd, "idle") == 0) {

                /* These printf() calls needs to be split up, as show_time() returns
                 * a pointer to a static buffer, and pushing two invocations onto
                 * the stack means that the times thus formatted will be incorrect.
                 */
                printf("%5d %-8s [%6s] ", (int) score->sce_pid,
                       score->sce_user, show_time(&score->sce_begin_session));
                printf("%6s %s", show_time(&score->sce_begin_idle), score->sce_cmd);

                if (verbose && !(outform & OF_ONELINE))
                    printf("\n");

            } else {
                if (downloading) {
                    printf("%5d %-8s [%6s] (%3s%%) %s %s", (int) score->sce_pid,
                           score->sce_user, show_time(&score->sce_begin_session),
                           percent_complete(score->sce_xfer_size, score->sce_xfer_done),
                           score->sce_cmd, score->sce_cmd_arg);

                } else {
                    printf("%5d %-8s [%6s] (n/a) %s %s", (int) score->sce_pid,
                           score->sce_user, show_time(&score->sce_begin_session),
                           score->sce_cmd, score->sce_cmd_arg);
                }

                if (verbose) {
                    printf("%sKB/s: %3.2f%s",
                           (outform & OF_ONELINE) ? " " : "\n\t",
                           (score->sce_xfer_len / 1024.0) /
                           (score->sce_xfer_elapsed / 1000),
                           (outform & OF_ONELINE) ? "" : "\n");
                }
            }

            /* Display additional information, if requested. */
            if (verbose) {
                if (score->sce_client_addr[0]) {
                    printf("%sclient: %s [%s]%s",
                           (outform & OF_ONELINE) ? " " : "\t",
                           score->sce_client_name, score->sce_client_addr,
                           (outform & OF_ONELINE) ? "" : "\n");
                }

                if (score->sce_server_addr[0]) {
                    printf("%sserver: %s (%s)%s",
                           (outform & OF_ONELINE) ? " " : "\t",
                           score->sce_server_addr, score->sce_server_label,
                           (outform & OF_ONELINE) ? "" : "\n");
                }

                if (score->sce_protocol[0]) {
                    printf("%sprotocol: %s%s",
                           (outform & OF_ONELINE) ? " " : "\t",
                           score->sce_protocol,
                           (outform & OF_ONELINE) ? "" : "\n");
                }

                if (score->sce_cwd[0]) {
                    printf("%slocation: %s%s",
                           (outform & OF_ONELINE) ? " " : "\t",
                           score->sce_cwd,
                           (outform & OF_ONELINE) ? "" : "\n");
                }

                if (score->sce_class[0]) {
                    printf("%sclass: %s",
                           (outform & OF_ONELINE) ? " " : "\t",
                           score->sce_class);
                }

                printf("%s", "\n");

            } else {
                printf("%s", "\n");
            }

        } else {

            printf("%5d %-8s [%6s] (authenticating)", (int) score->sce_pid,
                   score->sce_user, show_time(&score->sce_begin_session));

            /* Display additional information, if requested. */
            if (verbose) {
                if (score->sce_client_addr[0]) {
                    printf("%sclient: %s [%s]%s",
                           (outform & OF_ONELINE) ? " " : "\n\t",
                           score->sce_client_name, score->sce_client_addr,
                           (outform & OF_ONELINE) ? "" : "\n");
                }

                if (score->sce_server_addr[0]) {
                    printf("%sserver: %s (%s)%s",
                           (outform & OF_ONELINE) ? " " : "\t",
                           score->sce_server_addr, score->sce_server_label,
                           (outform & OF_ONELINE) ? "" : "\n");
                }

                if (score->sce_protocol[0]) {
                    printf("%sprotocol: %s%s",
                           (outform & OF_ONELINE) ? " " : "\t",
                           score->sce_protocol,
                           (outform & OF_ONELINE) ? "" : "\n");
                }

                if (score->sce_class[0]) {
                    printf("%sclass: %s",
                           (outform & OF_ONELINE) ? " " : "\t",
                           score->sce_class);
                }
            }

            printf("%s", "\n");
        }
    }
    util_close_scoreboard();

    if (total) {
        register unsigned int i = 0;

        for (i = 0; i != MAX_CLASSES; i++) {
            if (classes[i].score_class == 0)
                break;

            printf("Service class %-20s - %3lu user%s\n", classes[i].score_class,
                   classes[i].score_count, classes[i].score_count > 1 ? "s" : "");
        }

    } else {
        printf("no users connected\n");
    }

    if (server_name) {
        free(server_name);
        server_name = NULL;
    }

    return 0;
}