char target[PATH_MAX];
// Times
- time_t time_start;
+ struct timespec time_start;
// cgroup
struct pakfire_cgroup* cgroup;
return build->flags & flag;
}
-static time_t pakfire_build_duration(struct pakfire_build* build) {
- // What time is it now?
- time_t now = time(NULL);
+static double pakfire_build_duration(struct pakfire_build* build) {
+ struct timespec now;
+ int r;
- // Return any errors
- if (now < 0)
- return now;
+ // What time is it now?
+ r = clock_gettime(CLOCK_MONOTONIC, &now);
+ if (r < 0)
+ return r;
- return now - build->time_start;
+ return pakfire_timespec_delta(&now, &build->time_start);
}
static int __pakfire_build_setup_repo(struct pakfire* pakfire,
return r;
}
+static int pakfire_build_log_strftime(
+ char* buffer, const size_t length, const double t) {
+ const unsigned int h = (unsigned int)t / 3600;
+ const unsigned int m = (unsigned int)t % 3600 / 60;
+ const unsigned int s = (unsigned int)t % 60;
+ const unsigned int ms = (unsigned int)(t * 1000.0) % 1000;
+
+ if (h)
+ return __pakfire_string_format(buffer, length, "%02d:%02d:%02d.%04d", h, m, s, ms);
+
+ else if (m)
+ return __pakfire_string_format(buffer, length, " %02d:%02d.%04d", m, s, ms);
+
+ else
+ return __pakfire_string_format(buffer, length, " %02d.%04d", s, ms);
+}
+
static int pakfire_build_log_callback(struct pakfire* pakfire,
void* data, int priority, const char* line, size_t length) {
struct pakfire_build* build = data;
int r;
// Get the runtime of the build
- const time_t t = pakfire_build_duration(build);
+ const double t = pakfire_build_duration(build);
if (t < 0)
return t;
// Format the timestamp
- r = pakfire_string_format(buffer, "%8ld", t);
+ r = pakfire_build_log_strftime(buffer, sizeof(buffer), t);
if (r < 0)
return r;
}
static int pakfire_build_set_time_start(struct pakfire_build* build) {
- const time_t now = time(NULL);
+ int r;
- if (now < 0) {
+ // Fetch current time
+ r = clock_gettime(CLOCK_MONOTONIC, &build->time_start);
+ if (r < 0)
ERROR(build->pakfire, "Could not fetch start time: %m\n");
- return 1;
- }
-
- build->time_start = now;
- return 0;
+ return r;
}
PAKFIRE_EXPORT int pakfire_build_create(struct pakfire_build** build,