// States
int init:1;
+
+ // Callbacks
+ struct pakfire_build_callbacks {
+ // Log callback
+ pakfire_build_log_callback log;
+ void* log_data;
+ } callbacks;
};
#define TEMPLATE \
return r;
}
-static int pakfire_build_log_strftime(
- char* buffer, const size_t length, const double t) {
+static int pakfire_build_default_log_callback(struct pakfire* pakfire,
+ void* data, int priority, const char* message, size_t length) {
+ // Pass the message to the upstream logger
+ pakfire_log_condition(pakfire, priority, 0, "%.*s", (int)length, message);
+
+ return 0;
+}
+
+static int pakfire_build_log_prepend_timestamp(
+ char** buffer, const double t, const char* message, const int l) {
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);
+ return asprintf(buffer, "[%02d:%02d:%02d.%04d] %.*s", h, m, s, ms, l, message);
else if (m)
- return __pakfire_string_format(buffer, length, " %02d:%02d.%04d", m, s, ms);
+ return asprintf(buffer, "[ %02d:%02d.%04d] %.*s", m, s, ms, l, message);
else
- return __pakfire_string_format(buffer, length, " %02d.%04d", s, ms);
+ return asprintf(buffer, "[ %02d.%04d] %.*s", s, ms, l, message);
}
-static int pakfire_build_log_callback(struct pakfire* pakfire,
+static int pakfire_build_jail_log_callback(struct pakfire* pakfire,
void* data, int priority, const char* line, size_t length) {
struct pakfire_build* build = data;
- char buffer[128];
+ char* buffer = NULL;
int r;
// Get the runtime of the build
return t;
// Format the timestamp
- r = pakfire_build_log_strftime(buffer, sizeof(buffer), t);
+ r = pakfire_build_log_prepend_timestamp(&buffer, t, line, length);
if (r < 0)
return r;
- // Pass the message to the upstream logger
- pakfire_log_condition(pakfire, priority, 0, "[%s] %s", buffer, line);
+ // Run the log callback
+ r = build->callbacks.log(pakfire, build->callbacks.log_data, priority, buffer, r);
- return 0;
+ // Cleanup
+ if (buffer)
+ free(buffer);
+
+ return r;
}
/*
}
// Configure our custom logging callback
- pakfire_jail_set_log_callback(build->jail, pakfire_build_log_callback, build);
+ pakfire_jail_set_log_callback(build->jail, pakfire_build_jail_log_callback, build);
// Connect the jail to our cgroup
r = pakfire_jail_set_cgroup(build->jail, build->cgroup);
// Copy flags
b->flags = flags;
+ // Set default log callback
+ b->callbacks.log = pakfire_build_default_log_callback;
+
// Store start time
r = pakfire_build_set_time_start(b);
if (r)
return NULL;
}
+PAKFIRE_EXPORT void pakfire_build_set_log_callback(struct pakfire_build* build,
+ pakfire_build_log_callback callback, void* data) {
+ build->callbacks.log = callback;
+ build->callbacks.log_data = data;
+}
+
PAKFIRE_EXPORT int pakfire_build_set_ccache_path(
struct pakfire_build* build, const char* path) {
// Check if this can be called
PAKFIRE_BUILD_DISABLE_TESTS = (1 << 3),
};
+typedef int (*pakfire_build_log_callback)
+ (struct pakfire* pakfire, void* data, int priority, const char* message, size_t length);
+
int pakfire_build_create(struct pakfire_build** build,
struct pakfire* pakfire, const char* id, int flags);
struct pakfire_build* pakfire_build_ref(struct pakfire_build* build);
struct pakfire_build* pakfire_build_unref(struct pakfire_build* build);
+void pakfire_build_set_log_callback(struct pakfire_build* build,
+ pakfire_build_log_callback callback, void* data);
+
int pakfire_build_set_ccache_path(struct pakfire_build* build, const char* path);
int pakfire_build_set_target(struct pakfire_build* build, const char* target);