stdlib.h \
string.h \
syslog.h \
+ sys/personality.h \
sys/stat.h \
unistd.h
])
AC_CHECK_FUNCS([ \
assert \
+ personality \
secure_getenv \
strcmp \
strdup
#include <libintl.h>
#include <locale.h>
#include <sched.h>
-#include <sys/personality.h>
#include <solv/solver.h>
{"performance_index", (PyCFunction)performance_index, METH_VARARGS, NULL},
{"version_compare", (PyCFunction)version_compare, METH_VARARGS, NULL},
{"get_capabilities", (PyCFunction)get_capabilities, METH_VARARGS, NULL},
- {"personality", (PyCFunction)_personality, METH_VARARGS, NULL},
{"sync", (PyCFunction)_sync, METH_NOARGS, NULL},
{"unshare", (PyCFunction)_unshare, METH_VARARGS, NULL},
{"native_arch", (PyCFunction)_pakfire_native_arch, METH_NOARGS, NULL },
// Add constants
PyObject* d = PyModule_GetDict(module);
- // Personalities
- PyDict_SetItemString(d, "PERSONALITY_LINUX", Py_BuildValue("i", PER_LINUX));
- PyDict_SetItemString(d, "PERSONALITY_LINUX32", Py_BuildValue("i", PER_LINUX32));
-
// Namespace stuff
PyDict_SetItemString(d, "SCHED_CLONE_NEWIPC", Py_BuildValue("i", CLONE_NEWIPC));
PyDict_SetItemString(d, "SCHED_CLONE_NEWPID", Py_BuildValue("i", CLONE_NEWPID));
#include <errno.h>
#include <sched.h>
-#include <sys/personality.h>
#include <time.h>
#include <unistd.h>
#include "package.h"
#include "util.h"
-PyObject *_personality(PyObject *self, PyObject *args) {
- unsigned long persona;
- int ret = 0;
-
- if (!PyArg_ParseTuple(args, "l", &persona)) {
- /* XXX raise exception */
- return NULL;
- }
-
- /* Change personality here. */
- ret = personality(persona);
-
- if (ret < 0) {
- PyErr_SetString(PyExc_RuntimeError, "Could not set personality.");
- return NULL;
- }
-
- return Py_BuildValue("i", ret);
-}
-
PyObject *_sync(PyObject *self, PyObject *args) {
/* Just sync everything to disks. */
sync();
#include "pakfire.h"
-extern PyObject *_personality(PyObject *self, PyObject *args);
extern PyObject *_sync(PyObject *self, PyObject *args);
extern PyObject *_unshare(PyObject *self, PyObject *args);
extern PyObject *version_compare(PyObject *self, PyObject *args);
#include <stddef.h>
#include <stdio.h>
#include <string.h>
+#include <sys/personality.h>
#include <sys/utsname.h>
#include <pakfire/arch.h>
const char* name;
const char* platform;
const char* compatible[5];
+ unsigned long personality;
};
static const struct pakfire_arch PAKFIRE_ARCHES[] = {
.name = "x86_64",
.platform = "x86",
.compatible = { "i686", NULL },
+ .personality = PER_LINUX,
},
{
.name = "i686",
.platform = "x86",
+ .personality = PER_LINUX32,
},
// ARM
{
.name = "aarch64",
.platform = "arm",
+ .personality = PER_LINUX,
},
{
.name = "armv7hl",
.platform = "arm",
.compatible = { "armv7l", "armv6l", "armv5tejl", "armv5tel", NULL },
+ .personality = PER_LINUX32,
},
{
.name = "armv7l",
.platform = "arm",
.compatible = { "armv6l", "armv5tejl", "armv5tel", NULL },
+ .personality = PER_LINUX32,
},
{
.name = "armv6l",
.platform = "arm",
.compatible = { "armv5tejl", "armv5tel", NULL },
+ .personality = PER_LINUX32,
},
{
.name = "armv5tejl",
.platform = "arm",
.compatible = { "armv5tel", NULL },
+ .personality = PER_LINUX32,
},
{
.name = "armv5tel",
.platform = "arm",
+ .personality = PER_LINUX32,
},
};
return NULL;
}
+PAKFIRE_EXPORT unsigned long pakfire_arch_personality(const char* name) {
+ const struct pakfire_arch* arch = pakfire_arch_find(name);
+
+ if (arch)
+ return arch->personality;
+
+ return 0;
+}
+
PAKFIRE_EXPORT char* pakfire_arch_machine(const char* arch, const char* vendor) {
if (!vendor)
vendor = "unknown";
#include <errno.h>
#include <sched.h>
#include <stdlib.h>
+#include <sys/personality.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
+#include <pakfire/arch.h>
#include <pakfire/execute.h>
#include <pakfire/logging.h>
#include <pakfire/private.h>
static int pakfire_execute_fork(Pakfire pakfire, struct pakfire_execute_env* env) {
pid_t pid = getpid();
+ // Get architecture
+ const char* arch = pakfire_get_arch(pakfire);
+
DEBUG(env->pakfire, "Execution environment has been forked as PID %d\n", pid);
DEBUG(env->pakfire, " command = %s, root = %s\n", env->command, env->root);
return errno;
}
+ // Set personality
+ unsigned long persona = pakfire_arch_personality(arch);
+ r = personality(persona);
+ if (r < 0) {
+ ERROR(env->pakfire, "Could not set personality (%x)\n", persona);
+
+ return errno;
+ }
+
// exec() command
r = execve(env->command, (char**)env->argv, (char**)env->envp);
int pakfire_arch_supported(const char* name);
const char* pakfire_arch_platform(const char* name);
+unsigned long pakfire_arch_personality(const char* name);
char* pakfire_arch_machine(const char* arch, const char* vendor);
const char* pakfire_arch_native();
int pakfire_arch_is_compatible(const char* name, const char* compatible_arch);
pakfire_arch_is_compatible;
pakfire_arch_machine;
pakfire_arch_native;
+ pakfire_arch_personality;
pakfire_arch_platform;
pakfire_arch_supported;
pakfire_arch_supported_by_host;
command = "/usr/sbin/chroot %s %s %s" % (self.chrootPath(), SHELL_SCRIPT)
- # Add personality if we require one
- if self.pakfire.distro.personality:
- command = "%s %s" % (self.pakfire.distro.personality, command)
-
for key, val in list(self.environ.items()):
command = "%s=\"%s\" " % (key, val) + command
import subprocess
import time
-from ._pakfire import PERSONALITY_LINUX, PERSONALITY_LINUX32
-
from pakfire.i18n import _
import pakfire.util as util
from .errors import *
class ShellExecuteEnvironment(object):
- def __init__(self, command, cwd=None, chroot_path=None, personality=None, shell=False, timeout=0, env=None,
+ def __init__(self, command, cwd=None, chroot_path=None, shell=False, timeout=0, env=None,
cgroup=None, logger=None, log_output=True, log_errors=True, record_output=False, record_stdout=True, record_stderr=True):
# The given command that should be executed.
self.command = command
# Set timeout.
self.timeout = timeout
- # Personality.
- self.personality = personality
-
# Shell.
self.shell = shell
self.env = env
def create_subprocess(self):
# Create preexecution thingy for command
- preexec_fn = ChildPreExec(self.personality, self.chroot_path, self.cwd)
+ preexec_fn = ChildPreExec(self.chroot_path, self.cwd)
kwargs = {
"bufsize" : 0,
class ChildPreExec(object):
- def __init__(self, personality, chroot_path, cwd):
- self._personality = personality
+ def __init__(self, chroot_path, cwd):
self.chroot_path = chroot_path
self.cwd = cwd
- @property
- def personality(self):
- """
- Return personality value if supported.
- Otherwise return None.
- """
- personality_defs = {
- "linux64": PERSONALITY_LINUX,
- "linux32": PERSONALITY_LINUX32,
- }
-
- try:
- return personality_defs[self._personality]
- except KeyError:
- pass
-
def __call__(self, *args, **kargs):
# Set a new process group
os.setpgrp()
- # Set new personality if we got one.
- if self.personality:
- util.personality(self.personality)
-
# Change into new root.
if self.chroot_path:
os.chdir(self.chroot_path)
from .i18n import _
# Import binary version of capability functions
-from ._pakfire import get_capabilities, personality
+from ._pakfire import get_capabilities
def cli_is_interactive():
"""