struct pakfire_jail;
+typedef int (*pakfire_jail_log_callback)
+ (struct pakfire* pakfire, void* data, int priority, const char* line, size_t length);
+
int pakfire_jail_create(struct pakfire_jail** jail, struct pakfire* pakfire);
struct pakfire_jail* pakfire_jail_ref(struct pakfire_jail* jail);
int pakfire_jail_bind(struct pakfire_jail* jail,
const char* source, const char* target, int flags);
+// Callbacks
+void pakfire_jail_set_log_callback(struct pakfire_jail* jail,
+ pakfire_jail_log_callback callback, void* data);
+
// Resource Limits
int pakfire_jail_nice(struct pakfire_jail* jail, int nice);
// Mountpoints
struct pakfire_jail_mountpoint mountpoints[MAX_MOUNTPOINTS];
unsigned int num_mountpoints;
+
+ // Callbacks
+ struct pakfire_jail_callbacks {
+ // Log
+ pakfire_jail_log_callback log;
+ void* log_data;
+ } callbacks;
};
struct pakfire_log_buffer {
DEBUG(j->pakfire, "Allocated new jail at %p\n", j);
+ // Set the default logging callback
+ pakfire_jail_set_log_callback(j, pakfire_jail_default_log_callback, NULL);
+
// Set default environment
for (const struct environ* e = ENV; e->key; e++) {
r = pakfire_jail_set_env(j, e->key, e->val);
return NULL;
}
+// Logging Callback
+
+PAKFIRE_EXPORT void pakfire_jail_set_log_callback(struct pakfire_jail* jail,
+ pakfire_jail_log_callback callback, void* data) {
+ jail->callbacks.log = callback;
+ jail->callbacks.log_data = data;
+}
+
// Resource Limits
PAKFIRE_EXPORT int pakfire_jail_nice(struct pakfire_jail* jail, int nice) {
buffer = &ctx->buffers.log_INFO;
priority = LOG_INFO;
- callback = pakfire_jail_default_log_callback;
+ callback = jail->callbacks.log;
+ data = jail->callbacks.log_data;
} else if (fd == log_ERROR) {
buffer = &ctx->buffers.log_ERROR;
priority = LOG_ERR;
- callback = pakfire_jail_default_log_callback;
+ callback = jail->callbacks.log;
+ data = jail->callbacks.log_data;
} else if (fd == log_DEBUG) {
buffer = &ctx->buffers.log_DEBUG;
priority = LOG_DEBUG;
- callback = pakfire_jail_default_log_callback;
+ callback = jail->callbacks.log;
+ data = jail->callbacks.log_data;
// Handle anything from the log pipes
} else if (fd == stdout) {
buffer = &ctx->buffers.stdout;
priority = LOG_INFO;
- callback = ctx->communicate.out;
- data = ctx->communicate.data;
+ // Send any output to the default logger if no callback is set
+ if (ctx->communicate.out) {
+ callback = ctx->communicate.out;
+ data = ctx->communicate.data;
+ } else {
+ callback = jail->callbacks.log;
+ data = jail->callbacks.log_data;
+ }
} else if (fd == stderr) {
buffer = &ctx->buffers.stderr;
priority = LOG_ERR;
- callback = ctx->communicate.out;
- data = ctx->communicate.data;
+ // Send any output to the default logger if no callback is set
+ if (ctx->communicate.out) {
+ callback = ctx->communicate.out;
+ data = ctx->communicate.data;
+ } else {
+ callback = jail->callbacks.log;
+ data = jail->callbacks.log_data;
+ }
} else {
DEBUG(jail->pakfire, "Received invalid file descriptor %d\n", fd);
return -1;
}
- // Send any output to the default logger if no callback is set
- if (!communicate_out)
- communicate_out = pakfire_jail_default_log_callback;
-
// Initialize context for this call
struct pakfire_jail_exec ctx = {
.flags = flags,