]>
Commit | Line | Data |
---|---|---|
b792d887 MT |
1 | /*############################################################################# |
2 | # # | |
3 | # Pakfire - The IPFire package management system # | |
4 | # Copyright (C) 2011 Pakfire development team # | |
5 | # # | |
6 | # This program is free software: you can redistribute it and/or modify # | |
7 | # it under the terms of the GNU General Public License as published by # | |
8 | # the Free Software Foundation, either version 3 of the License, or # | |
9 | # (at your option) any later version. # | |
10 | # # | |
11 | # This program is distributed in the hope that it will be useful, # | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
14 | # GNU General Public License for more details. # | |
15 | # # | |
16 | # You should have received a copy of the GNU General Public License # | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
18 | # # | |
19 | #############################################################################*/ | |
102c5ee7 | 20 | |
392371f7 MT |
21 | #ifndef _GNU_SOURCE |
22 | #define _GNU_SOURCE | |
23 | #endif | |
24 | ||
102c5ee7 MT |
25 | #include <Python.h> |
26 | ||
392371f7 MT |
27 | #include <errno.h> |
28 | #include <sched.h> | |
ed4a9455 | 29 | #include <sys/personality.h> |
92aef532 | 30 | #include <unistd.h> |
ed4a9455 | 31 | |
392371f7 | 32 | #include "config.h" |
102c5ee7 MT |
33 | #include "util.h" |
34 | ||
ed4a9455 MT |
35 | PyObject *_personality(PyObject *self, PyObject *args) { |
36 | unsigned long persona; | |
37 | int ret = 0; | |
38 | ||
39 | if (!PyArg_ParseTuple(args, "l", &persona)) { | |
40 | /* XXX raise exception */ | |
41 | return NULL; | |
42 | } | |
43 | ||
44 | /* Change personality here. */ | |
45 | ret = personality(persona); | |
46 | ||
47 | if (ret < 0) { | |
48 | PyErr_SetString(PyExc_RuntimeError, "Could not set personality."); | |
49 | return NULL; | |
50 | } | |
51 | ||
52 | return Py_BuildValue("i", ret); | |
53 | } | |
54 | ||
92aef532 MT |
55 | PyObject *_sync(PyObject *self, PyObject *args) { |
56 | /* Just sync everything to disks. */ | |
57 | sync(); | |
58 | ||
59 | Py_RETURN_NONE; | |
60 | } | |
61 | ||
392371f7 MT |
62 | PyObject *_unshare(PyObject *self, PyObject *args) { |
63 | int flags = 0; | |
64 | ||
65 | if (!PyArg_ParseTuple(args, "i", &flags)) { | |
66 | return NULL; | |
67 | } | |
68 | ||
69 | int ret = unshare(flags); | |
70 | if (ret < 0) { | |
71 | return PyErr_SetFromErrno(PyExc_RuntimeError); | |
72 | } | |
73 | ||
74 | return Py_BuildValue("i", ret); | |
75 | } | |
76 | ||
102c5ee7 MT |
77 | PyObject *version_compare(PyObject *self, PyObject *args) { |
78 | Pool *pool; | |
79 | const char *evr1, *evr2; | |
80 | ||
81 | if (!PyArg_ParseTuple(args, "Oss", &pool, &evr1, &evr2)) { | |
82 | /* XXX raise exception */ | |
83 | return NULL; | |
84 | } | |
85 | ||
86 | int ret = pool_evrcmp_str(pool, evr1, evr2, EVRCMP_COMPARE); | |
87 | ||
88 | return Py_BuildValue("i", ret); | |
89 | } |