static PyObject* Pakfire_execute_logging_callback = NULL;
-static int __Pakfire_execute_logging_callback(Pakfire pakfire, int priority, const char* data) {
+static int __Pakfire_execute_logging_callback(Pakfire pakfire, void* data,
+ int priority, const char* line) {
int r = 0;
// Do nothing if callback isn't set
return 0;
// Create tuple with arguments for the callback function
- PyObject* args = Py_BuildValue("(is)", priority, data);
+ PyObject* args = Py_BuildValue("(is)", priority, line);
if (!args)
return 1;
// Execute command
int r = pakfire_execute(self->pakfire, argv, envp, flags,
- (logging_callback) ? __Pakfire_execute_logging_callback : NULL);
+ (logging_callback) ? __Pakfire_execute_logging_callback : NULL, NULL);
// Cleanup
for (unsigned int i = 0; envp[i]; i++)
// Execute script
int r = pakfire_execute_script(self->pakfire, script, strlen(script), envp, flags,
- (logging_callback) ? __Pakfire_execute_logging_callback : NULL);
+ (logging_callback) ? __Pakfire_execute_logging_callback : NULL, NULL);
// Cleanup
for (unsigned int i = 0; envp[i]; i++)
If not newline character is found, it will try to read more data until it finds one.
*/
static int pakfire_execute_logger_proxy(Pakfire pakfire, int fd,
- pakfire_execute_logging_callback logging_callback, int priority, struct pakfire_execute_buffer* buffer) {
+ pakfire_execute_logging_callback logging_callback, void* data, int priority,
+ struct pakfire_execute_buffer* buffer) {
char line[BUFFER_SIZE + 1];
// Fill up buffer from fd
line[length] = '\0';
// Log the line
- int r = logging_callback(pakfire, priority, line);
+ int r = logging_callback(pakfire, data, priority, line);
if (r)
return r;
}
static int pakfire_execute_logger(Pakfire pakfire, pakfire_execute_logging_callback logging_callback,
- pid_t pid, int stdout, int stderr, int* status) {
+ void* data, pid_t pid, int stdout, int stderr, int* status) {
int epollfd = -1;
struct epoll_event ev;
struct epoll_event events[EPOLL_MAX_EVENTS];
}
// Send everything to the logger
- r = pakfire_execute_logger_proxy(pakfire, fd, logging_callback, priority, buffer);
+ r = pakfire_execute_logger_proxy(pakfire, fd, logging_callback, data, priority, buffer);
if (r)
goto OUT;
}
return r;
}
-static int default_logging_callback(Pakfire pakfire, int priority, const char* line) {
+static int default_logging_callback(Pakfire pakfire, void* data, int priority, const char* line) {
switch (priority) {
case LOG_INFO:
INFO(pakfire, "%s", line);
}
PAKFIRE_EXPORT int pakfire_execute(Pakfire pakfire, const char* argv[], char* envp[],
- int flags, pakfire_execute_logging_callback logging_callback) {
+ int flags, pakfire_execute_logging_callback logging_callback, void* data) {
struct pakfire_execute env = {
.pakfire = pakfire,
.argv = argv,
if (env.stderr[1])
close(env.stderr[1]);
- if (pakfire_execute_logger(pakfire, logging_callback, pid, env.stdout[0], env.stderr[0], &status)) {
+ if (pakfire_execute_logger(pakfire, logging_callback, data, pid, env.stdout[0], env.stderr[0], &status)) {
ERROR(pakfire, "Log reading aborted: %s\n", strerror(errno));
}
}
}
PAKFIRE_EXPORT int pakfire_execute_command(Pakfire pakfire, const char* command, char* envp[],
- int flags, pakfire_execute_logging_callback logging_callback) {
+ int flags, pakfire_execute_logging_callback logging_callback, void* data) {
const char* argv[2] = {
command, NULL,
};
- return pakfire_execute(pakfire, argv, envp, flags, logging_callback);
+ return pakfire_execute(pakfire, argv, envp, flags, logging_callback, data);
}
-PAKFIRE_EXPORT int pakfire_execute_script(Pakfire pakfire, const char* data, const size_t size,
- char* envp[], int flags, pakfire_execute_logging_callback logging_callback) {
+PAKFIRE_EXPORT int pakfire_execute_script(Pakfire pakfire, const char* script, const size_t size,
+ char* envp[], int flags, pakfire_execute_logging_callback logging_callback, void* data) {
const char* root = pakfire_get_path(pakfire);
// Write the scriptlet to disk
DEBUG(pakfire, "Writing script to %s\n", path);
// Write data
- ssize_t bytes_written = write(fd, data, size);
+ ssize_t bytes_written = write(fd, script, size);
if (bytes_written < (ssize_t)size) {
ERROR(pakfire, "Could not write script to file %s: %s\n",
path, strerror(errno));
command = pakfire_path_relpath(root, path);
// Run the script
- r = pakfire_execute_command(pakfire, command, envp, flags, logging_callback);
+ r = pakfire_execute_command(pakfire, command, envp, flags, logging_callback, data);
if (r) {
DEBUG(pakfire, "Script return code: %d\n", r);
}
#include <pakfire/types.h>
-typedef int (*pakfire_execute_logging_callback)(Pakfire pakfire, int priority, const char* data);
+typedef int (*pakfire_execute_logging_callback)(Pakfire pakfire, void* data,
+ int priority, const char* line);
int pakfire_execute(Pakfire pakfire, const char* argv[], char* envp[],
- int flags, pakfire_execute_logging_callback logging_callback);
+ int flags, pakfire_execute_logging_callback logging_callback, void* data);
int pakfire_execute_command(Pakfire pakfire, const char* command, char* envp[],
- int flags, pakfire_execute_logging_callback logging_callback);
-int pakfire_execute_script(Pakfire pakfire, const char* data, const size_t size,
- char* envp[], int flags, pakfire_execute_logging_callback logging_callback);
+ int flags, pakfire_execute_logging_callback logging_callback, void* data);
+int pakfire_execute_script(Pakfire pakfire, const char* script, const size_t size,
+ char* envp[], int flags, pakfire_execute_logging_callback logging_callback, void* data);
enum {
PAKFIRE_EXECUTE_NONE = 0,
}
static int pakfire_step_run_shell_script(PakfireStep step, struct pakfire_scriptlet* scriptlet) {
- return pakfire_execute_script(step->pakfire, scriptlet->data, scriptlet->size, NULL, 0, NULL);
+ return pakfire_execute_script(step->pakfire, scriptlet->data, scriptlet->size, NULL, 0, NULL, NULL);
}
static int pakfire_step_run_script(PakfireStep step,
const char* path = pakfire_get_path(step->pakfire);
if (pakfire_access(step->pakfire, path, LDCONFIG, X_OK) == 0) {
- r = pakfire_execute_command(step->pakfire, LDCONFIG, NULL, 0, NULL);
+ r = pakfire_execute_command(step->pakfire, LDCONFIG, NULL, 0, NULL, NULL);
DEBUG(step->pakfire, "ldconfig returned %d\n", r);
}