]> git.ipfire.org Git - pakfire.git/blobdiff - src/libpakfire/build.c
build: Drop setting jail callback and use output callback instead
[pakfire.git] / src / libpakfire / build.c
index 702fdb426a7aaba1a572074c36c1389c68c16ba8..006a602bcc8cd5f016fff6358ffa80ceccde6ad1 100644 (file)
@@ -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) {