mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Change the flush logic for streams
Now stdout and stderr are always line buffered, and stdlog only flushed on request.
This commit is contained in:
parent
80d51384ac
commit
798de7ca99
16 changed files with 40 additions and 20 deletions
|
|
@ -1809,7 +1809,7 @@ bail:
|
|||
else
|
||||
ftag("summary:exit:error\n");
|
||||
}
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
|
||||
free(failed);
|
||||
free(failed_map);
|
||||
|
|
|
|||
|
|
@ -151,6 +151,6 @@ void state_dup(struct snapraid_state* state)
|
|||
} else {
|
||||
ftag("summary:exit:dup\n");
|
||||
}
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -117,6 +117,6 @@ void state_list(struct snapraid_state* state)
|
|||
ftag("summary:file_size:%" PRIu64 "\n", file_size);
|
||||
ftag("summary:link_count:%u\n", link_count);
|
||||
ftag("summary:exit:ok\n");
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -173,6 +173,11 @@ void os_init(int opt)
|
|||
SetThreadExecutionState(WIN32_ES_CONTINUOUS | WIN32_ES_SYSTEM_REQUIRED);
|
||||
}
|
||||
|
||||
/* set stdout and stderr as "line buffered" */
|
||||
/* this ensures that messages are mixed correctly */
|
||||
setvbuf(stdout, 0, _IOLBF, BUFSIZ);
|
||||
setvbuf(stderr, 0, _IOLBF, BUFSIZ);
|
||||
|
||||
last_error = 0;
|
||||
}
|
||||
|
||||
|
|
@ -1907,7 +1912,6 @@ static void* thread_spinup(void* arg)
|
|||
|
||||
pthread_mutex_lock(&io_lock);
|
||||
fprintf(stdout, "Spunup device '%" PRIx64 "' for disk '%s' in %" PRIu64 " ms.\n", (uint64_t)device, devinfo->name, tick_ms() - start);
|
||||
fflush(stdout);
|
||||
pthread_mutex_unlock(&io_lock);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ void parity_overflow(struct snapraid_state* state, data_off_t size)
|
|||
if (file->blockmax > 0) {
|
||||
if (file->blockvec[file->blockmax - 1].parity_pos >= blockalloc) {
|
||||
ftag("outofparity:%s:%s\n", disk->name, file->sub);
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
if (first) {
|
||||
first = 0;
|
||||
printf("\nYour data requires more parity than the available space.\n");
|
||||
|
|
|
|||
|
|
@ -259,6 +259,6 @@ void state_pool(struct snapraid_state* state)
|
|||
|
||||
ftag("summary:link_count::%u\n", count);
|
||||
ftag("summary:exit:ok\n");
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1750,7 +1750,7 @@ void state_scan(struct snapraid_state* state, int is_diff)
|
|||
} else {
|
||||
ftag("summary:exit:diff\n");
|
||||
}
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
}
|
||||
|
||||
tommy_list_foreach(&scanlist, (tommy_foreach_func*)free);
|
||||
|
|
|
|||
|
|
@ -502,7 +502,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par
|
|||
ftag("summary:exit:ok\n");
|
||||
else
|
||||
ftag("summary:exit:error\n");
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
|
||||
bail:
|
||||
for (j = 0; j < diskmax; ++j) {
|
||||
|
|
|
|||
|
|
@ -381,7 +381,7 @@ bail:
|
|||
void selftest(void)
|
||||
{
|
||||
ftag("selftest:\n");
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
|
||||
printf("Self test...\n");
|
||||
|
||||
|
|
|
|||
|
|
@ -924,7 +924,7 @@ int main(int argc, char* argv[])
|
|||
ftag("command:%s\n", command);
|
||||
for (i = 0; i < argc; ++i)
|
||||
ftag("argv:%u:%s\n", i, argv[i]);
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
|
||||
if (!opt.skip_self)
|
||||
selftest();
|
||||
|
|
|
|||
|
|
@ -930,7 +930,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co
|
|||
if (state->filter_hidden)
|
||||
ftag("filter:nohidden:\n");
|
||||
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -4284,7 +4284,7 @@ void state_read(struct snapraid_state* state)
|
|||
|
||||
if (!state->no_conf) {
|
||||
ftag("content:%s\n", path);
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
}
|
||||
printf("Loading state from %s...\n", path);
|
||||
|
||||
|
|
@ -4593,7 +4593,7 @@ int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, b
|
|||
|
||||
if (state->opt.gui) {
|
||||
ftag("run:begin:%u:%u:%u\n", blockstart, blockmax, countmax);
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
}
|
||||
|
||||
now = time(0);
|
||||
|
|
@ -4611,7 +4611,7 @@ int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, b
|
|||
printf("Not starting for interruption\n");
|
||||
}
|
||||
ftag("sigint:0: SIGINT received\n");
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
return 0;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -4623,7 +4623,7 @@ void state_progress_end(struct snapraid_state* state, block_off_t countpos, bloc
|
|||
{
|
||||
if (state->opt.gui) {
|
||||
ftag("run:end\n");
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
} else {
|
||||
time_t now;
|
||||
time_t elapsed;
|
||||
|
|
@ -4758,7 +4758,7 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off
|
|||
|
||||
if (state->opt.gui) {
|
||||
ftag("run:pos:%u:%u:%" PRIu64 ":%u:%u:%u:%u:%" PRIu64 "\n", blockpos, countpos, countsize, out_perc, out_eta, out_speed, out_cpu, (uint64_t)elapsed);
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
} else {
|
||||
printf("%u%%, %u MiB", out_perc, (unsigned)(countsize / (1024 * 1024)));
|
||||
if (out_speed)
|
||||
|
|
@ -4795,7 +4795,7 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off
|
|||
printf("Stopping for interruption at block %u\n", blockpos);
|
||||
}
|
||||
ftag("sigint:%u: SIGINT received\n", blockpos);
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
return 1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ int state_status(struct snapraid_state* state)
|
|||
ftag("summary:hash:%s\n", hash_config_name(state->hash));
|
||||
ftag("summary:prev_hash:%s\n", hash_config_name(state->prevhash));
|
||||
ftag("summary:best_hash:%s\n", hash_config_name(state->besthash));
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
|
||||
/* copy the info a temp vector, and count bad/rehash/unsynced blocks */
|
||||
infomap = malloc_nofail(blockmax * sizeof(snapraid_info));
|
||||
|
|
@ -303,7 +303,7 @@ int state_status(struct snapraid_state* state)
|
|||
ftag("summary:has_unsynced:%u\n", unsynced_blocks);
|
||||
ftag("summary:has_rehash:%u\n", rehash);
|
||||
ftag("summary:has_bad:%u:%u:%u\n", bad, bad_first, bad_last);
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
|
||||
if (!count) {
|
||||
ferr("The array is empty.\n");
|
||||
|
|
|
|||
|
|
@ -63,6 +63,12 @@ void flog(const char* format, ...)
|
|||
}
|
||||
}
|
||||
|
||||
void fflush_log(void)
|
||||
{
|
||||
if (stdlog)
|
||||
fflush(stdlog);
|
||||
}
|
||||
|
||||
void ftag(const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
|
|
|||
|
|
@ -48,6 +48,11 @@ void ferr(const char* format, ...) __attribute__((format(printf, 1, 2)));
|
|||
*/
|
||||
void flog(const char* format, ...) __attribute__((format(printf, 1, 2)));
|
||||
|
||||
/**
|
||||
* Flush the log output.
|
||||
*/
|
||||
void fflush_log(void);
|
||||
|
||||
/**
|
||||
* Tag message.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1151,7 +1151,7 @@ end:
|
|||
ftag("summary:exit:ok\n");
|
||||
else
|
||||
ftag("summary:exit:error\n");
|
||||
fflush(stdlog);
|
||||
fflush_log();
|
||||
|
||||
bail:
|
||||
for (j = 0; j < diskmax; ++j) {
|
||||
|
|
|
|||
|
|
@ -957,6 +957,11 @@ int devquery(tommy_list* high, tommy_list* low, int operation)
|
|||
void os_init(int opt)
|
||||
{
|
||||
(void)opt;
|
||||
|
||||
/* set stdout and stderr as "line buffered" */
|
||||
/* this ensures that messages are mixed correctly */
|
||||
setvbuf(stdout, 0, _IOLBF, BUFSIZ);
|
||||
setvbuf(stderr, 0, _IOLBF, BUFSIZ);
|
||||
}
|
||||
|
||||
void os_done(void)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue