#include <pakfire/logging.h>
#include <pakfire/private.h>
#include <pakfire/types.h>
+#include <pakfire/util.h>
#define BUFFER_SIZE 1024 * 64
#define EPOLL_MAX_EVENTS 2
return pakfire_execute(pakfire, argv, envp, flags, logging_callback);
}
+
+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) {
+ const char* root = pakfire_get_path(pakfire);
+
+ // Write the scriptlet to disk
+ char* path = pakfire_path_join(root, "tmp/.pakfire-script.XXXXXX");
+ int r;
+
+ DEBUG(pakfire, "Writing script to %s\n", path);
+
+ // Open a temporary file
+ int fd = mkstemp(path);
+ if (fd < 0) {
+ ERROR(pakfire, "Could not open a temporary file: %s\n",
+ strerror(errno));
+
+ r = errno;
+ }
+
+ // Write data
+ ssize_t bytes_written = write(fd, data, size);
+ if (bytes_written < (ssize_t)size) {
+ ERROR(pakfire, "Could not write script to file %s: %s\n",
+ path, strerror(errno));
+
+ r = errno;
+ goto out;
+ }
+
+ // Make the script executable
+ r = fchmod(fd, S_IRUSR|S_IWUSR|S_IXUSR);
+ if (r) {
+ ERROR(pakfire, "Could not set executable permissions on %s: %s\n",
+ path, strerror(errno));
+
+ r = errno;
+ goto out;
+ }
+
+ // Close file
+ r = close(fd);
+ if (r) {
+ ERROR(pakfire, "Could not close script file %s: %s\n",
+ path, strerror(errno));
+
+ r = errno;
+ goto out;
+ }
+
+ const char* command = path;
+ if (root)
+ command = pakfire_path_relpath(root, path);
+
+ // Run the script
+ r = pakfire_execute_command(pakfire, command, envp, flags, logging_callback);
+ if (r) {
+ DEBUG(pakfire, "Script return code: %d\n", r);
+ }
+
+out:
+ // Remove script from disk
+ unlink(path);
+
+ // Cleanup
+ free(path);
+
+ return r;
+}
int flags, pakfire_execute_logging_callback logging_callback);
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);
enum {
PAKFIRE_EXECUTE_NONE = 0,
}
static int pakfire_step_run_shell_script(PakfireStep step, struct pakfire_scriptlet* scriptlet) {
- const char* root = pakfire_get_path(step->pakfire);
-
- // Write the scriptlet to disk
- char* path = pakfire_path_join(root, "tmp/.pakfire-scriptlet.XXXXXX");
- int r;
-
- DEBUG(step->pakfire, "Writing script to %s\n", path);
-
- // Open a temporary file
- int fd = mkstemp(path);
- if (fd < 0) {
- ERROR(step->pakfire, "Could not open a temporary file: %s\n",
- strerror(errno));
-
- r = errno;
- }
-
- // Write data
- ssize_t bytes_written = write(fd, scriptlet->data, scriptlet->size);
- if (bytes_written < (ssize_t)scriptlet->size) {
- ERROR(step->pakfire, "Could not write script to file %s: %s\n",
- path, strerror(errno));
-
- r = errno;
- goto out;
- }
-
- // Make the script executable
- r = fchmod(fd, S_IRUSR|S_IWUSR|S_IXUSR);
- if (r) {
- ERROR(step->pakfire, "Could not set executable permissions on %s: %s\n",
- path, strerror(errno));
-
- r = errno;
- goto out;
- }
-
- // Close file
- r = close(fd);
- if (r) {
- ERROR(step->pakfire, "Could not close script file %s: %s\n",
- path, strerror(errno));
-
- r = errno;
- goto out;
- }
-
- const char* command = path;
- if (root)
- command = pakfire_path_relpath(root, path);
-
- // Run the script
- r = pakfire_execute_command(step->pakfire, command, NULL, 0, NULL);
- if (r) {
- DEBUG(step->pakfire, "Script return code: %d\n", r);
- }
-
-out:
- // Remove script from disk
- unlink(path);
-
- // Cleanup
- free(path);
-
- return r;
+ return pakfire_execute_script(step->pakfire, scriptlet->data, scriptlet->size, NULL, 0, NULL);
}
static int pakfire_step_run_script(PakfireStep step,