void cluster_helper_c::handle_discarded_duration(bool create_new_file, bool previously_discarding) { m->previous_discarded_duration = m->discarded_duration; if (create_new_file) { // || (!previously_discarding && m->discarding)) { mxdebug_if(m->debug_splitting, boost::format("RESETTING discarded duration of %1%, create_new_file %2% previously_discarding %3% m->discarding %4%\n") % format_timestamp(m->discarded_duration) % create_new_file % previously_discarding % m->discarding); m->discarded_duration = 0; } else if (previously_discarding && !m->discarding) { auto diff = m->last_discarded_timecode_and_duration - std::max<int64_t>(m->first_discarded_timecode, 0); m->discarded_duration += diff; mxdebug_if(m->debug_splitting, boost::format("ADDING to discarded duration TC at %1% / %2% diff %3% new total %4% create_new_file %5% previously_discarding %6% m->discarding %7%\n") % format_timestamp(m->first_discarded_timecode) % format_timestamp(m->last_discarded_timecode_and_duration) % format_timestamp(diff) % format_timestamp(m->discarded_duration) % create_new_file % previously_discarding % m->discarding); } else mxdebug_if(m->debug_splitting, boost::format("KEEPING discarded duration at %1%, create_new_file %2% previously_discarding %3% m->discarding %4%\n") % format_timestamp(m->discarded_duration) % create_new_file % previously_discarding % m->discarding); m->first_discarded_timecode = -1; m->last_discarded_timecode_and_duration = 0; }
static void warn_wall(usec_t n, struct shutdownd_command *c) { assert(c); assert(c->warn_wall); if (n >= c->elapse) return; if (c->wall_message[0]) utmp_wall(c->wall_message, NULL); else { char date[FORMAT_TIMESTAMP_MAX]; const char* prefix; char *l = NULL; if (c->mode == 'H') prefix = "The system is going down for system halt at "; else if (c->mode == 'P') prefix = "The system is going down for power-off at "; else if (c->mode == 'r') prefix = "The system is going down for reboot at "; else assert_not_reached("Unknown mode!"); if (asprintf(&l, "%s%s!", prefix, format_timestamp(date, sizeof(date), c->elapse)) < 0) log_error("Failed to allocate wall message"); else { utmp_wall(l, NULL); free(l); } } }
EbmlElement * kax_file_c::read_next_level1_element(uint32_t wanted_id, bool report_cluster_timestamp) { try { auto element = read_next_level1_element_internal(wanted_id); if (report_cluster_timestamp && (-1 != m_timestamp_scale)) report(boost::format(Y("The first cluster timestamp after the resync is %1%.\n")) % format_timestamp(FindChildValue<KaxClusterTimecode>(static_cast<KaxCluster *>(element)) * m_timestamp_scale)); return element; } catch (mtx::mm_io::exception &e) { mxwarn(boost::format("%1% %2% %3%\n") % (boost::format(Y("%1%: an exception occurred (message: %2%; type: %3%).")) % "kax_file_c::read_next_level1_element()" % (boost::format("%1% / %2%") % e.what() % e.error()) % typeid(e).name()) % Y("This usually indicates a damaged file structure.") % Y("The file will not be processed further.")); } catch (std::exception &e) { mxwarn(boost::format("%1% %2% %3%\n") % (boost::format(Y("%1%: an exception occurred (message: %2%; type: %3%).")) % "kax_file_c::read_next_level1_element()" % e.what() % typeid(e).name()) % Y("This usually indicates a damaged file structure.") % Y("The file will not be processed further.")); } catch (...) { mxwarn(boost::format("%1% %2% %3%\n") % (boost::format(Y("%1%: an unknown exception occurred.")) % "kax_file_c::read_next_level1_element()") % Y("This usually indicates a damaged file structure.") % Y("The file will not be processed further.")); } return nullptr; }
static void test_one(const char *input, const char *output) { CalendarSpec *c; _cleanup_free_ char *p = NULL, *q = NULL; usec_t u; char buf[FORMAT_TIMESTAMP_MAX]; int r; assert_se(calendar_spec_from_string(input, &c) >= 0); assert_se(calendar_spec_to_string(c, &p) >= 0); printf("\"%s\" → \"%s\"\n", input, p); assert_se(streq(p, output)); u = now(CLOCK_REALTIME); r = calendar_spec_next_usec(c, u, &u); printf("Next: %s\n", r < 0 ? strerror(-r) : format_timestamp(buf, sizeof(buf), u)); calendar_spec_free(c); assert_se(calendar_spec_from_string(p, &c) >= 0); assert_se(calendar_spec_to_string(c, &q) >= 0); calendar_spec_free(c); assert_se(streq(q, p)); }
void editable_event::timestamp (const std::string & ts_string) { midipulse ts = m_parent.string_to_pulses(ts_string); event::set_timestamp(ts); format_timestamp(); }
static void append_debug_pipe_message(LogPipeMessage *pipe_message) { char timestamp[MAX_TIMESTAMP_LENGTH]; uint64_t seconds = pipe_message->timestamp / 1000000; int microseconds = pipe_message->timestamp % 1000000; const char *level = "Unknown"; char source[192]; format_timestamp(seconds, microseconds, timestamp, sizeof(timestamp), "-", " ", ":"); switch (pipe_message->level) { case LOG_LEVEL_ERROR: level = "Error"; break; case LOG_LEVEL_WARN: level = "Warn"; break; case LOG_LEVEL_INFO: level = "Info"; break; case LOG_LEVEL_DEBUG: level = "Debug"; break; } if ((pipe_message->flags & LOG_PIPE_MESSAGE_FLAG_LIBUSB) != 0) { _snprintf(source, sizeof(source), "libusb:%s", pipe_message->source); } else { _snprintf(source, sizeof(source), "%s:%d", pipe_message->source, pipe_message->line); } append_debug_item(timestamp, level, source, pipe_message->message); }
static void append_debug_meta_message(const char *message) { char timestamp[MAX_TIMESTAMP_LENGTH]; format_timestamp(time(NULL), 0, timestamp, sizeof(timestamp), "-", " ", ":"); append_debug_item(timestamp, "Meta", "", message); }
void cluster_helper_c::create_tags_for_track_statistics(KaxTags &tags, std::string const &writing_app, boost::posix_time::ptime const &writing_date) { auto writing_date_str = !writing_date.is_not_a_date_time() ? mtx::date_time::to_string(writing_date, "%Y-%m-%d %H:%M:%S") : "1970-01-01 00:00:00"; for (auto const &ptzr : g_packetizers) { auto track_uid = ptzr.packetizer->get_uid(); auto const &stats = m->track_statistics[track_uid]; auto bps = stats.get_bits_per_second(); auto duration = stats.get_duration(); mtx::tags::remove_simple_tags_for<KaxTagTrackUID>(tags, track_uid, "BPS"); mtx::tags::remove_simple_tags_for<KaxTagTrackUID>(tags, track_uid, "DURATION"); mtx::tags::remove_simple_tags_for<KaxTagTrackUID>(tags, track_uid, "NUMBER_OF_FRAMES"); mtx::tags::remove_simple_tags_for<KaxTagTrackUID>(tags, track_uid, "NUMBER_OF_BYTES"); auto tag = mtx::tags::find_tag_for<KaxTagTrackUID>(tags, track_uid, mtx::tags::Movie, true); mtx::tags::set_target_type(*tag, mtx::tags::Movie, "MOVIE"); mtx::tags::set_simple(*tag, "BPS", to_string(bps ? *bps : 0)); mtx::tags::set_simple(*tag, "DURATION", format_timestamp(duration ? *duration : 0)); mtx::tags::set_simple(*tag, "NUMBER_OF_FRAMES", to_string(stats.get_num_frames())); mtx::tags::set_simple(*tag, "NUMBER_OF_BYTES", to_string(stats.get_num_bytes())); mtx::tags::set_simple(*tag, "_STATISTICS_WRITING_APP", writing_app); mtx::tags::set_simple(*tag, "_STATISTICS_WRITING_DATE_UTC", writing_date_str); mtx::tags::set_simple(*tag, "_STATISTICS_TAGS", "BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES"); } m->track_statistics.clear(); }
static void dump_commit (GVariant *variant, OstreeDumpFlags flags) { const gchar *subject; const gchar *body; guint64 timestamp; gs_free gchar *str; /* See OSTREE_COMMIT_GVARIANT_FORMAT */ g_variant_get (variant, "(a{sv}aya(say)&s&stayay)", NULL, NULL, NULL, &subject, &body, ×tamp, NULL, NULL); timestamp = GUINT64_FROM_BE (timestamp); str = format_timestamp (timestamp); if (str) g_print ("Date: %s\n", str); g_print ("\n"); dump_indented_lines (subject); if (body[0]) { g_print ("\n"); dump_indented_lines (body); } g_print ("\n"); }
static void append_debug_pipe_message(LogPipeMessage *pipe_message) { char timestamp[MAX_TIMESTAMP_LEN]; uint64_t seconds = pipe_message->timestamp / 1000000; int microseconds = pipe_message->timestamp % 1000000; const char *level = "<unknown>"; const char *category = "<unknown>"; char line[64]; format_timestamp(seconds, microseconds, timestamp, sizeof(timestamp), "-", " ", ":"); switch (pipe_message->level) { case LOG_LEVEL_NONE: level = "None"; break; case LOG_LEVEL_ERROR: level = "Error"; break; case LOG_LEVEL_WARN: level = "Warn"; break; case LOG_LEVEL_INFO: level = "Info"; break; case LOG_LEVEL_DEBUG: level = "Debug"; break; } switch (pipe_message->category) { case LOG_CATEGORY_EVENT: category = "Event"; break; case LOG_CATEGORY_USB: category = "USB"; break; case LOG_CATEGORY_NETWORK: category = "Network"; break; case LOG_CATEGORY_HOTPLUG: category = "Hotplug"; break; case LOG_CATEGORY_HARDWARE: category = "Hardware"; break; case LOG_CATEGORY_WEBSOCKET: category = "WebSocket"; break; case LOG_CATEGORY_OTHER: category = "Other"; break; case LOG_CATEGORY_LIBUSB: category = "libusb"; break; } _snprintf(line, sizeof(line), "%d", pipe_message->line); append_debug_item(timestamp, level, category, pipe_message->file, line, pipe_message->function, pipe_message->message); }
static int warn_wall(Manager *m, usec_t n) { char date[FORMAT_TIMESTAMP_MAX] = {}; _cleanup_free_ char *l = NULL; usec_t left; int r; assert(m); if (!m->enable_wall_messages) return 0; left = m->scheduled_shutdown_timeout > n; r = asprintf(&l, "%s%sThe system is going down for %s %s%s!", strempty(m->wall_message), isempty(m->wall_message) ? "" : "\n", m->scheduled_shutdown_type, left ? "at " : "NOW", left ? format_timestamp(date, sizeof(date), m->scheduled_shutdown_timeout) : ""); if (r < 0) { log_oom(); return 0; } utmp_wall(l, uid_to_name(m->scheduled_shutdown_uid), m->scheduled_shutdown_tty, logind_wall_tty_filter, m); return 1; }
int main(int argc, char* argv[]) { char s[MAX(FORMAT_TIMESPAN_MAX, FORMAT_TIMESTAMP_MAX)]; int r; dual_timestamp fw, l, k; dual_timestamp_from_monotonic(&k, 0); r = efi_get_boot_timestamps(NULL, &fw, &l); if (r < 0) { log_error("Failed to read variables: %s", strerror(-r)); return 1; } log_info("Firmware began %s before kernel.", format_timespan(s, sizeof(s), fw.monotonic, 0)); log_info("Loader began %s before kernel.", format_timespan(s, sizeof(s), l.monotonic, 0)); log_info("Firmware began %s.", format_timestamp(s, sizeof(s), fw.realtime)); log_info("Loader began %s.", format_timestamp(s, sizeof(s), l.realtime)); log_info("Kernel began %s.", format_timestamp(s, sizeof(s), k.realtime)); return 0; }
std::string editable_event::stock_event_string () { char temp[80]; std::string ts = format_timestamp(); analyze(); snprintf ( temp, sizeof temp, "%9s %-11s %-10s %-20s", ts.c_str(), m_name_status.c_str(), m_name_channel.c_str(), m_name_data.c_str() ); return std::string(temp); }
static int test_boot_timestamps(void) { char s[MAX(FORMAT_TIMESPAN_MAX, FORMAT_TIMESTAMP_MAX)]; int r; dual_timestamp fw, l, k; dual_timestamp_from_monotonic(&k, 0); r = boot_timestamps(NULL, &fw, &l); if (r < 0) { bool ok = r == -ENOENT || (getuid() != 0 && r == -EACCES); log_full_errno(ok ? LOG_DEBUG : LOG_ERR, r, "Failed to read variables: %m"); return ok ? 0 : r; } log_info("Firmware began %s before kernel.", format_timespan(s, sizeof(s), fw.monotonic, 0)); log_info("Loader began %s before kernel.", format_timespan(s, sizeof(s), l.monotonic, 0)); log_info("Firmware began %s.", format_timestamp(s, sizeof(s), fw.realtime)); log_info("Loader began %s.", format_timestamp(s, sizeof(s), l.realtime)); log_info("Kernel began %s.", format_timestamp(s, sizeof(s), k.realtime)); return 1; }
static int load_clock_timestamp(uid_t uid, gid_t gid) { _cleanup_close_ int fd = -1; usec_t min = TIME_EPOCH * USEC_PER_SEC; usec_t ct; int r; /* Let's try to make sure that the clock is always * monotonically increasing, by saving the clock whenever we * have a new NTP time, or when we shut down, and restoring it * when we start again. This is particularly helpful on * systems lacking a battery backed RTC. We also will adjust * the time to at least the build time of systemd. */ fd = open("/var/lib/systemd/clock", O_RDWR|O_CLOEXEC, 0644); if (fd >= 0) { struct stat st; usec_t stamp; /* check if the recorded time is later than the compiled-in one */ r = fstat(fd, &st); if (r >= 0) { stamp = timespec_load(&st.st_mtim); if (stamp > min) min = stamp; } /* Try to fix the access mode, so that we can still touch the file after dropping priviliges */ fchmod(fd, 0644); fchown(fd, uid, gid); } else /* create stamp file with the compiled-in date */ touch_file("/var/lib/systemd/clock", true, min, uid, gid, 0644); ct = now(CLOCK_REALTIME); if (ct < min) { struct timespec ts; char date[FORMAT_TIMESTAMP_MAX]; log_info("System clock time unset or jumped backwards, restoring from recorded timestamp: %s", format_timestamp(date, sizeof(date), min)); if (clock_settime(CLOCK_REALTIME, timespec_store(&ts, min)) < 0) log_error_errno(errno, "Failed to restore system clock: %m"); } return 0; }
static void test_one(const char *p) { usec_t t, q; char buf[FORMAT_TIMESTAMP_MAX], buf_relative[FORMAT_TIMESTAMP_RELATIVE_MAX]; assert_se(parse_timestamp(p, &t) >= 0); log_info("%s", format_timestamp(buf, sizeof(buf), t)); /* Chop off timezone */ *strrchr(buf, ' ') = 0; assert_se(parse_timestamp(buf, &q) >= 0); assert_se(q == t); log_info("%s", strna(format_timestamp_relative(buf_relative, sizeof(buf_relative), t))); assert_se(parse_timestamp(buf, &q) >= 0); }
static void test_format_timestamp(void) { unsigned i; log_info("/* %s */", __func__); for (i = 0; i < 100; i++) { char buf[MAX(FORMAT_TIMESTAMP_MAX, FORMAT_TIMESPAN_MAX)]; usec_t x, y; random_bytes(&x, sizeof(x)); x = x % (2147483600 * USEC_PER_SEC) + 1; assert_se(format_timestamp(buf, sizeof(buf), x)); log_info("%s", buf); assert_se(parse_timestamp(buf, &y) >= 0); assert_se(x / USEC_PER_SEC == y / USEC_PER_SEC); assert_se(format_timestamp_utc(buf, sizeof(buf), x)); log_info("%s", buf); assert_se(parse_timestamp(buf, &y) >= 0); assert_se(x / USEC_PER_SEC == y / USEC_PER_SEC); assert_se(format_timestamp_us(buf, sizeof(buf), x)); log_info("%s", buf); assert_se(parse_timestamp(buf, &y) >= 0); assert_se(x == y); assert_se(format_timestamp_us_utc(buf, sizeof(buf), x)); log_info("%s", buf); assert_se(parse_timestamp(buf, &y) >= 0); assert_se(x == y); assert_se(format_timestamp_relative(buf, sizeof(buf), x)); log_info("%s", buf); assert_se(parse_timestamp(buf, &y) >= 0); /* The two calls above will run with a slightly different local time. Make sure we are in the same * range however, but give enough leeway that this is unlikely to explode. And of course, * format_timestamp_relative() scales the accuracy with the distance from the current time up to one * month, cover for that too. */ assert_se(y > x ? y - x : x - y <= USEC_PER_MONTH + USEC_PER_DAY); } }
static void dump_commit (GVariant *variant, OstreeDumpFlags flags) { const gchar *subject; const gchar *body; guint64 timestamp; g_autofree char *str = NULL; g_autofree char *version = NULL; g_autoptr(GError) local_error = NULL; /* See OSTREE_COMMIT_GVARIANT_FORMAT */ g_variant_get (variant, "(a{sv}aya(say)&s&stayay)", NULL, NULL, NULL, &subject, &body, ×tamp, NULL, NULL); timestamp = GUINT64_FROM_BE (timestamp); str = format_timestamp (timestamp, &local_error); if (!str) errx (1, "Failed to read commit: %s", local_error->message); g_print ("Date: %s\n", str); if ((version = ot_admin_checksum_version (variant))) { g_print ("Version: %s\n", version); } if (subject[0]) { g_print ("\n"); dump_indented_lines (subject); } else { g_print ("(no subject)\n"); } if (body[0]) { g_print ("\n"); dump_indented_lines (body); } g_print ("\n"); }
json_t *make_timestamp(const char* key, const char *value, const char *format, const char *replicate, baton_error_t *error) { init_baton_error(error); char *formatted = format_timestamp(value, format); json_t *result = json_pack("{s:s}", key, formatted); if (!result) { set_baton_error(error, -1, "Failed to pack timestamp '%s': '%s' as JSON", key, value); goto error; } if (replicate) { int base = 10; char *endptr; int repl = strtoul(replicate, &endptr, base); if (*endptr) { set_baton_error(error, -1, "Failed to parse replicate number from " "string '%s'", replicate); goto error; } json_object_set_new(result, JSON_REPLICATE_KEY, json_integer(repl)); } free(formatted); return result; error: if (formatted) free(formatted); return NULL; }
int bus_print_property(const char *name, sd_bus_message *property, bool all) { char type; const char *contents; int r; assert(name); assert(property); r = sd_bus_message_peek_type(property, &type, &contents); if (r < 0) return r; switch (type) { case SD_BUS_TYPE_STRING: { const char *s; r = sd_bus_message_read_basic(property, type, &s); if (r < 0) return r; if (all || !isempty(s)) printf("%s=%s\n", name, s); return 1; } case SD_BUS_TYPE_BOOLEAN: { bool b; r = sd_bus_message_read_basic(property, type, &b); if (r < 0) return r; printf("%s=%s\n", name, yes_no(b)); return 1; } case SD_BUS_TYPE_UINT64: { uint64_t u; r = sd_bus_message_read_basic(property, type, &u); if (r < 0) return r; /* Yes, heuristics! But we can change this check * should it turn out to not be sufficient */ if (endswith(name, "Timestamp")) { char timestamp[FORMAT_TIMESTAMP_MAX], *t; t = format_timestamp(timestamp, sizeof(timestamp), u); if (t || all) printf("%s=%s\n", name, strempty(t)); } else if (strstr(name, "USec")) { char timespan[FORMAT_TIMESPAN_MAX]; printf("%s=%s\n", name, format_timespan(timespan, sizeof(timespan), u, 0)); } else printf("%s=%llu\n", name, (unsigned long long) u); return 1; } case SD_BUS_TYPE_UINT32: { uint32_t u; r = sd_bus_message_read_basic(property, type, &u); if (r < 0) return r; if (strstr(name, "UMask") || strstr(name, "Mode")) printf("%s=%04o\n", name, u); else printf("%s=%u\n", name, (unsigned) u); return 1; } case SD_BUS_TYPE_INT32: { int32_t i; r = sd_bus_message_read_basic(property, type, &i); if (r < 0) return r; printf("%s=%i\n", name, (int) i); return 1; } case SD_BUS_TYPE_DOUBLE: { double d; r = sd_bus_message_read_basic(property, type, &d); if (r < 0) return r; printf("%s=%g\n", name, d); return 1; } case SD_BUS_TYPE_ARRAY: if (streq(contents, "s")) { bool first = true; const char *str; r = sd_bus_message_enter_container(property, SD_BUS_TYPE_ARRAY, contents); if (r < 0) return r; while((r = sd_bus_message_read_basic(property, SD_BUS_TYPE_STRING, &str)) > 0) { if (first) printf("%s=", name); printf("%s%s", first ? "" : " ", str); first = false; } if (r < 0) return r; if (first && all) printf("%s=", name); if (!first || all) puts(""); r = sd_bus_message_exit_container(property); if (r < 0) return r; return 1; } else if (streq(contents, "y")) { const uint8_t *u; size_t n; r = sd_bus_message_read_array(property, SD_BUS_TYPE_BYTE, (const void**) &u, &n); if (r < 0) return r; if (all || n > 0) { unsigned int i; printf("%s=", name); for (i = 0; i < n; i++) printf("%02x", u[i]); puts(""); } return 1; } else if (streq(contents, "u")) { uint32_t *u; size_t n; r = sd_bus_message_read_array(property, SD_BUS_TYPE_UINT32, (const void**) &u, &n); if (r < 0) return r; if (all || n > 0) { unsigned int i; printf("%s=", name); for (i = 0; i < n; i++) printf("%08x", u[i]); puts(""); } return 1; } break; } return 0; }
int main(int argc, char *argv[]) { BtrfsQuotaInfo quota; int r, fd; fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY); if (fd < 0) log_error_errno(errno, "Failed to open root directory: %m"); else { char ts[FORMAT_TIMESTAMP_MAX], bs[FORMAT_BYTES_MAX]; BtrfsSubvolInfo info; r = btrfs_subvol_get_info_fd(fd, 0, &info); if (r < 0) log_error_errno(r, "Failed to get subvolume info: %m"); else { log_info("otime: %s", format_timestamp(ts, sizeof(ts), info.otime)); log_info("read-only (search): %s", yes_no(info.read_only)); } r = btrfs_qgroup_get_quota_fd(fd, 0, "a); if (r < 0) log_error_errno(r, "Failed to get quota info: %m"); else { log_info("referenced: %s", strna(format_bytes(bs, sizeof(bs), quota.referenced))); log_info("exclusive: %s", strna(format_bytes(bs, sizeof(bs), quota.exclusive))); log_info("referenced_max: %s", strna(format_bytes(bs, sizeof(bs), quota.referenced_max))); log_info("exclusive_max: %s", strna(format_bytes(bs, sizeof(bs), quota.exclusive_max))); } r = btrfs_subvol_get_read_only_fd(fd); if (r < 0) log_error_errno(r, "Failed to get read only flag: %m"); else log_info("read-only (ioctl): %s", yes_no(r)); safe_close(fd); } r = btrfs_subvol_make("/xxxtest"); if (r < 0) log_error_errno(r, "Failed to make subvolume: %m"); r = write_string_file("/xxxtest/afile", "ljsadhfljasdkfhlkjdsfha", WRITE_STRING_FILE_CREATE); if (r < 0) log_error_errno(r, "Failed to write file: %m"); r = btrfs_subvol_snapshot("/xxxtest", "/xxxtest2", 0); if (r < 0) log_error_errno(r, "Failed to make snapshot: %m"); r = btrfs_subvol_snapshot("/xxxtest", "/xxxtest3", BTRFS_SNAPSHOT_READ_ONLY); if (r < 0) log_error_errno(r, "Failed to make snapshot: %m"); r = btrfs_subvol_remove("/xxxtest", BTRFS_REMOVE_QUOTA); if (r < 0) log_error_errno(r, "Failed to remove subvolume: %m"); r = btrfs_subvol_remove("/xxxtest2", BTRFS_REMOVE_QUOTA); if (r < 0) log_error_errno(r, "Failed to remove subvolume: %m"); r = btrfs_subvol_remove("/xxxtest3", BTRFS_REMOVE_QUOTA); if (r < 0) log_error_errno(r, "Failed to remove subvolume: %m"); r = btrfs_subvol_snapshot("/etc", "/etc2", BTRFS_SNAPSHOT_READ_ONLY|BTRFS_SNAPSHOT_FALLBACK_COPY); if (r < 0) log_error_errno(r, "Failed to make snapshot: %m"); r = btrfs_subvol_remove("/etc2", BTRFS_REMOVE_QUOTA); if (r < 0) log_error_errno(r, "Failed to remove subvolume: %m"); r = btrfs_subvol_make("/xxxrectest"); if (r < 0) log_error_errno(r, "Failed to make subvolume: %m"); r = btrfs_subvol_make("/xxxrectest/xxxrectest2"); if (r < 0) log_error_errno(r, "Failed to make subvolume: %m"); r = btrfs_subvol_make("/xxxrectest/xxxrectest3"); if (r < 0) log_error_errno(r, "Failed to make subvolume: %m"); r = btrfs_subvol_make("/xxxrectest/xxxrectest3/sub"); if (r < 0) log_error_errno(r, "Failed to make subvolume: %m"); if (mkdir("/xxxrectest/dir", 0755) < 0) log_error_errno(errno, "Failed to make directory: %m"); r = btrfs_subvol_make("/xxxrectest/dir/xxxrectest4"); if (r < 0) log_error_errno(r, "Failed to make subvolume: %m"); if (mkdir("/xxxrectest/dir/xxxrectest4/dir", 0755) < 0) log_error_errno(errno, "Failed to make directory: %m"); r = btrfs_subvol_make("/xxxrectest/dir/xxxrectest4/dir/xxxrectest5"); if (r < 0) log_error_errno(r, "Failed to make subvolume: %m"); if (mkdir("/xxxrectest/mnt", 0755) < 0) log_error_errno(errno, "Failed to make directory: %m"); r = btrfs_subvol_snapshot("/xxxrectest", "/xxxrectest2", BTRFS_SNAPSHOT_RECURSIVE); if (r < 0) log_error_errno(r, "Failed to snapshot subvolume: %m"); r = btrfs_subvol_remove("/xxxrectest", BTRFS_REMOVE_QUOTA|BTRFS_REMOVE_RECURSIVE); if (r < 0) log_error_errno(r, "Failed to recursively remove subvolume: %m"); r = btrfs_subvol_remove("/xxxrectest2", BTRFS_REMOVE_QUOTA|BTRFS_REMOVE_RECURSIVE); if (r < 0) log_error_errno(r, "Failed to recursively remove subvolume: %m"); r = btrfs_subvol_make("/xxxquotatest"); if (r < 0) log_error_errno(r, "Failed to make subvolume: %m"); r = btrfs_subvol_auto_qgroup("/xxxquotatest", 0, true); if (r < 0) log_error_errno(r, "Failed to set up auto qgroup: %m"); r = btrfs_subvol_make("/xxxquotatest/beneath"); if (r < 0) log_error_errno(r, "Failed to make subvolume: %m"); r = btrfs_subvol_auto_qgroup("/xxxquotatest/beneath", 0, false); if (r < 0) log_error_errno(r, "Failed to set up auto qgroup: %m"); r = btrfs_qgroup_set_limit("/xxxquotatest/beneath", 0, 4ULL * 1024 * 1024 * 1024); if (r < 0) log_error_errno(r, "Failed to set up quota limit: %m"); r = btrfs_subvol_set_subtree_quota_limit("/xxxquotatest", 0, 5ULL * 1024 * 1024 * 1024); if (r < 0) log_error_errno(r, "Failed to set up quota limit: %m"); r = btrfs_subvol_snapshot("/xxxquotatest", "/xxxquotatest2", BTRFS_SNAPSHOT_RECURSIVE|BTRFS_SNAPSHOT_QUOTA); if (r < 0) log_error_errno(r, "Failed to setup snapshot: %m"); r = btrfs_qgroup_get_quota("/xxxquotatest2/beneath", 0, "a); if (r < 0) log_error_errno(r, "Failed to query quota: %m"); assert_se(quota.referenced_max == 4ULL * 1024 * 1024 * 1024); r = btrfs_subvol_get_subtree_quota("/xxxquotatest2", 0, "a); if (r < 0) log_error_errno(r, "Failed to query quota: %m"); assert_se(quota.referenced_max == 5ULL * 1024 * 1024 * 1024); r = btrfs_subvol_remove("/xxxquotatest", BTRFS_REMOVE_QUOTA|BTRFS_REMOVE_RECURSIVE); if (r < 0) log_error_errno(r, "Failed remove subvolume: %m"); r = btrfs_subvol_remove("/xxxquotatest2", BTRFS_REMOVE_QUOTA|BTRFS_REMOVE_RECURSIVE); if (r < 0) log_error_errno(r, "Failed remove subvolume: %m"); return 0; }
int main(int argc, char *argv[]) { char t[] = "/tmp/journal-XXXXXX"; unsigned n; JournalFile *f; const char *verification_key = argv[1]; usec_t from = 0, to = 0, total = 0; char a[FORMAT_TIMESTAMP_MAX]; char b[FORMAT_TIMESTAMP_MAX]; char c[FORMAT_TIMESPAN_MAX]; struct stat st; uint64_t p; /* journal_file_open requires a valid machine id */ if (access("/etc/machine-id", F_OK) != 0) return EXIT_TEST_SKIP; log_set_max_level(LOG_DEBUG); assert_se(mkdtemp(t)); assert_se(chdir(t) >= 0); log_info("Generating..."); assert_se(journal_file_open("test.journal", O_RDWR|O_CREAT, 0666, true, !!verification_key, NULL, NULL, NULL, &f) == 0); for (n = 0; n < N_ENTRIES; n++) { struct iovec iovec; struct dual_timestamp ts; char *test; dual_timestamp_get(&ts); assert_se(asprintf(&test, "RANDOM=%lu", random() % RANDOM_RANGE)); iovec.iov_base = (void*) test; iovec.iov_len = strlen(test); assert_se(journal_file_append_entry(f, &ts, &iovec, 1, NULL, NULL, NULL) == 0); free(test); } journal_file_close(f); log_info("Verifying..."); assert_se(journal_file_open("test.journal", O_RDONLY, 0666, true, !!verification_key, NULL, NULL, NULL, &f) == 0); /* journal_file_print_header(f); */ journal_file_dump(f); assert_se(journal_file_verify(f, verification_key, &from, &to, &total, true) >= 0); if (verification_key && JOURNAL_HEADER_SEALED(f->header)) log_info("=> Validated from %s to %s, %s missing", format_timestamp(a, sizeof(a), from), format_timestamp(b, sizeof(b), to), format_timespan(c, sizeof(c), total > to ? total - to : 0, 0)); journal_file_close(f); if (verification_key) { log_info("Toggling bits..."); assert_se(stat("test.journal", &st) >= 0); for (p = 38448*8+0; p < ((uint64_t) st.st_size * 8); p ++) { bit_toggle("test.journal", p); log_info("[ %"PRIu64"+%"PRIu64"]", p / 8, p % 8); if (raw_verify("test.journal", verification_key) >= 0) log_notice(ANSI_HIGHLIGHT_RED ">>>> %"PRIu64" (bit %"PRIu64") can be toggled without detection." ANSI_NORMAL, p / 8, p % 8); bit_toggle("test.journal", p); } } log_info("Exiting..."); assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0); return 0; }
/// output MessagePack object to stream in text format void log_text(FILE *stream, msgpack_object *msg) { // helper macro to access a specific array element #define MEMBER(n) msg->via.array.ptr[n] //msgpack_object_print(stream, *msg); // (print msgpack array, DEBUG only) // process ID if (MEMBER(3).type != MSGPACK_OBJECT_NIL) fprintf(stream, "PID 0x%X ", (unsigned int)MEMBER(3).via.u64); // indentation (DEBUG only) //fprintf(stream, "@%u ", (unsigned int)MEMBER(1).via.u64); // serial (DEBUG only) //fprintf(stream, "#%u ", (uint32_t)MEMBER(7).via.u64); // log level LOG_LEVEL level = MEMBER(0).via.u64; putc('[', stream); fputs(log_level_string(level), stream); fputs("] ", stream); double timestamp = MEMBER(2).via.f64; if (timestamp > 0) { // log timestamp (UTC seconds since the Epoch) char time_str[16]; format_timestamp(time_str, sizeof(time_str), "%H:%M:%S.qqq ", timestamp, true); fputs(time_str, stream); } // message origin (e.g. module) if (msgpack_object_str_fwrite(MEMBER(4).via.str, stream)) fputs(": ", stream); switch (level) { case LOG_LEVEL_SEPARATOR: // no message text, no attachment fputs("----------------------------------------", stream); break; case LOG_LEVEL_CHECKPOINT: fputs("Check point '", stream); msgpack_object_str_fwrite(MEMBER(5).via.str, stream); // msg = ID/name fputs("' #", stream); msgpack_object_print(stream, MEMBER(6)); // attachment = pass count break; case LOG_LEVEL_SCRATCHPAD: msgpack_object_str_fwrite(MEMBER(5).via.str, stream); // msg = key fputs(" <- ", stream); msgpack_object_str_fwrite(MEMBER(6).via.str, stream); // attachment = value break; default: msgpack_object_str_fwrite(MEMBER(5).via.str, stream); // the actual message // optional attachment (arbitrary MessagePack object) if (MEMBER(6).type != MSGPACK_OBJECT_NIL) { fputs("\n\t", stream); // new line and TAB msgpack_object_print(stream, MEMBER(6)); } } putc('\n', stream); fflush(stream); }
static int print_timesync_property(const char *name, const char *expected_value, sd_bus_message *m, bool value, bool all) { char type; const char *contents; int r; assert(name); assert(m); r = sd_bus_message_peek_type(m, &type, &contents); if (r < 0) return r; switch (type) { case SD_BUS_TYPE_STRUCT: if (streq(name, "NTPMessage")) { _cleanup_(ntp_status_info_clear) NTPStatusInfo i = {}; char ts[FORMAT_TIMESPAN_MAX], stamp[FORMAT_TIMESTAMP_MAX]; r = map_ntp_message(NULL, NULL, m, NULL, &i); if (r < 0) return r; if (i.packet_count == 0) return 1; if (!value) { fputs(name, stdout); fputc('=', stdout); } printf("{ Leap=%u, Version=%u, Mode=%u, Stratum=%u, Precision=%i,", i.leap, i.version, i.mode, i.stratum, i.precision); printf(" RootDelay=%s,", format_timespan(ts, sizeof(ts), i.root_delay, 0)); printf(" RootDispersion=%s,", format_timespan(ts, sizeof(ts), i.root_dispersion, 0)); if (i.stratum == 1) printf(" Reference=%s,", i.reference.str); else printf(" Reference=%" PRIX32 ",", be32toh(i.reference.val)); printf(" OriginateTimestamp=%s,", format_timestamp(stamp, sizeof(stamp), i.origin)); printf(" ReceiveTimestamp=%s,", format_timestamp(stamp, sizeof(stamp), i.recv)); printf(" TransmitTimestamp=%s,", format_timestamp(stamp, sizeof(stamp), i.trans)); printf(" DestinationTimestamp=%s,", format_timestamp(stamp, sizeof(stamp), i.dest)); printf(" Ignored=%s PacketCount=%" PRIu64 ",", yes_no(i.spike), i.packet_count); printf(" Jitter=%s }\n", format_timespan(ts, sizeof(ts), i.jitter, 0)); return 1; } else if (streq(name, "ServerAddress")) { _cleanup_free_ char *str = NULL; r = map_server_address(NULL, NULL, m, NULL, &str); if (r < 0) return r; if (arg_all || !isempty(str)) bus_print_property_value(name, expected_value, value, str); return 1; } break; } return 0; }
/* * Sub-TLVs consume the "extra data" of Babel TLVs (see Section 4.3 of RFC6126), * their encoding is similar to the encoding of TLVs, but the type namespace is * different: * * o Type 0 stands for Pad1 sub-TLV with the same encoding as the Pad1 TLV. * o Type 1 stands for PadN sub-TLV with the same encoding as the PadN TLV. * o Type 2 stands for Diversity sub-TLV, which propagates diversity routing * data. Its body is a variable-length sequence of 8-bit unsigned integers, * each representing per-hop number of interferring radio channel for the * prefix. Channel 0 is invalid and must not be used in the sub-TLV, channel * 255 interferes with any other channel. * o Type 3 stands for Timestamp sub-TLV, used to compute RTT between * neighbours. In the case of a Hello TLV, the body stores a 32-bits * timestamp, while in the case of a IHU TLV, two 32-bits timestamps are * stored. * * Sub-TLV types 0 and 1 are valid for any TLV type, whether sub-TLV type 2 is * only valid for TLV type 8 (Update). Note that within an Update TLV a missing * Diversity sub-TLV is not the same as a Diversity sub-TLV with an empty body. * The former would mean a lack of any claims about the interference, and the * latter would state that interference is definitely absent. * A type 3 sub-TLV is valid both for Hello and IHU TLVs, though the exact * semantic of the sub-TLV is different in each case. */ static void subtlvs_print(netdissect_options *ndo, const u_char *cp, const u_char *ep, const uint8_t tlv_type) { uint8_t subtype, sublen; const char *sep; uint32_t t1, t2; while (cp < ep) { subtype = *cp++; if(subtype == MESSAGE_SUB_PAD1) { ND_PRINT((ndo, " sub-pad1")); continue; } if(cp == ep) goto corrupt; sublen = *cp++; if(cp + sublen > ep) goto corrupt; switch(subtype) { case MESSAGE_SUB_PADN: ND_PRINT((ndo, " sub-padn")); cp += sublen; break; case MESSAGE_SUB_DIVERSITY: ND_PRINT((ndo, " sub-diversity")); if (sublen == 0) { ND_PRINT((ndo, " empty")); break; } sep = " "; while(sublen--) { ND_PRINT((ndo, "%s%s", sep, tok2str(diversity_str, "%u", *cp++))); sep = "-"; } if(tlv_type != MESSAGE_UPDATE && tlv_type != MESSAGE_UPDATE_SRC_SPECIFIC) ND_PRINT((ndo, " (bogus)")); break; case MESSAGE_SUB_TIMESTAMP: ND_PRINT((ndo, " sub-timestamp")); if(tlv_type == MESSAGE_HELLO) { if(sublen < 4) goto corrupt; t1 = EXTRACT_32BITS(cp); ND_PRINT((ndo, " %s", format_timestamp(t1))); } else if(tlv_type == MESSAGE_IHU) { if(sublen < 8) goto corrupt; t1 = EXTRACT_32BITS(cp); ND_PRINT((ndo, " %s", format_timestamp(t1))); t2 = EXTRACT_32BITS(cp + 4); ND_PRINT((ndo, "|%s", format_timestamp(t2))); } else ND_PRINT((ndo, " (bogus)")); cp += sublen; break; default: ND_PRINT((ndo, " sub-unknown-0x%02x", subtype)); cp += sublen; } /* switch */ } /* while */ return; corrupt: ND_PRINT((ndo, " (corrupt)")); }
void generic_packetizer_c::force_duration_on_last_packet() { if (m_packet_queue.empty()) { mxverb_tid(3, m_ti.m_fname, m_ti.m_id, "force_duration_on_last_packet: packet queue is empty\n"); return; } packet_cptr &packet = m_packet_queue.back(); packet->duration_mandatory = true; mxverb_tid(3, m_ti.m_fname, m_ti.m_id, boost::format("force_duration_on_last_packet: forcing at %1% with %|2$.3f|ms\n") % format_timestamp(packet->timecode) % (packet->duration / 1000.0)); }
static void save_debug_log(void) { char save_timestamp[MAX_TIMESTAMP_LENGTH]; char save_filename[_MAX_PATH]; char *filters = "Log Files (*.log, *.txt)\0*.log;*.txt\0\0"; OPENFILENAME ofn; FILE *fp; int count; LVITEM lvi_timestamp; char timestamp[128]; LVITEM lvi_level; char level[64]; LVITEM lvi_source; char source[192]; LVITEM lvi_message; char message[1024]; int i; format_timestamp(time(NULL), -1, save_timestamp, sizeof(save_timestamp), "", "_", ""); _snprintf(save_filename, sizeof(save_filename), "brickd_debug_%s.log", save_timestamp); memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = _hwnd; ofn.hInstance = _hinstance; ofn.lpstrFilter = filters; ofn.lpstrFile = save_filename; ofn.lpstrDefExt = "log"; ofn.nMaxFile = sizeof(save_filename); ofn.lpstrTitle = "Save Live Debug Log"; ofn.Flags = OFN_EXPLORER | OFN_OVERWRITEPROMPT; if (!GetSaveFileName(&ofn)) { return; } fp = fopen(save_filename, "wb"); if (fp == NULL) { report_error("Could not write to '%s'", save_filename); } count = ListView_GetItemCount(_debug_list_view); lvi_timestamp.iSubItem = 0; lvi_timestamp.mask = LVIF_TEXT; lvi_timestamp.pszText = timestamp; lvi_timestamp.cchTextMax = sizeof(timestamp) - 1; lvi_level.iSubItem = 1; lvi_level.mask = LVIF_TEXT; lvi_level.pszText = level; lvi_level.cchTextMax = sizeof(level) - 1; lvi_source.iSubItem = 2; lvi_source.mask = LVIF_TEXT; lvi_source.pszText = source; lvi_source.cchTextMax = sizeof(source) - 1; lvi_message.iSubItem = 3; lvi_message.mask = LVIF_TEXT; lvi_message.pszText = message; lvi_message.cchTextMax = sizeof(message) - 1; for (i = 0; i < count; ++i) { lvi_timestamp.iItem = i; lvi_level.iItem = i; lvi_source.iItem = i; lvi_message.iItem = i; if (!ListView_GetItem(_debug_list_view, &lvi_timestamp)) { strcpy(timestamp, "Unknown"); } if (!ListView_GetItem(_debug_list_view, &lvi_level)) { strcpy(level, "Unknown"); } if (!ListView_GetItem(_debug_list_view, &lvi_source)) { strcpy(source, "Unknown"); } if (!ListView_GetItem(_debug_list_view, &lvi_message)) { strcpy(message, "Unknown"); } fprintf(fp, "%s <%s> [%s] %s\r\n", timestamp, level, source, message); } fclose(fp); }
void generic_packetizer_c::add_packet2(packet_cptr pack) { if (pack->has_discard_padding()) set_required_matroska_version(4); pack->timecode = ADJUST_TIMECODE(pack->timecode); if (pack->has_bref()) pack->bref = ADJUST_TIMECODE(pack->bref); if (pack->has_fref()) pack->fref = ADJUST_TIMECODE(pack->fref); if (pack->has_duration()) { pack->duration = static_cast<int64_t>(pack->duration * m_ti.m_tcsync.numerator / m_ti.m_tcsync.denominator); if (pack->has_discard_padding()) pack->duration -= std::min(pack->duration, pack->discard_padding.to_ns()); } if ((2 > m_htrack_min_cache) && pack->has_fref()) { set_track_min_cache(2); rerender_track_headers(); } else if ((1 > m_htrack_min_cache) && pack->has_bref()) { set_track_min_cache(1); rerender_track_headers(); } if (0 > pack->timecode) return; // 'timecode < safety_last_timecode' may only occur for B frames. In this // case we have the coding order, e.g. IPB1B2 and the timecodes // I: 0, P: 120, B1: 40, B2: 80. if (!m_relaxed_timecode_checking && (pack->timecode < m_safety_last_timecode) && (0 > pack->fref) && hack_engaged(ENGAGE_ENABLE_TIMECODE_WARNING)) { if (track_audio == m_htrack_type) { int64_t needed_timecode_offset = m_safety_last_timecode + m_safety_last_duration - pack->timecode; m_correction_timecode_offset += needed_timecode_offset; pack->timecode += needed_timecode_offset; if (pack->has_bref()) pack->bref += needed_timecode_offset; if (pack->has_fref()) pack->fref += needed_timecode_offset; mxwarn_tid(m_ti.m_fname, m_ti.m_id, boost::format(Y("The current packet's timecode is smaller than that of the previous packet. " "This usually means that the source file is a Matroska file that has not been created 100%% correctly. " "The timecodes of all packets will be adjusted by %1%ms in order not to lose any data. " "This may throw audio/video synchronization off, but that can be corrected with mkvmerge's \"--sync\" option. " "If you already use \"--sync\" and you still get this warning then do NOT worry -- this is normal. " "If this error happens more than once and you get this message more than once for a particular track " "then either is the source file badly mastered, or mkvmerge contains a bug. " "In this case you should contact the author Moritz Bunkus <*****@*****.**>.\n")) % ((needed_timecode_offset + 500000) / 1000000)); } else mxwarn_tid(m_ti.m_fname, m_ti.m_id, boost::format("generic_packetizer_c::add_packet2: timecode < last_timecode (%1% < %2%). %3%\n") % format_timestamp(pack->timecode) % format_timestamp(m_safety_last_timecode) % BUGMSG); } m_safety_last_timecode = pack->timecode; m_safety_last_duration = pack->duration; pack->timecode_before_factory = pack->timecode; m_packet_queue.push_back(pack); if (!m_timestamp_factory || (TFA_IMMEDIATE == m_timestamp_factory_application_mode)) apply_factory_once(pack); else apply_factory(); }
static int output_timestamp_realtime(FILE *f, sd_journal *j, OutputMode mode, OutputFlags flags, const char *realtime) { char buf[MAX(FORMAT_TIMESTAMP_MAX, 64)]; struct tm *(*gettime_r)(const time_t *, struct tm *); struct tm tm; uint64_t x; time_t t; int r; assert(f); assert(j); if (realtime) r = safe_atou64(realtime, &x); if (!realtime || r < 0 || !VALID_REALTIME(x)) r = sd_journal_get_realtime_usec(j, &x); if (r < 0) return log_error_errno(r, "Failed to get realtime timestamp: %m"); if (IN_SET(mode, OUTPUT_SHORT_FULL, OUTPUT_WITH_UNIT)) { const char *k; if (flags & OUTPUT_UTC) k = format_timestamp_utc(buf, sizeof(buf), x); else k = format_timestamp(buf, sizeof(buf), x); if (!k) { log_error("Failed to format timestamp: %"PRIu64, x); return -EINVAL; } } else { char usec[7]; gettime_r = (flags & OUTPUT_UTC) ? gmtime_r : localtime_r; t = (time_t) (x / USEC_PER_SEC); switch (mode) { case OUTPUT_SHORT_UNIX: xsprintf(buf, "%10"PRI_TIME".%06"PRIu64, t, x % USEC_PER_SEC); break; case OUTPUT_SHORT_ISO: if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", gettime_r(&t, &tm)) <= 0) { log_error("Failed to format ISO time"); return -EINVAL; } break; case OUTPUT_SHORT_ISO_PRECISE: /* No usec in strftime, so we leave space and copy over */ if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.xxxxxx%z", gettime_r(&t, &tm)) <= 0) { log_error("Failed to format ISO-precise time"); return -EINVAL; } xsprintf(usec, "%06"PRI_USEC, x % USEC_PER_SEC); memcpy(buf + 20, usec, 6); break; case OUTPUT_SHORT: case OUTPUT_SHORT_PRECISE: if (strftime(buf, sizeof(buf), "%b %d %H:%M:%S", gettime_r(&t, &tm)) <= 0) { log_error("Failed to format syslog time"); return -EINVAL; } if (mode == OUTPUT_SHORT_PRECISE) { size_t k; assert(sizeof(buf) > strlen(buf)); k = sizeof(buf) - strlen(buf); r = snprintf(buf + strlen(buf), k, ".%06"PRIu64, x % USEC_PER_SEC); if (r <= 0 || (size_t) r >= k) { /* too long? */ log_error("Failed to format precise time"); return -EINVAL; } } break; default: assert_not_reached("Unknown time format"); } } fputs(buf, f); return (int) strlen(buf); }
static void read_event_log(void) { DWORD status = ERROR_SUCCESS; DWORD bytes_to_read = 0; DWORD bytes_read = 0; DWORD minimum_bytes_to_read = 0; PBYTE temp = NULL; if (_record_buffer == NULL) { bytes_to_read = MAX_RECORD_BUFFER_SIZE; _record_buffer = (PBYTE)malloc(bytes_to_read); if (_record_buffer == NULL) { report_error("Could not allocate record buffer"); return; } } while (status == ERROR_SUCCESS) { if (!ReadEventLog(_event_log, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ, 0, _record_buffer, bytes_to_read, &bytes_read, &minimum_bytes_to_read)) { status = GetLastError(); if (status == ERROR_INSUFFICIENT_BUFFER) { status = ERROR_SUCCESS; temp = (PBYTE)realloc(_record_buffer, minimum_bytes_to_read); if (temp == NULL) { report_error("Could not reallocate record buffer to %u bytes", minimum_bytes_to_read); return; } _record_buffer = temp; bytes_to_read = minimum_bytes_to_read; } else if (status != ERROR_HANDLE_EOF) { report_error("Could not read event log: %s (%d)", get_error_name(status), status); return; } } else { PBYTE record = _record_buffer; PBYTE end_of_records = _record_buffer + bytes_read; char timestamp[MAX_TIMESTAMP_LENGTH]; const char *level; const char *source; const char *message; while (record < end_of_records) { if (strcmp((const char *)(record + sizeof(EVENTLOGRECORD)), "Brick Daemon") == 0) { format_timestamp(((PEVENTLOGRECORD)record)->TimeGenerated, -1, timestamp, sizeof(timestamp), "-", " ", ":"); switch (((PEVENTLOGRECORD)record)->EventType) { case EVENTLOG_ERROR_TYPE: level = "Error"; break; case EVENTLOG_WARNING_TYPE: level = "Warn"; break; case EVENTLOG_INFORMATION_TYPE: level = "Info"; break; case EVENTLOG_AUDIT_SUCCESS: level = "Audit Success"; break; case EVENTLOG_AUDIT_FAILURE: level = "Audit Failure"; break; default: level = "Unknown"; break; } switch (((PEVENTLOGRECORD)record)->EventID) { case BRICKD_GENERIC_WARNING: case BRICKD_GENERIC_ERROR: source = "Generic"; break; case BRICKD_LIBUSB_WARNING: case BRICKD_LIBUSB_ERROR: source = "Libusb"; break; default: source = "Unknown"; break; } if (((PEVENTLOGRECORD)record)->NumStrings > 0) { message = (const char *)(record + ((PEVENTLOGRECORD)record)->StringOffset); } else { message = "Unknown"; } append_event_item(timestamp, level, source, message); } record += ((PEVENTLOGRECORD)record)->Length; } } } }