]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
jail: Add basic type
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 2 Aug 2022 08:01:46 +0000 (08:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 2 Aug 2022 08:01:46 +0000 (08:01 +0000)
The goal is to split execute.c into a more flexible API.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/libpakfire/include/pakfire/jail.h [new file with mode: 0644]
src/libpakfire/jail.c [new file with mode: 0644]

index 31d89fe1fe6c2dc5154ed410018fdee029462468..5b10ba5cec25bc028d2d7358702f11b99537e2a0 100644 (file)
@@ -228,6 +228,7 @@ libpakfire_la_SOURCES = \
        src/libpakfire/execute.c \
        src/libpakfire/file.c \
        src/libpakfire/filelist.c \
+       src/libpakfire/jail.c \
        src/libpakfire/key.c \
        src/libpakfire/keystore.c \
        src/libpakfire/logging.c \
@@ -265,6 +266,7 @@ pkginclude_HEADERS += \
        src/libpakfire/include/pakfire/file.h \
        src/libpakfire/include/pakfire/filelist.h \
        src/libpakfire/include/pakfire/i18n.h \
+       src/libpakfire/include/pakfire/jail.h \
        src/libpakfire/include/pakfire/key.h \
        src/libpakfire/include/pakfire/keystore.h \
        src/libpakfire/include/pakfire/logging.h \
diff --git a/src/libpakfire/include/pakfire/jail.h b/src/libpakfire/include/pakfire/jail.h
new file mode 100644 (file)
index 0000000..d2c45dc
--- /dev/null
@@ -0,0 +1,37 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2022 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef PAKFIRE_JAIL_H
+#define PAKFIRE_JAIL_H
+
+#ifdef PAKFIRE_PRIVATE
+
+#include <pakfire/pakfire.h>
+
+struct pakfire_jail;
+
+int pakfire_jail_create(struct pakfire_jail** jail, struct pakfire* pakfire);
+
+struct pakfire_jail* pakfire_jail_ref(struct pakfire_jail* jail);
+struct pakfire_jail* pakfire_jail_unref(struct pakfire_jail* jail);
+
+#endif
+
+#endif /* PAKFIRE_JAIL_H */
diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c
new file mode 100644 (file)
index 0000000..6447a90
--- /dev/null
@@ -0,0 +1,62 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2022 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <pakfire/jail.h>
+#include <pakfire/pakfire.h>
+
+struct pakfire_jail {
+       struct pakfire* pakfire;
+       int nrefs;
+};
+
+int pakfire_jail_create(struct pakfire_jail** jail, struct pakfire* pakfire) {
+       struct pakfire_jail* j = calloc(1, sizeof(*j));
+       if (!j)
+               return 1;
+
+       // Reference Pakfire
+       j->pakfire = pakfire_ref(pakfire);
+
+       // Initialize reference counter
+       j->nrefs = 1;
+
+       // Done
+       *jail = j;
+       return 0;
+}
+
+static void pakfire_jail_free(struct pakfire_jail* jail) {
+       pakfire_unref(jail->pakfire);
+       free(jail);
+}
+
+struct pakfire_jail* pakfire_jail_ref(struct pakfire_jail* jail) {
+       ++jail->nrefs;
+
+       return jail;
+}
+
+struct pakfire_jail* pakfire_jail_unref(struct pakfire_jail* jail) {
+       if (--jail->nrefs > 0)
+               return jail;
+
+       pakfire_jail_free(jail);
+       return NULL;
+}