-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: #1177 Signed-off-by: Sohan Kunkerkar <[email protected]>
- Loading branch information
1 parent
7da99fb
commit 2ed1f0b
Showing
8 changed files
with
401 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/* | ||
* crun - OCI runtime written in C | ||
* | ||
* crun 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 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* crun 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 crun. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <config.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <argp.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
|
||
#include <yajl/yajl_tree.h> | ||
#include <yajl/yajl_gen.h> | ||
|
||
#include "crun.h" | ||
#include "libcrun/container.h" | ||
#include "libcrun/utils.h" | ||
|
||
static char doc[] = "OCI runtime"; | ||
|
||
static struct argp_option options[] = { {0} }; | ||
|
||
static char args_doc[] = "features"; | ||
|
||
static error_t | ||
parse_opt (int key, char *arg arg_unused, struct argp_state *state arg_unused) | ||
{ | ||
if (key != ARGP_KEY_NO_ARGS) { | ||
return ARGP_ERR_UNKNOWN; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static struct argp run_argp = { options, parse_opt, args_doc, doc, NULL, NULL, NULL }; | ||
|
||
int crun_command_features(struct crun_global_arguments *global_args, int argc, char **argv, libcrun_error_t *err) { | ||
argp_parse(&run_argp, argc, argv, 0, 0, &options); | ||
|
||
// Call the function in features.c to gather the feature information | ||
struct features_info_s info; | ||
int result = libcrun_container_print_features(&info); | ||
if (result != 0) { | ||
libcrun_make_error(err, result, "Failed to gather features information."); | ||
return result; | ||
} | ||
|
||
// Prepare the JSON output | ||
yajl_gen jsonGen = yajl_gen_alloc(NULL); | ||
yajl_gen_status status; | ||
|
||
yajl_gen_config(jsonGen, yajl_gen_beautify, 1); // Optional: Enable pretty formatting | ||
|
||
// Start building the JSON | ||
yajl_gen_map_open(jsonGen); | ||
|
||
// Add ociVersionMin field | ||
yajl_gen_string(jsonGen, (const unsigned char *) "ociVersionMin", strlen("ociVersionMin")); | ||
yajl_gen_string(jsonGen, (const unsigned char *) info.ociVersionMin, strlen(info.ociVersionMin)); | ||
|
||
// Add ociVersionMax field | ||
yajl_gen_string(jsonGen, (const unsigned char *) "ociVersionMax", strlen("ociVersionMax")); | ||
yajl_gen_string(jsonGen, (const unsigned char *) info.ociVersionMax, strlen(info.ociVersionMax)); | ||
|
||
// Add hooks array | ||
yajl_gen_string(jsonGen, (const unsigned char *) "hooks", strlen("hooks")); | ||
yajl_gen_array_open(jsonGen); | ||
|
||
for (size_t i = 0; info.hooks[i] != NULL; i++) { | ||
yajl_gen_string(jsonGen, (const unsigned char *) info.hooks[i], strlen(info.hooks[i])); | ||
} | ||
|
||
yajl_gen_array_close(jsonGen); | ||
|
||
// Add mountOptions array | ||
yajl_gen_string(jsonGen, (const unsigned char *) "mountOptions", strlen("mountOptions")); | ||
yajl_gen_array_open(jsonGen); | ||
|
||
for (size_t i = 0; info.mountOptions[i] != NULL; i++) { | ||
yajl_gen_string(jsonGen, (const unsigned char *) info.mountOptions[i], strlen(info.mountOptions[i])); | ||
} | ||
|
||
yajl_gen_array_close(jsonGen); | ||
|
||
yajl_gen_string(jsonGen, (const unsigned char *) "linux", strlen("linux")); | ||
yajl_gen_map_open(jsonGen); | ||
|
||
// Add namespaces array | ||
yajl_gen_string(jsonGen, (const unsigned char *) "namespaces", strlen("namespaces")); | ||
yajl_gen_array_open(jsonGen); | ||
|
||
for (size_t i = 0; info.linux.namespaces[i] != NULL; i++) { | ||
yajl_gen_string(jsonGen, (const unsigned char *) info.linux.namespaces[i], strlen(info.linux.namespaces[i])); | ||
} | ||
|
||
yajl_gen_array_close(jsonGen); | ||
|
||
// Add capabilities array | ||
yajl_gen_string(jsonGen, (const unsigned char *) "capabilities", strlen("capabilities")); | ||
yajl_gen_array_open(jsonGen); | ||
|
||
for (size_t i = 0; info.linux.capabilities[i] != NULL; i++) { | ||
yajl_gen_string(jsonGen, (const unsigned char *) info.linux.capabilities[i], strlen(info.linux.capabilities[i])); | ||
} | ||
|
||
yajl_gen_array_close(jsonGen); | ||
|
||
// Generate the "cgroup" field | ||
yajl_gen_string(jsonGen, (const unsigned char *) "cgroup", strlen("cgroup")); | ||
yajl_gen_map_open(jsonGen); | ||
|
||
// Generate the "v1" field | ||
yajl_gen_string(jsonGen, (const unsigned char *) "v1", strlen("v1")); | ||
yajl_gen_bool(jsonGen, info.linux.cgroup.v1); | ||
|
||
// Generate the "v2" field | ||
yajl_gen_string(jsonGen, (const unsigned char *) "v2", strlen("v2")); | ||
yajl_gen_bool(jsonGen, info.linux.cgroup.v2); | ||
|
||
// Generate the "systemd" field | ||
yajl_gen_string(jsonGen, (const unsigned char *) "systemd", strlen("systemd")); | ||
yajl_gen_bool(jsonGen, info.linux.cgroup.systemd); | ||
|
||
// Generate the "systemdUser" field | ||
yajl_gen_string(jsonGen, (const unsigned char *) "systemdUser", strlen("systemdUser")); | ||
yajl_gen_bool(jsonGen, info.linux.cgroup.systemdUser); | ||
|
||
yajl_gen_map_close(jsonGen); | ||
|
||
// Add seccomp field with TODO comment | ||
yajl_gen_string(jsonGen, (const unsigned char *) "seccomp", strlen("seccomp")); | ||
yajl_gen_map_open(jsonGen); | ||
|
||
yajl_gen_string(jsonGen, (const unsigned char *) "/* TODO: */", strlen("/* TODO: */")); | ||
|
||
yajl_gen_map_close(jsonGen); | ||
|
||
|
||
// Generate the "apparmor" field | ||
yajl_gen_string(jsonGen, (const unsigned char *) "apparmor", strlen("apparmor")); | ||
yajl_gen_map_open(jsonGen); | ||
|
||
// Generate the "enabled" field | ||
yajl_gen_string(jsonGen, (const unsigned char *) "enabled", strlen("enabled")); | ||
yajl_gen_bool(jsonGen, info.linux.apparmor.enabled); | ||
|
||
yajl_gen_map_close(jsonGen); | ||
|
||
// Generate the "selinux" field | ||
yajl_gen_string(jsonGen, (const unsigned char *) "selinux", strlen("selinux")); | ||
yajl_gen_map_open(jsonGen); | ||
|
||
// Generate the "enabled" field | ||
yajl_gen_string(jsonGen, (const unsigned char *) "enabled", strlen("enabled")); | ||
yajl_gen_bool(jsonGen, info.linux.selinux.enabled); | ||
|
||
yajl_gen_map_close(jsonGen); | ||
|
||
// End for linux build | ||
yajl_gen_map_close(jsonGen); | ||
|
||
// End building the JSON | ||
yajl_gen_map_close(jsonGen); | ||
|
||
// Get the JSON as a string | ||
const unsigned char *jsonString; | ||
size_t jsonLength; | ||
yajl_gen_get_buf(jsonGen, &jsonString, &jsonLength); | ||
|
||
// Print the JSON output to stdout | ||
printf("%s", (const char *)jsonString); | ||
|
||
// Clean up | ||
yajl_gen_free(jsonGen); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* crun - OCI runtime written in C | ||
* | ||
* Copyright (C) 2017, 2018, 2019 Giuseppe Scrivano <[email protected]> | ||
* crun 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 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* crun 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 crun. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#ifndef FEATURES_H | ||
#define FEATURES_H | ||
|
||
#include "crun.h" | ||
|
||
int crun_command_features (struct crun_global_arguments *global_args, int argc, char **argv, libcrun_error_t *error); | ||
|
||
#endif |
Oops, something went wrong.