From 980ccfe643cae88f3fa46f4b13d73a665ef78194 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 28 Nov 2017 19:31:05 +0100 Subject: [PATCH] libpakfire: Automatically detect system architecture Signed-off-by: Michael Tremer --- Makefile.am | 2 ++ src/_pakfire/pakfire.c | 2 +- src/libpakfire/include/pakfire/system.h | 26 +++++++++++++++ src/libpakfire/pakfire.c | 4 +++ src/libpakfire/system.c | 42 +++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/libpakfire/include/pakfire/system.h create mode 100644 src/libpakfire/system.c diff --git a/Makefile.am b/Makefile.am index 282e76861..fa524580e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -258,6 +258,7 @@ libpakfire_la_SOURCES = \ src/libpakfire/solution.c \ src/libpakfire/solver.c \ src/libpakfire/step.c \ + src/libpakfire/system.c \ src/libpakfire/transaction.c \ src/libpakfire/util.c @@ -285,6 +286,7 @@ pkginclude_HEADERS += \ src/libpakfire/include/pakfire/solution.h \ src/libpakfire/include/pakfire/solver.h \ src/libpakfire/include/pakfire/step.h \ + src/libpakfire/include/pakfire/system.h \ src/libpakfire/include/pakfire/transaction.h \ src/libpakfire/include/pakfire/types.h \ src/libpakfire/include/pakfire/util.h diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 2b45a0799..bdcc3a92b 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -39,7 +39,7 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { const char* path = NULL; const char* arch = NULL; - if (!PyArg_ParseTuple(args, "ss", &path, &arch)) + if (!PyArg_ParseTuple(args, "s|s", &path, &arch)) return -1; self->pakfire = pakfire_create(path, arch); diff --git a/src/libpakfire/include/pakfire/system.h b/src/libpakfire/include/pakfire/system.h new file mode 100644 index 000000000..d7137143e --- /dev/null +++ b/src/libpakfire/include/pakfire/system.h @@ -0,0 +1,26 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2017 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_SYSTEM_H +#define PAKFIRE_SYSTEM_H + +const char* system_machine(); + +#endif /* PAKFIRE_SYSTEM_H */ diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 3c38df967..7552055ae 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -29,6 +30,9 @@ Pakfire pakfire_create(const char* path, const char* arch) { pakfire->nrefs = 1; pakfire->path = pakfire_strdup(path); + if (!arch) { + arch = system_machine(); + } pakfire->arch = pakfire_strdup(arch); // Initialize the pool diff --git a/src/libpakfire/system.c b/src/libpakfire/system.c new file mode 100644 index 000000000..cc0b9d2f3 --- /dev/null +++ b/src/libpakfire/system.c @@ -0,0 +1,42 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2017 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 + +#include +#include +#include + +const char* system_machine() { + static char __system_machine[STRING_SIZE] = ""; + + if (!*__system_machine) { + struct utsname buf; + + int r = uname(&buf); + if (!r) + return NULL; + + strncpy(__system_machine, buf.machine, sizeof(*__system_machine)); + } + + return __system_machine; +} -- 2.39.5