}
}
-static int pakfire_jail_drain_buffer_with_callback(struct pakfire_jail* jail,
- struct pakfire_log_buffer* buffer, pakfire_jail_stdout_callback callback, void* data) {
- const char* eol = NULL;
- int r;
-
- while (buffer->used) {
- // Search for the end of the first line
- eol = memchr(buffer->data, '\n', buffer->used);
-
- // No newline found
- if (!eol) {
- // If the buffer is full, we send the entire content to make space.
- if (buffer->used >= sizeof(buffer->data)) {
- CTX_DEBUG(jail->ctx, "Buffer is full. Sending all content\n");
-
- eol = buffer->data + buffer->used - 1;
-
- // Otherwise we might have only read parts of the output...
- } else {
- break;
- }
- }
-
- // Find the length of the string
- const size_t length = eol - buffer->data + 1;
-
- // Call the callback
- r = callback(jail->ctx, jail, data, buffer->data, length);
- if (r) {
- CTX_ERROR(jail->ctx, "The standard output callback returned an error: %d\n", r);
- return r;
- }
-
- // Remove line from buffer
- memmove(buffer->data, buffer->data + length, buffer->used - length);
- buffer->used -= length;
- }
-
- return 0;
-}
-
/*
Passes any log messages on to the context logger
*/
}
}
-static int pakfire_jail_command_output(struct pakfire_ctx* ctx, struct pakfire_jail* jail,
- void* data, const char* line, const size_t length) {
- CTX_INFO(ctx, "Command Output: %.*s", (int)length, line);
-
- return 0;
-}
-
-int pakfire_jail_capture_stdout(struct pakfire_ctx* ctx, struct pakfire_jail* jail,
- void* data, const char* line, size_t length) {
- char** output = (char**)data;
- int r;
-
- // Append everything from stdout to a buffer
- r = asprintf(output, "%s%.*s", (output && *output) ? *output : "", (int)length, line);
- if (r < 0)
- return -errno;
-
- return 0;
-}
-
// Capabilities
// Logs all capabilities of the current process