static void write_frequent_update() { FILE* handle = fopen (PENDING_FREQUENT_UPDATE_FILENAME, "w"); if (!handle) { #ifndef NDEBUG perror("Could not open update file for writing"); #endif exit(1); } if (!fprintf(handle, "%d\n%s\n", FREQUENT_FILE_FORMAT_VERSION, BUILD_ID) < 0) { #ifndef NDEBUG perror("Error writing update"); #endif exit(1); } time_t current_timestamp = time(NULL); if (!fprintf(handle, "%s %" PRId64 " %d %" PRId64 "\n\n", bismark_id, start_timestamp_microseconds, frequent_sequence_number, (int64_t)current_timestamp) < 0) { #ifndef NDEBUG perror("Error writing update"); #endif exit(1); } if (device_throughput_table_write_update(&device_throughput_table, handle)) { exit(1); } fclose(handle); char update_filename[FILENAME_MAX]; snprintf(update_filename, FILENAME_MAX, FREQUENT_UPDATE_FILENAME, bismark_id, start_timestamp_microseconds, frequent_sequence_number); if (rename(PENDING_FREQUENT_UPDATE_FILENAME, update_filename)) { #ifndef NDEBUG perror("Could not stage update"); #endif exit(1); } ++frequent_sequence_number; device_throughput_table_init(&device_throughput_table); }
static void write_frequent_update() { printf("Writing frequent log to %s\n", PENDING_FREQUENT_UPDATE_FILENAME); FILE* handle = fopen(PENDING_FREQUENT_UPDATE_FILENAME, "w"); if (!handle) { perror("Could not open update file for writing"); exit(1); } if (fprintf(handle, "%d\n", FREQUENT_FILE_FORMAT_VERSION) < 0) { perror("Error writing update"); exit(1); } time_t current_timestamp = time(NULL); if (fprintf(handle, "%" PRId64 "\n", (int64_t)current_timestamp) < 0) { perror("Error writing update"); exit(1); } if (fprintf(handle, "%s\n\n", buffer_to_hex(bismark_mac, ETH_ALEN)) < 0) { perror("Error writing update"); exit(1); } if (device_throughput_table_write_update(&device_throughput_table, handle)) { exit(1); } fclose(handle); char update_filename[FILENAME_MAX]; snprintf(update_filename, FILENAME_MAX, FREQUENT_UPDATE_FILENAME, bismark_id, start_timestamp_microseconds, frequent_sequence_number); if (rename(PENDING_FREQUENT_UPDATE_FILENAME, update_filename)) { perror("Could not stage update"); exit(1); } ++frequent_sequence_number; device_throughput_table_init(&device_throughput_table); }