char* kwlist[] = {
"command",
"environ",
+ "bind",
"interactive",
"logging_callback",
"nice",
PyObject* command = NULL;
PyObject* environ = NULL;
+ PyObject* bind = NULL;
int interactive = 0;
PyObject* logging_callback = NULL;
int nice = 0;
int return_output = 0;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OpOip", kwlist, &command, &environ,
- &interactive, &logging_callback, &nice, &return_output))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OOpOip", kwlist, &command, &environ,
+ &bind, &interactive, &logging_callback, &nice, &return_output))
return NULL;
// Check if command is a list
argv[i] = PyUnicode_AsUTF8(item);
}
+ // Check if bind is a sequence
+ if (bind && !PySequence_Check(bind)) {
+ PyErr_SetString(PyExc_ValueError, "bind is not a sequence");
+ goto ERROR;
+ }
+
// Interactive?
if (interactive)
flags |= PAKFIRE_JAIL_INTERACTIVE;
}
}
+ const Py_ssize_t num_bind = PySequence_Length(bind);
+
+ // Bind
+ for (unsigned int i = 0; i < num_bind; i++) {
+ PyObject* b = PySequence_ITEM(bind, i);
+ if (!b)
+ goto ERROR;
+
+ // Check if this is a Unicode object
+ if (!PyUnicode_Check(b)) {
+ PyErr_SetString(PyExc_ValueError, "bind contains a non-Unicode object");
+ Py_DECREF(b);
+ goto ERROR;
+ }
+
+ const char* path = PyUnicode_AsUTF8(b);
+
+ // Perform bind
+ r = pakfire_jail_bind(jail, path, path, 0);
+ if (r) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ Py_DECREF(b);
+ goto ERROR;
+ }
+
+ Py_DECREF(b);
+ }
+
// Execute command
r = pakfire_jail_exec(jail, argv, (return_output) ? &output : NULL);
return ret;
}
-static PyObject* Pakfire_bind(PakfireObject* self, PyObject* args) {
- const char* src = NULL;
- const char* dst = NULL;
-
- if (!PyArg_ParseTuple(args, "s|z", &src, &dst))
- return NULL;
-
- int r = pakfire_bind(self->pakfire, src, dst, 0);
- if (r) {
- PyErr_SetFromErrno(PyExc_OSError);
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
static PyObject* Pakfire_copy_in(PakfireObject* self, PyObject* args) {
const char* src = NULL;
const char* dst = NULL;
}
static struct PyMethodDef Pakfire_methods[] = {
- {
- "bind",
- (PyCFunction)Pakfire_bind,
- METH_VARARGS,
- NULL,
- },
{
"build",
(PyCFunction)Pakfire_build,
#include <pakfire/arch.h>
#include <pakfire/logging.h>
#include <pakfire/pakfire.h>
-#include <pakfire/private.h>
#include <pakfire/mount.h>
#include <pakfire/util.h>
return 0;
}
-PAKFIRE_EXPORT int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags) {
+int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags) {
struct stat st;
char mountpoint[PATH_MAX];
"""
Executes a command
"""
- # Bind-mount everything
- for bind in args.binds:
- p.bind(bind)
-
# Log everything to the console
def logging_callback(level, line):
if level >= logging.ERROR:
sys.stdout.write("%s\n" % line)
try:
- return p.execute(args.command,
+ return p.execute(args.command, bind=args.binds,
interactive=args.interactive, logging_callback=logging_callback)
# Exit program with the command's exit code