int flags = 0;
int r;
PyObject* ret = NULL;
- char** buffer = NULL;
char* output = NULL;
PyObject* command = NULL;
}
// Execute command
- r = pakfire_jail_exec(jail, argv, (return_output) ? &buffer : NULL);
+ r = pakfire_jail_exec(jail, argv, (return_output) ? &output : NULL);
// If the return code was negative, we had some internal error
if (r < 0) {
// Did the user request the output?
if (return_output) {
- size_t length = 0;
-
- // Join everything together into a long string
- if (buffer) {
- output = pakfire_jail_concat_output(jail, (const char**)buffer, &length);
- if (!output) {
- PyErr_SetFromErrno(PyExc_OSError);
- goto ERROR;
- }
- }
-
// Return the buffer as bytes
- ret = PyBytes_FromStringAndSize(output, length);
+ ret = PyBytes_FromString(output);
// Otherwise just return None
} else {
ERROR:
if (argv)
free(argv);
- if (buffer) {
- for (char** line = buffer; *line; line++) {
- free(*line);
- }
- free(buffer);
- }
if (output)
free(output);
"exit 0\n"
static int pakfire_build_run_script(struct pakfire_build* build, const char* filename,
- const char* args[], char*** output) {
+ const char* args[], char** output) {
char* script = NULL;
size_t size = 0;
char path[PATH_MAX];
static int pakfire_build_find_dependencies(struct pakfire_build* build,
struct pakfire_package* pkg, struct pakfire_filelist* filelist, const char* buildroot) {
- char** provides = NULL;
- char** requires = NULL;
+ char* provides = NULL;
+ char* requires = NULL;
char path[PATH_MAX];
// Allocate path to write the filelist to
goto ERROR;
}
+#warning TODO parse dependencies
+#if 0
// Add all provides to the package
if (provides) {
for (char** element = provides; *element; element++) {
pakfire_package_add_requires(pkg, *element);
}
}
+#endif
// Success
r = 0;
ERROR:
- if (provides) {
- for (char** element = provides; *element; element++)
- free(*element);
+ if (provides)
free(provides);
- }
- if (requires) {
- for (char** element = requires; *element; element++)
- free(*element);
+ if (requires)
free(requires);
- }
unlink(path);
return r;
static int pakfire_build_add_scriptlet_requires(struct pakfire_build* build,
struct pakfire_package* pkg, struct pakfire_scriptlet* scriptlet) {
- char** prerequires = NULL;
+ char* prerequires = NULL;
char path[PATH_MAX];
size_t size;
int r;
goto ERROR;
// Add all pre-requires to the package
+#warning TODO parse dependenices
+#if 0
if (prerequires) {
for (char** element = prerequires; *element; element++) {
DEBUG(build->pakfire, "Adding pre-requires: %s\n", *element);
pakfire_package_add_prerequires(pkg, *element);
}
}
+#endif
ERROR:
if (r && *path)
unlink(path);
- if (prerequires) {
- for (char** element = prerequires; *element; element++)
- free(*element);
+ if (prerequires)
free(prerequires);
- }
return r;
}
int pakfire_jail_import_env(struct pakfire_jail* jail, const char* env[]);
// Execute
-int pakfire_jail_exec(struct pakfire_jail* jail, const char* argv[], char*** output);
+int pakfire_jail_exec(struct pakfire_jail* jail, const char* argv[], char** output);
int pakfire_jail_exec_script(struct pakfire_jail* jail,
- const char* script, const size_t size, const char* args[], char*** output);
-
-// Utility functions
-char* pakfire_jail_concat_output(struct pakfire_jail* jail,
- const char** input, size_t* length);
+ const char* script, const size_t size, const char* args[], char** output);
#ifdef PAKFIRE_PRIVATE
int pakfire_jail_set_cgroup(struct pakfire_jail* jail, struct pakfire_cgroup* cgroup);
// Convenience functions
-int pakfire_jail_run(struct pakfire* pakfire, const char* argv[], int flags, char*** output);
+int pakfire_jail_run(struct pakfire* pakfire, const char* argv[], int flags, char** output);
int pakfire_jail_run_script(struct pakfire* pakfire,
- const char* script, const size_t length, const char* argv[], int flags, char*** output);
+ const char* script, const size_t length, const char* argv[], int flags, char** output);
int pakfire_jail_shell(struct pakfire* pakfire);
int pakfire_jail_ldconfig(struct pakfire* pakfire);
static int pakfire_jail_capture_stdout(struct pakfire* pakfire, void* data, int priority,
const char* line, size_t length) {
- char*** array = (char***)data;
+ char** output = (char**)data;
+ int r;
- // Append everything from stdout to an array
+ // Append everything from stdout to a buffer
if (priority == LOG_INFO) {
- length = 0;
-
- // Create a copy of line
- char* message = strdup(line);
- if (!message)
+ r = asprintf(output, "%s%s", (output && *output) ? *output : "", line);
+ if (r < 0)
return 1;
-
- // Determine the length of the existing array
- if (*array) {
- for (char** element = *array; *element; element++)
- length++;
- }
-
- // Allocate space
- *array = reallocarray(*array, length + 2, sizeof(**array));
- if (!*array)
- return 1;
-
- // Append message and terminate the array
- (*array)[length] = message;
- (*array)[length + 1] = NULL;
-
return 0;
}
}
PAKFIRE_EXPORT int pakfire_jail_exec(struct pakfire_jail* jail,
- const char* argv[], char*** output) {
+ const char* argv[], char** output) {
int r;
// Store logging callback
}
PAKFIRE_EXPORT int pakfire_jail_exec_script(struct pakfire_jail* jail,
- const char* script, const size_t size, const char* args[], char*** output) {
+ const char* script, const size_t size, const char* args[], char** output) {
char path[PATH_MAX];
const char** argv = NULL;
int r;
A convenience function that creates a new jail, runs the given command and destroys
the jail again.
*/
-int pakfire_jail_run(struct pakfire* pakfire, const char* argv[], int flags, char*** output) {
+int pakfire_jail_run(struct pakfire* pakfire, const char* argv[], int flags, char** output) {
struct pakfire_jail* jail = NULL;
int r;
}
int pakfire_jail_run_script(struct pakfire* pakfire,
- const char* script, const size_t length, const char* argv[], int flags, char*** output) {
+ const char* script, const size_t length, const char* argv[], int flags, char** output) {
struct pakfire_jail* jail = NULL;
int r;
// Run ldconfig
return pakfire_jail_run(pakfire, argv, 0, NULL);
}
-
-// Utility functions
-
-PAKFIRE_EXPORT char* pakfire_jail_concat_output(struct pakfire_jail* jail,
- const char** input, size_t* length) {
- // Return nothing on no input
- if (!input)
- return NULL;
-
- // XXX Maybe there is a more efficient way to do this
-
- char* output = pakfire_string_join((char**)input, "");
- if (!output)
- return NULL;
-
- // Store the length of the result
- if (length)
- *length = strlen(output);
-
- return output;
-}
pakfire_key_unref;
# jail
- pakfire_jail_concat_output;
pakfire_jail_create;
pakfire_jail_exec;
pakfire_jail_exec_script;
static int test_nice(const struct test* t) {
struct pakfire_jail* jail = NULL;
- char** output = NULL;
+ char* output = NULL;
int r = EXIT_FAILURE;
const char* argv[] = {
"/command", "print-nice", NULL,
};
- char* expected_output[] = {
- "5\n", NULL,
- };
-
// Create a new jail
ASSERT_SUCCESS(pakfire_jail_create(&jail, t->pakfire, 0));
// Set something sane
ASSERT_SUCCESS(pakfire_jail_nice(jail, 5));
+ // Check if the nice level has been set
ASSERT_SUCCESS(pakfire_jail_exec(jail, argv, &output));
- ASSERT_STRING_ARRAY_EQUALS(output, expected_output);
+ ASSERT_STRING_EQUALS(output, "5\n");
// Success
r = EXIT_SUCCESS;
FAIL:
if (jail)
pakfire_jail_unref(jail);
- if (output) {
- for (char** line = output; *line; line++)
- free(*line);
+ if (output)
free(output);
- }
return r;
}