From: Michael Tremer Date: Tue, 19 Dec 2023 17:19:23 +0000 (+0000) Subject: build: Drop setting jail callback and use output callback instead X-Git-Tag: 0.9.30~1267 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c6b9aa3879de6e67ead3e64bcd3e100205dc68e6;p=pakfire.git build: Drop setting jail callback and use output callback instead Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 702fdb426..006a602bc 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -190,6 +190,30 @@ static double pakfire_build_duration(struct pakfire_build* build) { return pakfire_timespec_delta(&now, &build->time_start); } +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; + + // Get the runtime of the build + const double t = pakfire_build_duration(build); + if (t < 0) + return 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 BUILD_LOG(build, priority, "[%02d:%02d:%02d.%04d] %.*s", h, m, s, ms, length, line); + + else if (m) + return BUILD_LOG(build, priority, "[ %02d:%02d.%04d] %.*s", m, s, ms, length, line); + + else + return BUILD_LOG(build, priority, "[ %02d.%04d] %.*s", s, ms, length, line); +} + static int __pakfire_build_setup_repo(struct pakfire* pakfire, struct pakfire_repo* repo, void* p) { char path[PATH_MAX]; @@ -1079,7 +1103,8 @@ static int pakfire_build_stage(struct pakfire_build* build, } // Run the script - r = pakfire_jail_exec_script(build->jail, script, strlen(script), NULL, NULL, NULL, NULL); + r = pakfire_jail_exec_script(build->jail, script, strlen(script), + NULL, NULL, pakfire_build_jail_log_callback, build); if (r) BUILD_ERROR(build, "Build stage '%s' failed with status %d\n", stage, r); @@ -1461,30 +1486,6 @@ ERROR: return r; } -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; - - // Get the runtime of the build - const double t = pakfire_build_duration(build); - if (t < 0) - return 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 BUILD_LOG(build, priority, "[%02d:%02d:%02d.%04d] %.*s", h, m, s, ms, length, line); - - else if (m) - return BUILD_LOG(build, priority, "[ %02d:%02d.%04d] %.*s", m, s, ms, length, line); - - else - return BUILD_LOG(build, priority, "[ %02d.%04d] %.*s", s, ms, length, line); -} - /* Sets up a new jail for this build */ @@ -1498,9 +1499,6 @@ static int pakfire_build_setup_jail(struct pakfire_build* build) { return r; } - // Configure our custom logging callback - 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); if (r) {