From: Michael Tremer Date: Tue, 2 Aug 2022 08:01:46 +0000 (+0000) Subject: jail: Add basic type X-Git-Tag: 0.9.28~648 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd37ccaf894a2261905082408d7681d925f0b4ad;p=pakfire.git jail: Add basic type The goal is to split execute.c into a more flexible API. Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 31d89fe1f..5b10ba5ce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 000000000..d2c45dc49 --- /dev/null +++ b/src/libpakfire/include/pakfire/jail.h @@ -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 . # +# # +#############################################################################*/ + +#ifndef PAKFIRE_JAIL_H +#define PAKFIRE_JAIL_H + +#ifdef PAKFIRE_PRIVATE + +#include + +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 index 000000000..6447a9045 --- /dev/null +++ b/src/libpakfire/jail.c @@ -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 . # +# # +#############################################################################*/ + +#include +#include + +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; +}