#include <systemd/sd-event.h>
+#include <pakfire/buffer.h>
#include <pakfire/client.h>
#include <pakfire/config.h>
#include <pakfire/ctx.h>
return r;
}
+
+/*
+ This is called when a job has crashed.
+*/
+int pakfire_client_job_crashed(struct pakfire_client* self,
+ const char* job_id, int signo, struct pakfire_buffer* log) {
+ struct json_object* request = NULL;
+ struct pakfire_xfer* xfer = NULL;
+ int r;
+
+ // Create a new request object
+ r = pakfire_json_new_object(&request);
+ if (r < 0)
+ goto ERROR;
+
+ // Add signal number
+ r = pakfire_json_add_int64(request, "signo", signo);
+ if (r < 0)
+ goto ERROR;
+
+ // Optionally append the log
+ if (!pakfire_buffer_is_empty(log)) {
+ r = pakfire_json_add_bytes(request, "log", log->data, log->length);
+ if (r < 0)
+ goto ERROR;
+ }
+
+ // Create a new transfer
+ r = pakfire_client_xfer_create(&xfer, self, "/api/v1/jobs/%s/crashed", job_id);
+ if (r < 0)
+ goto ERROR;
+
+ // Enable authentication
+ r = pakfire_client_xfer_auth(self, xfer);
+ if (r < 0)
+ goto ERROR;
+
+ // Set the request body
+ r = pakfire_xfer_set_json_payload(xfer, request);
+ if (r < 0)
+ goto ERROR;
+
+ // Enqueue the transfer
+ r = pakfire_httpclient_enqueue(self->httpclient, xfer);
+
+ERROR:
+ if (xfer)
+ pakfire_xfer_unref(xfer);
+
+ return r;
+}
#include <json.h>
+#include <pakfire/buffer.h>
#include <pakfire/builder.h>
#include <pakfire/ctx.h>
#include <pakfire/xfer.h>
int pakfire_client_delete_repo(struct pakfire_client* client,
const char* distro, const char* name);
+// Jobs
+
+int pakfire_client_job_crashed(struct pakfire_client* self,
+ const char* job_id, int signo, struct pakfire_buffer* log);
+
#endif /* PAKFIRE_CLIENT_H */
return r;
}
-static int pakfire_job_crashed(struct pakfire_job* job, const siginfo_t* si) {
- struct pakfire_xfer* xfer = NULL;
+static int pakfire_job_crashed(struct pakfire_job* self, const siginfo_t* si) {
+ struct pakfire_buffer log = {};
int r;
- struct pakfire_job_log {
- char* data;
- size_t length;
- } log = {};
-
- DEBUG(job->ctx, "Sending crash report...\n");
+ DEBUG(self->ctx, "Sending crash report...\n");
// Dump the log
- r = pakfire_log_buffer_dump(job->log.buffer, &log.data, &log.length);
- if (r < 0)
- goto ERROR;
-
- // Create a new transfer
- r = pakfire_job_xfer_create(&xfer, job, "/api/v1/jobs/%s/crashed", job->id);
- if (r < 0)
- goto ERROR;
-
- // Enable authentication
- r = pakfire_xfer_auth(xfer);
- if (r)
- goto ERROR;
-
- // Add the exit code
- r = pakfire_xfer_add_param(xfer, "signo", "%d", si->si_status);
+ r = pakfire_log_buffer_dump(self->log.buffer, &log.data, &log.length);
if (r < 0)
goto ERROR;
- // If we have a log, let's send the log, too
- // XXX THIS IS NOT QUITE IDEAL BECAUSE THE LOG COULD CONTAIN NULL-CHARACTERS
- // WE SHOULD IMPLEMENT THIS WITH CURL'S MIME CALLBACK FUNCTIONS
- if (log.data) {
- r = pakfire_xfer_add_param(xfer, "log", "%.*s", (int)log.length, log.data);
- if (r < 0)
- goto ERROR;
- }
-
- // Send the request
- r = pakfire_xfer_run_api_request(xfer, NULL, NULL);
- if (r < 0)
- goto ERROR;
+ // Send the report
+ r = pakfire_client_job_crashed(self->client, self->id, si->si_status, &log);
ERROR:
- if (xfer)
- pakfire_xfer_unref(xfer);
- if (log.data)
- free(log.data);
+ pakfire_buffer_free(&log);
return r;
}