From aa7facf08a5d4bc18f2d13510e4528699286c1de Mon Sep 17 00:00:00 2001 From: Krishna Chilleri Date: Sat, 16 Mar 2024 11:02:35 +0000 Subject: [PATCH 01/12] ch-run detects oci bundle path and runs it --- bin/ch-run.c | 6 ++++++ bin/ch_core.c | 13 +++++++++++-- bin/ch_core.h | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bin/ch-run.c b/bin/ch-run.c index a2a5e8afe..59dae3645 100644 --- a/bin/ch-run.c +++ b/bin/ch-run.c @@ -216,6 +216,12 @@ int main(int argc, char *argv[]) case IMG_NONE: FATAL("unknown image type: %s", args.c.img_ref); break; + case OCI_BUNDLE: + if (args.c.newroot != NULL) // --mount was set + WARNING("--mount invalid with directory image, ignoring"); + args.c.newroot = realpath_(cat(args.c.img_ref, "/rootfs"), false); + img_directory_verify(args.c.newroot, &args); + break; } if (args.c.join) { diff --git a/bin/ch_core.c b/bin/ch_core.c index cd25e2bd0..1b39fc486 100644 --- a/bin/ch_core.c +++ b/bin/ch_core.c @@ -370,6 +370,8 @@ enum img_type image_type(const char *ref, const char *storage_dir) struct stat st; FILE *fp; char magic[4]; // four bytes, not a string + char *conff = cat(ref, "/config.json"); + char *rootfs = cat(ref, "/rootfs"); // If there’s a directory in storage where we would expect there to be if // ref were an image name, assume it really is an image name. @@ -380,8 +382,15 @@ enum img_type image_type(const char *ref, const char *storage_dir) Zf (stat(ref, &st), "can't stat: %s", ref); // If ref is the path to a directory, then it’s a directory. - if (S_ISDIR(st.st_mode)) - return IMG_DIRECTORY; + // If ref is the path to a directory that contains rootfs directory + // and config.json file, assume it is an oci bundle + if (S_ISDIR(st.st_mode)) { + if (path_exists(rootfs, NULL, true) && path_exists(conff, NULL, true)) { + return OCI_BUNDLE; + } else { + return IMG_DIRECTORY; + } + } // Now we know it’s file-like enough to read. See if it has the SquashFS // magic number. diff --git a/bin/ch_core.h b/bin/ch_core.h index f65cfc083..8cb7ff0a3 100644 --- a/bin/ch_core.h +++ b/bin/ch_core.h @@ -25,6 +25,7 @@ enum img_type { IMG_SQUASH, // SquashFS archive file (not yet mounted) IMG_NAME, // name of image in storage IMG_NONE, // image type is not set yet + OCI_BUNDLE, // contains rootfs img_directory and config.json file }; struct container { From 9672bc41a70a1062d020445381cb8736c3b22708 Mon Sep 17 00:00:00 2001 From: Krishna Chilleri <149612138+kchilleri@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:47:33 -0600 Subject: [PATCH 02/12] remove extra spacing added after first commit --- bin/ch-run.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/ch-run.c b/bin/ch-run.c index 59dae3645..12129fb57 100644 --- a/bin/ch-run.c +++ b/bin/ch-run.c @@ -219,8 +219,8 @@ int main(int argc, char *argv[]) case OCI_BUNDLE: if (args.c.newroot != NULL) // --mount was set WARNING("--mount invalid with directory image, ignoring"); - args.c.newroot = realpath_(cat(args.c.img_ref, "/rootfs"), false); - img_directory_verify(args.c.newroot, &args); + args.c.newroot = realpath_(cat(args.c.img_ref, "/rootfs"), false); + img_directory_verify(args.c.newroot, &args); break; } From 0bb253153eea5e0b6c4f242dffced0fd23ffb1cd Mon Sep 17 00:00:00 2001 From: Krishna Chilleri <149612138+kchilleri@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:49:55 -0600 Subject: [PATCH 03/12] remove extra spacing added after first commit --- bin/ch_core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/ch_core.c b/bin/ch_core.c index 1b39fc486..6ddd87a40 100644 --- a/bin/ch_core.c +++ b/bin/ch_core.c @@ -385,11 +385,11 @@ enum img_type image_type(const char *ref, const char *storage_dir) // If ref is the path to a directory that contains rootfs directory // and config.json file, assume it is an oci bundle if (S_ISDIR(st.st_mode)) { - if (path_exists(rootfs, NULL, true) && path_exists(conff, NULL, true)) { - return OCI_BUNDLE; - } else { - return IMG_DIRECTORY; - } + if (path_exists(rootfs, NULL, true) && path_exists(conff, NULL, true)) { + return OCI_BUNDLE; + } else { + return IMG_DIRECTORY; + } } // Now we know it’s file-like enough to read. See if it has the SquashFS From e41480c4e931f92a140fdf59bf8434bf0d0d6bcd Mon Sep 17 00:00:00 2001 From: Krishna Chilleri <149612138+kchilleri@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:52:44 -0600 Subject: [PATCH 04/12] remove extra spacing added after first commit --- bin/ch-run.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/ch-run.c b/bin/ch-run.c index 12129fb57..365a23251 100644 --- a/bin/ch-run.c +++ b/bin/ch-run.c @@ -216,11 +216,11 @@ int main(int argc, char *argv[]) case IMG_NONE: FATAL("unknown image type: %s", args.c.img_ref); break; - case OCI_BUNDLE: - if (args.c.newroot != NULL) // --mount was set + case OCI_BUNDLE: + if (args.c.newroot != NULL) // --mount was set WARNING("--mount invalid with directory image, ignoring"); - args.c.newroot = realpath_(cat(args.c.img_ref, "/rootfs"), false); - img_directory_verify(args.c.newroot, &args); + args.c.newroot = realpath_(cat(args.c.img_ref, "/rootfs"), false); + img_directory_verify(args.c.newroot, &args); break; } From 30335955433e163ed10ba283d3767d7560fa0e0f Mon Sep 17 00:00:00 2001 From: Krishna Chilleri <149612138+kchilleri@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:11:01 -0600 Subject: [PATCH 05/12] Add Krishna to contributors section --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 0e6d8c311..2fdb1b692 100644 --- a/README.rst +++ b/README.rst @@ -56,6 +56,7 @@ Contributors: * Richard Berger * Lucas Caudill +* Krishna Chilleri * Rusty Davis * Hunter Easterday * Oliver Freyermuth From a1f6dd74c4463d3534fa15a473f4e297d984c0bc Mon Sep 17 00:00:00 2001 From: Krishna Chilleri Date: Tue, 30 Apr 2024 16:47:31 -0600 Subject: [PATCH 06/12] add json files for json parsing capability --- bin/ch-run.c | 13 +- bin/ch_core.c | 6 +- bin/ch_core.h | 2 +- bin/json.c | 1057 +++++++++++++++++++++++++++++++++++++++++++++++++ bin/json.h | 288 ++++++++++++++ 5 files changed, 1355 insertions(+), 11 deletions(-) create mode 100644 bin/json.c create mode 100644 bin/json.h diff --git a/bin/ch-run.c b/bin/ch-run.c index 365a23251..e061038c4 100644 --- a/bin/ch-run.c +++ b/bin/ch-run.c @@ -15,7 +15,7 @@ #include "config.h" #include "ch_core.h" #include "ch_misc.h" - +#include "json.h" /** Constants and macros **/ @@ -208,6 +208,11 @@ int main(int argc, char *argv[]) Tf (!args.c.writable || args.unsafe, "--write invalid when running by name"); break; + case IMG_OCI_BUNDLE: + /* Parse config.json file -> containerize */ + /* OR call ch-run-oci to create and start/run container */ + args.c.newroot = path_join(args.c.img_ref, "/rootfs"); + break; case IMG_SQUASH: #ifndef HAVE_LIBSQUASHFUSE FATAL("this ch-run does not support internal SquashFS mounts"); @@ -216,12 +221,6 @@ int main(int argc, char *argv[]) case IMG_NONE: FATAL("unknown image type: %s", args.c.img_ref); break; - case OCI_BUNDLE: - if (args.c.newroot != NULL) // --mount was set - WARNING("--mount invalid with directory image, ignoring"); - args.c.newroot = realpath_(cat(args.c.img_ref, "/rootfs"), false); - img_directory_verify(args.c.newroot, &args); - break; } if (args.c.join) { diff --git a/bin/ch_core.c b/bin/ch_core.c index 6ddd87a40..683551956 100644 --- a/bin/ch_core.c +++ b/bin/ch_core.c @@ -370,8 +370,8 @@ enum img_type image_type(const char *ref, const char *storage_dir) struct stat st; FILE *fp; char magic[4]; // four bytes, not a string - char *conff = cat(ref, "/config.json"); - char *rootfs = cat(ref, "/rootfs"); + char *conff = path_join(ref, "/config.json"); + char *rootfs = path_join(ref, "/rootfs"); // If there’s a directory in storage where we would expect there to be if // ref were an image name, assume it really is an image name. @@ -386,7 +386,7 @@ enum img_type image_type(const char *ref, const char *storage_dir) // and config.json file, assume it is an oci bundle if (S_ISDIR(st.st_mode)) { if (path_exists(rootfs, NULL, true) && path_exists(conff, NULL, true)) { - return OCI_BUNDLE; + return IMG_OCI_BUNDLE; } else { return IMG_DIRECTORY; } diff --git a/bin/ch_core.h b/bin/ch_core.h index 8cb7ff0a3..6a315f613 100644 --- a/bin/ch_core.h +++ b/bin/ch_core.h @@ -25,7 +25,7 @@ enum img_type { IMG_SQUASH, // SquashFS archive file (not yet mounted) IMG_NAME, // name of image in storage IMG_NONE, // image type is not set yet - OCI_BUNDLE, // contains rootfs img_directory and config.json file + IMG_OCI_BUNDLE, // contains rootfs img_directory and config.json file }; struct container { diff --git a/bin/json.c b/bin/json.c new file mode 100644 index 000000000..deef49ff3 --- /dev/null +++ b/bin/json.c @@ -0,0 +1,1057 @@ +/* vim: set et ts=3 sw=3 sts=3 ft=c: + * + * Copyright (C) 2012-2021 the json-parser authors All rights reserved. + * https://github.com/json-parser/json-parser + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "json.h" + +#ifdef _MSC_VER + #ifndef _CRT_SECURE_NO_WARNINGS + #define _CRT_SECURE_NO_WARNINGS + #endif +#endif + +#include +#include +#include +#include +#include +#include + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + /* C99 might give us uintptr_t and UINTPTR_MAX but they also might not be provided */ + #include +#endif + +#ifndef JSON_INT_T_OVERRIDDEN + #if defined(_MSC_VER) + /* https://docs.microsoft.com/en-us/cpp/cpp/data-type-ranges */ + #define JSON_INT_MAX 9223372036854775807LL + #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + /* C99 */ + #define JSON_INT_MAX INT_FAST64_MAX + #else + /* C89 */ + #include + #define JSON_INT_MAX LONG_MAX + #endif +#endif + +#ifndef JSON_INT_MAX +#define JSON_INT_MAX (json_int_t)(((unsigned json_int_t)(-1)) / (unsigned json_int_t)2); +#endif + +typedef unsigned int json_uchar; + +const struct _json_value json_value_none; + +static unsigned char hex_value (json_char c) +{ + if (isdigit((unsigned char)c)) + return c - '0'; + + switch (c) { + case 'a': case 'A': return 0x0A; + case 'b': case 'B': return 0x0B; + case 'c': case 'C': return 0x0C; + case 'd': case 'D': return 0x0D; + case 'e': case 'E': return 0x0E; + case 'f': case 'F': return 0x0F; + default: return 0xFF; + } +} + +static int would_overflow (json_int_t value, json_char b) +{ + return ((JSON_INT_MAX - (b - '0')) / 10 ) < value; +} + +typedef struct +{ + size_t used_memory; + + json_settings settings; + int first_pass; + + const json_char * ptr; + unsigned int cur_line, cur_col; + +} json_state; + +static void * default_alloc (size_t size, int zero, void * user_data) +{ + (void)user_data; /* ignore unused-parameter warn */ + return zero ? calloc (1, size) : malloc (size); +} + +static void default_free (void * ptr, void * user_data) +{ + (void)user_data; /* ignore unused-parameter warn */ + free (ptr); +} + +static void * json_alloc (json_state * state, size_t size, int zero) +{ + if ((ULONG_MAX - 8 - state->used_memory) < size) + return 0; + + if (state->settings.max_memory + && (state->used_memory += size) > state->settings.max_memory) + { + return 0; + } + + return state->settings.mem_alloc (size, zero, state->settings.user_data); +} + +static int new_value (json_state * state, + json_value ** top, json_value ** root, json_value ** alloc, + json_type type) +{ + json_value * value; + size_t values_size; + + if (!state->first_pass) + { + value = *top = *alloc; + *alloc = (*alloc)->_reserved.next_alloc; + + if (!*root) + *root = value; + + switch (value->type) + { + case json_array: + + if (value->u.array.length == 0) + break; + + if (! (value->u.array.values = (json_value **) json_alloc + (state, value->u.array.length * sizeof (json_value *), 0)) ) + { + return 0; + } + + value->u.array.length = 0; + break; + + case json_object: + + if (value->u.object.length == 0) + break; + + values_size = sizeof (*value->u.object.values) * value->u.object.length; + + if (! (value->u.object.values = (json_object_entry *) json_alloc + #ifdef UINTPTR_MAX + (state, values_size + ((uintptr_t) value->u.object.values), 0)) ) + #else + (state, values_size + ((size_t) value->u.object.values), 0)) ) + #endif + { + return 0; + } + + value->_reserved.object_mem = (void *) (((char *) value->u.object.values) + values_size); + + value->u.object.length = 0; + break; + + case json_string: + + if (! (value->u.string.ptr = (json_char *) json_alloc + (state, (value->u.string.length + 1) * sizeof (json_char), 0)) ) + { + return 0; + } + + value->u.string.length = 0; + break; + + default: + break; + }; + + return 1; + } + + if (! (value = (json_value *) json_alloc + (state, sizeof (json_value) + state->settings.value_extra, 1))) + { + return 0; + } + + if (!*root) + *root = value; + + value->type = type; + value->parent = *top; + + #ifdef JSON_TRACK_SOURCE + value->line = state->cur_line; + value->col = state->cur_col; + #endif + + if (*alloc) + (*alloc)->_reserved.next_alloc = value; + + *alloc = *top = value; + + return 1; +} + +#define whitespace \ + case '\n': ++ state.cur_line; state.cur_col = 0; /* FALLTHRU */ \ + case ' ': /* FALLTHRU */ case '\t': /* FALLTHRU */ case '\r' + +#define string_add(b) \ + do { if (!state.first_pass) string [string_length] = b; ++ string_length; } while (0); + +#define line_and_col \ + state.cur_line, state.cur_col + +static const long + flag_next = 1 << 0, + flag_reproc = 1 << 1, + flag_need_comma = 1 << 2, + flag_seek_value = 1 << 3, + flag_escaped = 1 << 4, + flag_string = 1 << 5, + flag_need_colon = 1 << 6, + flag_done = 1 << 7, + flag_num_negative = 1 << 8, + flag_num_zero = 1 << 9, + flag_num_e = 1 << 10, + flag_num_e_got_sign = 1 << 11, + flag_num_e_negative = 1 << 12, + flag_line_comment = 1 << 13, + flag_block_comment = 1 << 14, + flag_num_got_decimal = 1 << 15; + +json_value * json_parse_ex (json_settings * settings, + const json_char * json, + size_t length, + char * error_buf) +{ + char error [json_error_max]; + const json_char * end; + json_value * top, * root, * alloc = 0; + json_state state = { 0 }; + long flags = 0; + int num_digits = 0; + double num_e = 0, num_fraction = 0; + + /* Skip UTF-8 BOM + */ + if (length >= 3 && ((unsigned char) json [0]) == 0xEF + && ((unsigned char) json [1]) == 0xBB + && ((unsigned char) json [2]) == 0xBF) + { + json += 3; + length -= 3; + } + + error[0] = '\0'; + end = (json + length); + + memcpy (&state.settings, settings, sizeof (json_settings)); + + if (!state.settings.mem_alloc) + state.settings.mem_alloc = default_alloc; + + if (!state.settings.mem_free) + state.settings.mem_free = default_free; + + for (state.first_pass = 1; state.first_pass >= 0; -- state.first_pass) + { + json_uchar uchar; + unsigned char uc_b1, uc_b2, uc_b3, uc_b4; + json_char * string = 0; + unsigned int string_length = 0; + + top = root = 0; + flags = flag_seek_value; + + state.cur_line = 1; + + for (state.ptr = json ;; ++ state.ptr) + { + json_char b = (state.ptr == end ? 0 : *state.ptr); + + if (flags & flag_string) + { + if (!b) + { sprintf (error, "%u:%u: Unexpected EOF in string", line_and_col); + goto e_failed; + } + + if (string_length > UINT_MAX - 8) + goto e_overflow; + + if (flags & flag_escaped) + { + flags &= ~ flag_escaped; + + switch (b) + { + case 'b': string_add ('\b'); break; + case 'f': string_add ('\f'); break; + case 'n': string_add ('\n'); break; + case 'r': string_add ('\r'); break; + case 't': string_add ('\t'); break; + case 'u': + + if (end - state.ptr <= 4 || + (uc_b1 = hex_value (*++ state.ptr)) == 0xFF || + (uc_b2 = hex_value (*++ state.ptr)) == 0xFF || + (uc_b3 = hex_value (*++ state.ptr)) == 0xFF || + (uc_b4 = hex_value (*++ state.ptr)) == 0xFF) + { + sprintf (error, "%u:%u: Invalid character value `%c`", line_and_col, b); + goto e_failed; + } + + uc_b1 = (uc_b1 << 4) | uc_b2; + uc_b2 = (uc_b3 << 4) | uc_b4; + uchar = (uc_b1 << 8) | uc_b2; + + if ((uchar & 0xF800) == 0xD800) { + json_uchar uchar2; + + if (end - state.ptr <= 6 || (*++ state.ptr) != '\\' || (*++ state.ptr) != 'u' || + (uc_b1 = hex_value (*++ state.ptr)) == 0xFF || + (uc_b2 = hex_value (*++ state.ptr)) == 0xFF || + (uc_b3 = hex_value (*++ state.ptr)) == 0xFF || + (uc_b4 = hex_value (*++ state.ptr)) == 0xFF) + { + sprintf (error, "%u:%u: Invalid character value `%c`", line_and_col, b); + goto e_failed; + } + + uc_b1 = (uc_b1 << 4) | uc_b2; + uc_b2 = (uc_b3 << 4) | uc_b4; + uchar2 = (uc_b1 << 8) | uc_b2; + + uchar = 0x010000 | ((uchar & 0x3FF) << 10) | (uchar2 & 0x3FF); + } + + if (sizeof (json_char) >= sizeof (json_uchar) || (uchar <= 0x7F)) + { + string_add ((json_char) uchar); + break; + } + + if (uchar <= 0x7FF) + { + if (state.first_pass) + string_length += 2; + else + { string [string_length ++] = 0xC0 | (uchar >> 6); + string [string_length ++] = 0x80 | (uchar & 0x3F); + } + + break; + } + + if (uchar <= 0xFFFF) { + if (state.first_pass) + string_length += 3; + else + { string [string_length ++] = 0xE0 | (uchar >> 12); + string [string_length ++] = 0x80 | ((uchar >> 6) & 0x3F); + string [string_length ++] = 0x80 | (uchar & 0x3F); + } + + break; + } + + if (state.first_pass) + string_length += 4; + else + { string [string_length ++] = 0xF0 | (uchar >> 18); + string [string_length ++] = 0x80 | ((uchar >> 12) & 0x3F); + string [string_length ++] = 0x80 | ((uchar >> 6) & 0x3F); + string [string_length ++] = 0x80 | (uchar & 0x3F); + } + + break; + + default: + string_add (b); + }; + + continue; + } + + if (b == '\\') + { + flags |= flag_escaped; + continue; + } + + if (b == '"') + { + if (!state.first_pass) + string [string_length] = 0; + + flags &= ~ flag_string; + string = 0; + + switch (top->type) + { + case json_string: + + top->u.string.length = string_length; + flags |= flag_next; + + break; + + case json_object: + + if (state.first_pass) { + json_char **chars = (json_char **) &top->u.object.values; + chars[0] += string_length + 1; + } + else + { + top->u.object.values [top->u.object.length].name + = (json_char *) top->_reserved.object_mem; + + top->u.object.values [top->u.object.length].name_length + = string_length; + + (*(json_char **) &top->_reserved.object_mem) += string_length + 1; + } + + flags |= flag_seek_value | flag_need_colon; + continue; + + default: + break; + }; + } + else + { + string_add (b); + continue; + } + } + + if (state.settings.settings & json_enable_comments) + { + if (flags & (flag_line_comment | flag_block_comment)) + { + if (flags & flag_line_comment) + { + if (b == '\r' || b == '\n' || !b) + { + flags &= ~ flag_line_comment; + -- state.ptr; /* so null can be reproc'd */ + } + + continue; + } + + if (flags & flag_block_comment) + { + if (!b) + { sprintf (error, "%u:%u: Unexpected EOF in block comment", line_and_col); + goto e_failed; + } + + if (b == '*' && state.ptr < (end - 1) && state.ptr [1] == '/') + { + flags &= ~ flag_block_comment; + ++ state.ptr; /* skip closing sequence */ + } + + continue; + } + } + else if (b == '/') + { + if (! (flags & (flag_seek_value | flag_done)) && top->type != json_object) + { sprintf (error, "%u:%u: Comment not allowed here", line_and_col); + goto e_failed; + } + + if (++ state.ptr == end) + { sprintf (error, "%u:%u: EOF unexpected", line_and_col); + goto e_failed; + } + + switch (b = *state.ptr) + { + case '/': + flags |= flag_line_comment; + continue; + + case '*': + flags |= flag_block_comment; + continue; + + default: + sprintf (error, "%u:%u: Unexpected `%c` in comment opening sequence", line_and_col, b); + goto e_failed; + }; + } + } + + if (flags & flag_done) + { + if (!b) + break; + + switch (b) + { + whitespace: + continue; + + default: + + sprintf (error, "%u:%u: Trailing garbage: `%c`", + line_and_col, b); + + goto e_failed; + }; + } + + if (flags & flag_seek_value) + { + switch (b) + { + whitespace: + continue; + + case ']': + + if (top && top->type == json_array) + flags = (flags & ~ (flag_need_comma | flag_seek_value)) | flag_next; + else + { sprintf (error, "%u:%u: Unexpected `]`", line_and_col); + goto e_failed; + } + + break; + + default: + + if (flags & flag_need_comma) + { + if (b == ',') + { flags &= ~ flag_need_comma; + continue; + } + else + { + sprintf (error, "%u:%u: Expected `,` before `%c`", + line_and_col, b); + + goto e_failed; + } + } + + if (flags & flag_need_colon) + { + if (b == ':') + { flags &= ~ flag_need_colon; + continue; + } + else + { + sprintf (error, "%u:%u: Expected `:` before `%c`", + line_and_col, b); + + goto e_failed; + } + } + + flags &= ~ flag_seek_value; + + switch (b) + { + case '{': + + if (!new_value (&state, &top, &root, &alloc, json_object)) + goto e_alloc_failure; + + continue; + + case '[': + + if (!new_value (&state, &top, &root, &alloc, json_array)) + goto e_alloc_failure; + + flags |= flag_seek_value; + continue; + + case '"': + + if (!new_value (&state, &top, &root, &alloc, json_string)) + goto e_alloc_failure; + + flags |= flag_string; + + string = top->u.string.ptr; + string_length = 0; + + continue; + + case 't': + + if ((end - state.ptr) <= 3 || *(++ state.ptr) != 'r' || + *(++ state.ptr) != 'u' || *(++ state.ptr) != 'e') + { + goto e_unknown_value; + } + + if (!new_value (&state, &top, &root, &alloc, json_boolean)) + goto e_alloc_failure; + + top->u.boolean = 1; + + flags |= flag_next; + break; + + case 'f': + + if ((end - state.ptr) <= 4 || *(++ state.ptr) != 'a' || + *(++ state.ptr) != 'l' || *(++ state.ptr) != 's' || + *(++ state.ptr) != 'e') + { + goto e_unknown_value; + } + + if (!new_value (&state, &top, &root, &alloc, json_boolean)) + goto e_alloc_failure; + + flags |= flag_next; + break; + + case 'n': + + if ((end - state.ptr) <= 3 || *(++ state.ptr) != 'u' || + *(++ state.ptr) != 'l' || *(++ state.ptr) != 'l') + { + goto e_unknown_value; + } + + if (!new_value (&state, &top, &root, &alloc, json_null)) + goto e_alloc_failure; + + flags |= flag_next; + break; + + default: + + if (isdigit ((unsigned char) b) || b == '-') + { + if (!new_value (&state, &top, &root, &alloc, json_integer)) + goto e_alloc_failure; + + if (!state.first_pass) + { + while (isdigit ((unsigned char) b) || b == '+' || b == '-' + || b == 'e' || b == 'E' || b == '.') + { + if ( (++ state.ptr) == end) + { + b = 0; + break; + } + + b = *state.ptr; + } + + flags |= flag_next | flag_reproc; + break; + } + + flags &= ~ (flag_num_negative | flag_num_e | + flag_num_e_got_sign | flag_num_e_negative | + flag_num_zero); + + num_digits = 0; + num_fraction = 0; + num_e = 0; + + if (b != '-') + { + flags |= flag_reproc; + break; + } + + flags |= flag_num_negative; + continue; + } + else + { sprintf (error, "%u:%u: Unexpected `%c` when seeking value", line_and_col, b); + goto e_failed; + } + }; + }; + } + else + { + switch (top->type) + { + case json_object: + + switch (b) + { + whitespace: + continue; + + case '"': + + if (flags & flag_need_comma) + { sprintf (error, "%u:%u: Expected `,` before `\"`", line_and_col); + goto e_failed; + } + + flags |= flag_string; + + string = (json_char *) top->_reserved.object_mem; + string_length = 0; + + break; + + case '}': + + flags = (flags & ~ flag_need_comma) | flag_next; + break; + + case ',': + + if (flags & flag_need_comma) + { + flags &= ~ flag_need_comma; + break; + } /* FALLTHRU */ + + default: + sprintf (error, "%u:%u: Unexpected `%c` in object", line_and_col, b); + goto e_failed; + }; + + break; + + case json_integer: + case json_double: + + if (isdigit ((unsigned char)b)) + { + ++ num_digits; + + if (top->type == json_integer || flags & flag_num_e) + { + if (! (flags & flag_num_e)) + { + if (flags & flag_num_zero) + { sprintf (error, "%u:%u: Unexpected `0` before `%c`", line_and_col, b); + goto e_failed; + } + + if (num_digits == 1 && b == '0') + flags |= flag_num_zero; + } + else + { + flags |= flag_num_e_got_sign; + num_e = (num_e * 10) + (b - '0'); + continue; + } + + if (would_overflow(top->u.integer, b)) + { + json_int_t integer = top->u.integer; + -- num_digits; + -- state.ptr; + top->type = json_double; + top->u.dbl = (double)integer; + continue; + } + + top->u.integer = (top->u.integer * 10) + (b - '0'); + continue; + } + + if (flags & flag_num_got_decimal) + num_fraction = (num_fraction * 10) + (b - '0'); + else + top->u.dbl = (top->u.dbl * 10) + (b - '0'); + + continue; + } + + if (b == '+' || b == '-') + { + if ( (flags & flag_num_e) && !(flags & flag_num_e_got_sign)) + { + flags |= flag_num_e_got_sign; + + if (b == '-') + flags |= flag_num_e_negative; + + continue; + } + } + else if (b == '.' && top->type == json_integer) + { + json_int_t integer = top->u.integer; + + if (!num_digits) + { sprintf (error, "%u:%u: Expected digit before `.`", line_and_col); + goto e_failed; + } + + top->type = json_double; + top->u.dbl = (double) integer; + + flags |= flag_num_got_decimal; + num_digits = 0; + continue; + } + + if (! (flags & flag_num_e)) + { + if (top->type == json_double) + { + if (!num_digits) + { sprintf (error, "%u:%u: Expected digit after `.`", line_and_col); + goto e_failed; + } + + top->u.dbl += num_fraction / pow (10.0, num_digits); + } + + if (b == 'e' || b == 'E') + { + flags |= flag_num_e; + + if (top->type == json_integer) + { + json_int_t integer = top->u.integer; + top->type = json_double; + top->u.dbl = (double) integer; + } + + num_digits = 0; + flags &= ~ flag_num_zero; + + continue; + } + } + else + { + if (!num_digits) + { sprintf (error, "%u:%u: Expected digit after `e`", line_and_col); + goto e_failed; + } + + top->u.dbl *= pow (10.0, (flags & flag_num_e_negative ? - num_e : num_e)); + } + + if (flags & flag_num_negative) + { + if (top->type == json_integer) + top->u.integer = - top->u.integer; + else + top->u.dbl = - top->u.dbl; + } + + flags |= flag_next | flag_reproc; + break; + + default: + break; + }; + } + + if (flags & flag_reproc) + { + flags &= ~ flag_reproc; + -- state.ptr; + } + + if (flags & flag_next) + { + flags = (flags & ~ flag_next) | flag_need_comma; + + if (!top->parent) + { + /* root value done */ + + flags |= flag_done; + continue; + } + + if (top->parent->type == json_array) + flags |= flag_seek_value; + + if (!state.first_pass) + { + json_value * parent = top->parent; + + switch (parent->type) + { + case json_object: + + parent->u.object.values + [parent->u.object.length].value = top; + + break; + + case json_array: + + parent->u.array.values + [parent->u.array.length] = top; + + break; + + default: + break; + }; + } + + if ( (++ top->parent->u.array.length) > UINT_MAX - 8) + goto e_overflow; + + top = top->parent; + + continue; + } + } + + alloc = root; + } + + return root; + +e_unknown_value: + + sprintf (error, "%u:%u: Unknown value", line_and_col); + goto e_failed; + +e_alloc_failure: + + strcpy (error, "Memory allocation failure"); + goto e_failed; + +e_overflow: + + sprintf (error, "%u:%u: Too long (caught overflow)", line_and_col); + goto e_failed; + +e_failed: + + if (error_buf) + { + if (*error) + strcpy (error_buf, error); + else + strcpy (error_buf, "Unknown error"); + } + + if (state.first_pass) + alloc = root; + + while (alloc) + { + top = alloc->_reserved.next_alloc; + state.settings.mem_free (alloc, state.settings.user_data); + alloc = top; + } + + if (!state.first_pass) + json_value_free_ex (&state.settings, root); + + return 0; +} + +json_value * json_parse (const json_char * json, size_t length) +{ + json_settings settings = { 0 }; + return json_parse_ex (&settings, json, length, 0); +} + +void json_value_free_ex (json_settings * settings, json_value * value) +{ + json_value * cur_value; + + if (!value) + return; + + value->parent = 0; + + while (value) + { + switch (value->type) + { + case json_array: + + if (!value->u.array.length) + { + settings->mem_free (value->u.array.values, settings->user_data); + break; + } + + value = value->u.array.values [-- value->u.array.length]; + continue; + + case json_object: + + if (!value->u.object.length) + { + settings->mem_free (value->u.object.values, settings->user_data); + break; + } + + value = value->u.object.values [-- value->u.object.length].value; + continue; + + case json_string: + + settings->mem_free (value->u.string.ptr, settings->user_data); + break; + + default: + break; + }; + + cur_value = value; + value = value->parent; + settings->mem_free (cur_value, settings->user_data); + } +} + +void json_value_free (json_value * value) +{ + json_settings settings = { 0 }; + settings.mem_free = default_free; + json_value_free_ex (&settings, value); +} diff --git a/bin/json.h b/bin/json.h new file mode 100644 index 000000000..1f6431614 --- /dev/null +++ b/bin/json.h @@ -0,0 +1,288 @@ + +/* vim: set et ts=3 sw=3 sts=3 ft=c: + * + * Copyright (C) 2012-2021 the json-parser authors All rights reserved. + * https://github.com/json-parser/json-parser + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _JSON_H +#define _JSON_H + +#ifndef json_char + #define json_char char +#endif + +#ifndef json_int_t + #undef JSON_INT_T_OVERRIDDEN + #if defined(_MSC_VER) + #define json_int_t __int64 + #elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined(__cplusplus) && __cplusplus >= 201103L) + /* C99 and C++11 */ + #include + #define json_int_t int_fast64_t + #else + /* C89 */ + #define json_int_t long + #endif +#else + #define JSON_INT_T_OVERRIDDEN 1 +#endif + +#include + +#ifdef __cplusplus + + #include + + extern "C" + { + +#endif + +typedef struct +{ + unsigned long max_memory; /* should be size_t, but would modify the API */ + int settings; + + /* Custom allocator support (leave null to use malloc/free) + */ + + void * (* mem_alloc) (size_t, int zero, void * user_data); + void (* mem_free) (void *, void * user_data); + + void * user_data; /* will be passed to mem_alloc and mem_free */ + + size_t value_extra; /* how much extra space to allocate for values? */ + +} json_settings; + +#define json_enable_comments 0x01 + +typedef enum +{ + json_none, + json_object, + json_array, + json_integer, + json_double, + json_string, + json_boolean, + json_null + +} json_type; + +extern const struct _json_value json_value_none; + +typedef struct _json_object_entry +{ + json_char * name; + unsigned int name_length; + + struct _json_value * value; + +} json_object_entry; + +typedef struct _json_value +{ + struct _json_value * parent; + + json_type type; + + union + { + int boolean; + json_int_t integer; + double dbl; + + struct + { + unsigned int length; + json_char * ptr; /* null terminated */ + + } string; + + struct + { + unsigned int length; + + json_object_entry * values; + + #if defined(__cplusplus) + json_object_entry * begin () const + { return values; + } + json_object_entry * end () const + { return values + length; + } + #endif + + } object; + + struct + { + unsigned int length; + struct _json_value ** values; + + #if defined(__cplusplus) + _json_value ** begin () const + { return values; + } + _json_value ** end () const + { return values + length; + } + #endif + + } array; + + } u; + + union + { + struct _json_value * next_alloc; + void * object_mem; + + } _reserved; + + #ifdef JSON_TRACK_SOURCE + + /* Location of the value in the source JSON + */ + unsigned int line, col; + + #endif + + + /* Some C++ operator sugar */ + + #ifdef __cplusplus + + public: + + inline _json_value () + { memset (this, 0, sizeof (_json_value)); + } + + inline const struct _json_value &operator [] (int index) const + { + if (type != json_array || index < 0 + || ((unsigned int) index) >= u.array.length) + { + return json_value_none; + } + + return *u.array.values [index]; + } + + inline const struct _json_value &operator [] (const char * index) const + { + if (type != json_object) + return json_value_none; + + for (unsigned int i = 0; i < u.object.length; ++ i) + if (!strcmp (u.object.values [i].name, index)) + return *u.object.values [i].value; + + return json_value_none; + } + + inline operator const char * () const + { + switch (type) + { + case json_string: + return u.string.ptr; + + default: + return ""; + }; + } + + inline operator json_int_t () const + { + switch (type) + { + case json_integer: + return u.integer; + + case json_double: + return (json_int_t) u.dbl; + + default: + return 0; + }; + } + + inline operator bool () const + { + if (type != json_boolean) + return false; + + return u.boolean != 0; + } + + inline operator double () const + { + switch (type) + { + case json_integer: + return (double) u.integer; + + case json_double: + return u.dbl; + + default: + return 0; + }; + } + + #endif + +} json_value; + +json_value * json_parse (const json_char * json, + size_t length); + +#define json_error_max 128 +json_value * json_parse_ex (json_settings * settings, + const json_char * json, + size_t length, + char * error); + +void json_value_free (json_value *); + + +/* Not usually necessary, unless you used a custom mem_alloc and now want to + * use a custom mem_free. + */ +void json_value_free_ex (json_settings * settings, + json_value *); + + +#ifdef __cplusplus + } /* extern "C" */ +#endif + +#endif From 22ffe22ee497fc0161e96e907797d9115f0e8764 Mon Sep 17 00:00:00 2001 From: Krishna Chilleri Date: Tue, 30 Apr 2024 16:52:58 -0600 Subject: [PATCH 07/12] add modified Makefile that includes new json files --- bin/Makefile | 890 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 890 insertions(+) create mode 100644 bin/Makefile diff --git a/bin/Makefile b/bin/Makefile new file mode 100644 index 000000000..620c1b1be --- /dev/null +++ b/bin/Makefile @@ -0,0 +1,890 @@ +# Makefile.in generated by automake 1.16.5 from Makefile.am. +# bin/Makefile. Generated from Makefile.in by configure. + +# Copyright (C) 1994-2021 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + +# Bugs in this Makefile: +# +# 1. $(EXEEXT) not included for scripts. + + + +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/charliecloud +pkgincludedir = $(includedir)/charliecloud +pkglibdir = $(libdir)/charliecloud +pkglibexecdir = $(libexecdir)/charliecloud +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = aarch64-unknown-linux-gnu +host_triplet = aarch64-unknown-linux-gnu +target_triplet = aarch64-unknown-linux-gnu +bin_PROGRAMS = ch-checkns$(EXEEXT) ch-run$(EXEEXT) +am__append_1 = ch_fuse.h ch_fuse.c +am__append_2 = ch-image +subdir = bin +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/misc/m4/ax_check_compile_flag.m4 \ + $(top_srcdir)/misc/m4/ax_compare_version.m4 \ + $(top_srcdir)/misc/m4/ax_pthread.m4 \ + $(top_srcdir)/misc/m4/ax_with_prog.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(dist_bin_SCRIPTS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(bindir)" \ + "$(DESTDIR)$(bindir)" +PROGRAMS = $(bin_PROGRAMS) +am_ch_checkns_OBJECTS = ch-checkns.$(OBJEXT) ch_misc.$(OBJEXT) +ch_checkns_OBJECTS = $(am_ch_checkns_OBJECTS) +ch_checkns_LDADD = $(LDADD) +am__ch_run_SOURCES_DIST = ch-run.c ch_core.h ch_core.c ch_misc.h \ + ch_misc.c ch_fuse.h ch_fuse.c json.h json.c +am__objects_1 = ch_run-ch_fuse.$(OBJEXT) +am_ch_run_OBJECTS = ch_run-ch-run.$(OBJEXT) ch_run-ch_core.$(OBJEXT) \ + ch_run-ch_misc.$(OBJEXT) ch_run-json.$(OBJEXT) $(am__objects_1) +ch_run_OBJECTS = $(am_ch_run_OBJECTS) +am__DEPENDENCIES_1 = +ch_run_DEPENDENCIES = $(am__DEPENDENCIES_1) +ch_run_LINK = $(CCLD) $(ch_run_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +SCRIPTS = $(bin_SCRIPTS) $(dist_bin_SCRIPTS) +AM_V_P = $(am__v_P_$(V)) +am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY)) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I. +depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/ch-checkns.Po ./$(DEPDIR)/ch_misc.Po \ + ./$(DEPDIR)/ch_run-ch-run.Po ./$(DEPDIR)/ch_run-ch_core.Po \ + ./$(DEPDIR)/ch_run-ch_fuse.Po ./$(DEPDIR)/ch_run-ch_misc.Po \ + ./$(DEPDIR)/ch_run-json.Po +am__mv = mv -f +AM_V_lt = $(am__v_lt_$(V)) +am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) +am__v_lt_0 = --silent +am__v_lt_1 = +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(ch_checkns_SOURCES) $(ch_run_SOURCES) +DIST_SOURCES = $(ch_checkns_SOURCES) $(am__ch_run_SOURCES_DIST) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \ + config.h.in +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/config.h.in \ + $(top_srcdir)/build-aux/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = ${SHELL} '/usr/local/src/charliecloud/build-aux/missing' aclocal-1.16 +AMTAR = $${TAR-tar} +AM_DEFAULT_VERBOSITY = 1 +AUTOCONF = ${SHELL} '/usr/local/src/charliecloud/build-aux/missing' autoconf +AUTOHEADER = ${SHELL} '/usr/local/src/charliecloud/build-aux/missing' autoheader +AUTOMAKE = ${SHELL} '/usr/local/src/charliecloud/build-aux/missing' automake-1.16 +AWK = mawk +BATS = bats +BATS_VERSION_NOTE = ok (1.8.2) +CC = gcc +CCDEPMODE = depmode=gcc3 +CFLAGS = -O0 -g -fmax-errors=1 -std=c99 -Wall -Werror -I/usr/include/fuse3 +CH_RUN_LIBS = -lsquashfuse_ll -lfuse3 -lrt -lm +CPP = gcc -E +CPPFLAGS = +CSCOPE = cscope +CTAGS = ctags +CYGPATH_W = echo +DEFS = -DHAVE_CONFIG_H +DEPDIR = .deps +DOCUTILS_VERSION_NOTE = ok (0.19) +DOT = dot +DOT_VERSION_NOTE = ok (2.43.0) +ECHO_C = +ECHO_N = -n +ECHO_T = +EGREP = /usr/bin/grep -E +ETAGS = etags +EXEEXT = +GIT = git +GIT2DOT = git2dot.py +GIT2DOT_VERSION_NOTE = ok (0.8.3) +GIT_VERSION_NOTE = ok (2.39.2) +GREP = /usr/bin/grep +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s +LDFLAGS = +LIBOBJS = +LIBS = +LTLIBOBJS = +MAINT = # +MAKEINFO = ${SHELL} '/usr/local/src/charliecloud/build-aux/missing' makeinfo +MKDIR_P = install -d -m 0755 +MKSQUASHFS = mksquashfs +MKSQUASHFS_VERSION_NOTE = ok (4.5.1) +NVIDIA_CLI = +NVIDIA_CLI_VERSION_NOTE = not found +OBJEXT = o +PACKAGE = charliecloud +PACKAGE_BUGREPORT = https://github.com/hpc/charliecloud +PACKAGE_NAME = Charliecloud +PACKAGE_STRING = Charliecloud 0.38~pre+runocibundles1754.3033595 +PACKAGE_TARNAME = charliecloud +PACKAGE_URL = +PACKAGE_VERSION = 0.38~pre+runocibundles1754.3033595 +PATH_SEPARATOR = : +PTHREAD_CC = gcc +PTHREAD_CFLAGS = -pthread +PTHREAD_CXX = +PTHREAD_LIBS = -lpthread +PYTHON = python3 +PYTHON_SHEBANG = /usr/bin/env python3 +PYTHON_VERSION_NOTE = ok (3.11.2) +REQUESTS_VERSION_NOTE = ok (2.28.1) +RSYNC = rsync +RSYNC_VERSION_NOTE = ok (3.2.7) +RTD_VERSION_NOTE = ok (1.2.0) +SED = /usr/bin/sed +SET_MAKE = +SHELL = /bin/bash +SHELLCHECK = shellcheck +SHELLCHECK_VERSION_NOTE = ok (0.10.0) +SPHINX = /usr/bin/sphinx-build +SPHINX_VERSION_NOTE = ok (5.3.0) +SQUASHFUSE = squashfuse +SQUASHFUSE_VERSION_NOTE = ok (0.5.2) +STRIP = +VERSION = 0.38~pre+runocibundles1754.3033595 +WGET = wget +WGET_VERSION_NOTE = ok (1.21.3) +_BASH = bash +_BASH_VERSION_NOTE = ok (5.2.15(1)-release) +abs_builddir = /usr/local/src/charliecloud/bin +abs_srcdir = /usr/local/src/charliecloud/bin +abs_top_builddir = /usr/local/src/charliecloud +abs_top_srcdir = /usr/local/src/charliecloud +ac_ct_CC = gcc +am__include = include +am__leading_dot = . +am__quote = +am__tar = $${TAR-tar} chof - "$$tardir" +am__untar = $${TAR-tar} xf - +ax_pthread_config = +bindir = ${exec_prefix}/bin +build = aarch64-unknown-linux-gnu +build_alias = +build_cpu = aarch64 +build_os = linux-gnu +build_vendor = unknown +builddir = . +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} +dvidir = ${docdir} +exec_prefix = ${prefix} +have_pkg_config = yes +host = aarch64-unknown-linux-gnu +host_alias = +host_cpu = aarch64 +host_os = linux-gnu +host_vendor = unknown +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = ${SHELL} /usr/local/src/charliecloud/build-aux/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = $(MKDIR_P) +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /tmp/foo +program_transform_name = s,x,x, +psdir = ${docdir} +runstatedir = ${localstatedir}/run +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +srcdir = . +sysconfdir = ${prefix}/etc +target = aarch64-unknown-linux-gnu +target_alias = +target_cpu = aarch64 +target_os = linux-gnu +target_vendor = unknown +top_build_prefix = ../ +top_builddir = .. +top_srcdir = .. +ch_checkns_SOURCES = ch-checkns.c ch_misc.h ch_misc.c +ch_run_SOURCES = ch-run.c ch_core.h ch_core.c ch_misc.h ch_misc.c \ + json.h json.c $(am__append_1) +ch_run_CFLAGS = $(CFLAGS) $(PTHREAD_CFLAGS) +ch_run_LDADD = $(CH_RUN_LIBS) +dist_bin_SCRIPTS = ch-convert \ + ch-fromhost \ + ch-test + +bin_SCRIPTS = ch-run-oci $(am__append_2) +EXTRA_SCRIPTS = ch-image # more scripts that *may* be built +EXTRA_DIST = ch-image.py.in ch-run-oci.py.in +CLEANFILES = $(bin_SCRIPTS) $(EXTRA_SCRIPTS) +all: config.h + $(MAKE) $(AM_MAKEFLAGS) all-am + +.SUFFIXES: +.SUFFIXES: .c .o .obj +$(srcdir)/Makefile.in: # $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign bin/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign bin/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: # $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): # $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +config.h: stamp-h1 + @test -f $@ || rm -f stamp-h1 + @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) stamp-h1 + +stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status + @rm -f stamp-h1 + cd $(top_builddir) && $(SHELL) ./config.status bin/config.h +$(srcdir)/config.h.in: # $(am__configure_deps) + ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) + rm -f stamp-h1 + touch $@ + +distclean-hdr: + -rm -f config.h stamp-h1 +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ + fi; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p \ + ; then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' \ + -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' \ + `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files + +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) + +ch-checkns$(EXEEXT): $(ch_checkns_OBJECTS) $(ch_checkns_DEPENDENCIES) $(EXTRA_ch_checkns_DEPENDENCIES) + @rm -f ch-checkns$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(ch_checkns_OBJECTS) $(ch_checkns_LDADD) $(LIBS) + +ch-run$(EXEEXT): $(ch_run_OBJECTS) $(ch_run_DEPENDENCIES) $(EXTRA_ch_run_DEPENDENCIES) + @rm -f ch-run$(EXEEXT) + $(AM_V_CCLD)$(ch_run_LINK) $(ch_run_OBJECTS) $(ch_run_LDADD) $(LIBS) +install-binSCRIPTS: $(bin_SCRIPTS) + @$(NORMAL_INSTALL) + @list='$(bin_SCRIPTS)'; test -n "$(bindir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + if test -f "$$d$$p"; then echo "$$d$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n' \ + -e 'h;s|.*|.|' \ + -e 'p;x;s,.*/,,;$(transform)' | sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1; } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) { files[d] = files[d] " " $$1; \ + if (++n[d] == $(am__install_max)) { \ + print "f", d, files[d]; n[d] = 0; files[d] = "" } } \ + else { print "f", d "/" $$4, $$1 } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_SCRIPT) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_SCRIPT) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binSCRIPTS: + @$(NORMAL_UNINSTALL) + @list='$(bin_SCRIPTS)'; test -n "$(bindir)" || exit 0; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 's,.*/,,;$(transform)'`; \ + dir='$(DESTDIR)$(bindir)'; $(am__uninstall_files_from_dir) +install-dist_binSCRIPTS: $(dist_bin_SCRIPTS) + @$(NORMAL_INSTALL) + @list='$(dist_bin_SCRIPTS)'; test -n "$(bindir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + if test -f "$$d$$p"; then echo "$$d$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n' \ + -e 'h;s|.*|.|' \ + -e 'p;x;s,.*/,,;$(transform)' | sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1; } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) { files[d] = files[d] " " $$1; \ + if (++n[d] == $(am__install_max)) { \ + print "f", d, files[d]; n[d] = 0; files[d] = "" } } \ + else { print "f", d "/" $$4, $$1 } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_SCRIPT) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_SCRIPT) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-dist_binSCRIPTS: + @$(NORMAL_UNINSTALL) + @list='$(dist_bin_SCRIPTS)'; test -n "$(bindir)" || exit 0; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 's,.*/,,;$(transform)'`; \ + dir='$(DESTDIR)$(bindir)'; $(am__uninstall_files_from_dir) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +include ./$(DEPDIR)/ch-checkns.Po # am--include-marker +include ./$(DEPDIR)/ch_misc.Po # am--include-marker +include ./$(DEPDIR)/ch_run-ch-run.Po # am--include-marker +include ./$(DEPDIR)/ch_run-ch_core.Po # am--include-marker +include ./$(DEPDIR)/ch_run-ch_fuse.Po # am--include-marker +include ./$(DEPDIR)/ch_run-ch_misc.Po # am--include-marker +include ./$(DEPDIR)/ch_run-json.Po # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.c.o: + $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ + $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ + $(am__mv) $$depbase.Tpo $$depbase.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ $< + +.c.obj: + $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ + $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ + $(am__mv) $$depbase.Tpo $$depbase.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ch_run-ch-run.o: ch-run.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -MT ch_run-ch-run.o -MD -MP -MF $(DEPDIR)/ch_run-ch-run.Tpo -c -o ch_run-ch-run.o `test -f 'ch-run.c' || echo '$(srcdir)/'`ch-run.c + $(AM_V_at)$(am__mv) $(DEPDIR)/ch_run-ch-run.Tpo $(DEPDIR)/ch_run-ch-run.Po +# $(AM_V_CC)source='ch-run.c' object='ch_run-ch-run.o' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -c -o ch_run-ch-run.o `test -f 'ch-run.c' || echo '$(srcdir)/'`ch-run.c + +ch_run-ch-run.obj: ch-run.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -MT ch_run-ch-run.obj -MD -MP -MF $(DEPDIR)/ch_run-ch-run.Tpo -c -o ch_run-ch-run.obj `if test -f 'ch-run.c'; then $(CYGPATH_W) 'ch-run.c'; else $(CYGPATH_W) '$(srcdir)/ch-run.c'; fi` + $(AM_V_at)$(am__mv) $(DEPDIR)/ch_run-ch-run.Tpo $(DEPDIR)/ch_run-ch-run.Po +# $(AM_V_CC)source='ch-run.c' object='ch_run-ch-run.obj' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -c -o ch_run-ch-run.obj `if test -f 'ch-run.c'; then $(CYGPATH_W) 'ch-run.c'; else $(CYGPATH_W) '$(srcdir)/ch-run.c'; fi` + +ch_run-ch_core.o: ch_core.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -MT ch_run-ch_core.o -MD -MP -MF $(DEPDIR)/ch_run-ch_core.Tpo -c -o ch_run-ch_core.o `test -f 'ch_core.c' || echo '$(srcdir)/'`ch_core.c + $(AM_V_at)$(am__mv) $(DEPDIR)/ch_run-ch_core.Tpo $(DEPDIR)/ch_run-ch_core.Po +# $(AM_V_CC)source='ch_core.c' object='ch_run-ch_core.o' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -c -o ch_run-ch_core.o `test -f 'ch_core.c' || echo '$(srcdir)/'`ch_core.c + +ch_run-ch_core.obj: ch_core.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -MT ch_run-ch_core.obj -MD -MP -MF $(DEPDIR)/ch_run-ch_core.Tpo -c -o ch_run-ch_core.obj `if test -f 'ch_core.c'; then $(CYGPATH_W) 'ch_core.c'; else $(CYGPATH_W) '$(srcdir)/ch_core.c'; fi` + $(AM_V_at)$(am__mv) $(DEPDIR)/ch_run-ch_core.Tpo $(DEPDIR)/ch_run-ch_core.Po +# $(AM_V_CC)source='ch_core.c' object='ch_run-ch_core.obj' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -c -o ch_run-ch_core.obj `if test -f 'ch_core.c'; then $(CYGPATH_W) 'ch_core.c'; else $(CYGPATH_W) '$(srcdir)/ch_core.c'; fi` + +ch_run-ch_misc.o: ch_misc.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -MT ch_run-ch_misc.o -MD -MP -MF $(DEPDIR)/ch_run-ch_misc.Tpo -c -o ch_run-ch_misc.o `test -f 'ch_misc.c' || echo '$(srcdir)/'`ch_misc.c + $(AM_V_at)$(am__mv) $(DEPDIR)/ch_run-ch_misc.Tpo $(DEPDIR)/ch_run-ch_misc.Po +# $(AM_V_CC)source='ch_misc.c' object='ch_run-ch_misc.o' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -c -o ch_run-ch_misc.o `test -f 'ch_misc.c' || echo '$(srcdir)/'`ch_misc.c + +ch_run-ch_misc.obj: ch_misc.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -MT ch_run-ch_misc.obj -MD -MP -MF $(DEPDIR)/ch_run-ch_misc.Tpo -c -o ch_run-ch_misc.obj `if test -f 'ch_misc.c'; then $(CYGPATH_W) 'ch_misc.c'; else $(CYGPATH_W) '$(srcdir)/ch_misc.c'; fi` + $(AM_V_at)$(am__mv) $(DEPDIR)/ch_run-ch_misc.Tpo $(DEPDIR)/ch_run-ch_misc.Po +# $(AM_V_CC)source='ch_misc.c' object='ch_run-ch_misc.obj' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -c -o ch_run-ch_misc.obj `if test -f 'ch_misc.c'; then $(CYGPATH_W) 'ch_misc.c'; else $(CYGPATH_W) '$(srcdir)/ch_misc.c'; fi` + +ch_run-ch_fuse.o: ch_fuse.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -MT ch_run-ch_fuse.o -MD -MP -MF $(DEPDIR)/ch_run-ch_fuse.Tpo -c -o ch_run-ch_fuse.o `test -f 'ch_fuse.c' || echo '$(srcdir)/'`ch_fuse.c + $(AM_V_at)$(am__mv) $(DEPDIR)/ch_run-ch_fuse.Tpo $(DEPDIR)/ch_run-ch_fuse.Po +# $(AM_V_CC)source='ch_fuse.c' object='ch_run-ch_fuse.o' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -c -o ch_run-ch_fuse.o `test -f 'ch_fuse.c' || echo '$(srcdir)/'`ch_fuse.c + +ch_run-ch_fuse.obj: ch_fuse.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -MT ch_run-ch_fuse.obj -MD -MP -MF $(DEPDIR)/ch_run-ch_fuse.Tpo -c -o ch_run-ch_fuse.obj `if test -f 'ch_fuse.c'; then $(CYGPATH_W) 'ch_fuse.c'; else $(CYGPATH_W) '$(srcdir)/ch_fuse.c'; fi` + $(AM_V_at)$(am__mv) $(DEPDIR)/ch_run-ch_fuse.Tpo $(DEPDIR)/ch_run-ch_fuse.Po +# $(AM_V_CC)source='ch_fuse.c' object='ch_run-ch_fuse.obj' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -c -o ch_run-ch_fuse.obj `if test -f 'ch_fuse.c'; then $(CYGPATH_W) 'ch_fuse.c'; else $(CYGPATH_W) '$(srcdir)/ch_fuse.c'; fi` + +ch_run-json.o: json.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -MT ch_run-json.o -MD -MP -MF $(DEPDIR)/ch_run-json.Tpo -c -o ch_run-json.o `test -f 'json.c' || echo '$(srcdir)/'`json.c + $(AM_V_at)$(am__mv) $(DEPDIR)/ch_run-json.Tpo $(DEPDIR)/ch_run-json.Po +# $(AM_V_CC)source='json.c' object='ch_run-json.o' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -c -o ch_run-json.o `test -f 'json.c' || echo '$(srcdir)/'`json.c + +ch_run-json.obj: json.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -MT ch_run-json.obj -MD -MP -MF $(DEPDIR)/ch_run-json.Tpo -c -o ch_run-json.obj `if test -f 'json.c'; then $(CYGPATH_W) 'json.c'; else $(CYGPATH_W) '$(srcdir)/json.c'; fi` + $(AM_V_at)$(am__mv) $(DEPDIR)/ch_run-json.Tpo $(DEPDIR)/ch_run-json.Po +# $(AM_V_CC)source='json.c' object='ch_run-json.obj' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -c -o ch_run-json.obj `if test -f 'json.c'; then $(CYGPATH_W) 'json.c'; else $(CYGPATH_W) '$(srcdir)/json.c'; fi` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) $(SCRIPTS) config.h +installdirs: + for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/ch-checkns.Po + -rm -f ./$(DEPDIR)/ch_misc.Po + -rm -f ./$(DEPDIR)/ch_run-ch-run.Po + -rm -f ./$(DEPDIR)/ch_run-ch_core.Po + -rm -f ./$(DEPDIR)/ch_run-ch_fuse.Po + -rm -f ./$(DEPDIR)/ch_run-ch_misc.Po + -rm -f ./$(DEPDIR)/ch_run-json.Po + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-hdr distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-binPROGRAMS install-binSCRIPTS \ + install-dist_binSCRIPTS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f ./$(DEPDIR)/ch-checkns.Po + -rm -f ./$(DEPDIR)/ch_misc.Po + -rm -f ./$(DEPDIR)/ch_run-ch-run.Po + -rm -f ./$(DEPDIR)/ch_run-ch_core.Po + -rm -f ./$(DEPDIR)/ch_run-ch_fuse.Po + -rm -f ./$(DEPDIR)/ch_run-ch_misc.Po + -rm -f ./$(DEPDIR)/ch_run-json.Po + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS uninstall-binSCRIPTS \ + uninstall-dist_binSCRIPTS + +.MAKE: all install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ + clean-binPROGRAMS clean-generic cscopelist-am ctags ctags-am \ + distclean distclean-compile distclean-generic distclean-hdr \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-binPROGRAMS install-binSCRIPTS \ + install-data install-data-am install-dist_binSCRIPTS \ + install-dvi install-dvi-am install-exec install-exec-am \ + install-html install-html-am install-info install-info-am \ + install-man install-pdf install-pdf-am install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \ + ps ps-am tags tags-am uninstall uninstall-am \ + uninstall-binPROGRAMS uninstall-binSCRIPTS \ + uninstall-dist_binSCRIPTS + +.PRECIOUS: Makefile + + +ch-image: ch-image.py.in +ch-run-oci: ch-run-oci.py.in + +$(bin_SCRIPTS): %: %.py.in + rm -f $@ + sed -E 's|%PYTHON_SHEBANG%|/usr/bin/env python3|' < $< > $@ + chmod +rx,-w $@ # respects umask + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: From 2c394385c718b7cd7630060da38376284bfec67d Mon Sep 17 00:00:00 2001 From: Krishna Chilleri Date: Wed, 8 May 2024 12:52:38 -0600 Subject: [PATCH 08/12] remove json files - install json debian package instead --- bin/Makefile | 26 +- bin/ch-run.c | 1 - bin/json.c | 1057 -------------------------------------------------- bin/json.h | 288 -------------- 4 files changed, 4 insertions(+), 1368 deletions(-) delete mode 100644 bin/json.c delete mode 100644 bin/json.h diff --git a/bin/Makefile b/bin/Makefile index 620c1b1be..cd1185bc8 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -119,10 +119,10 @@ am_ch_checkns_OBJECTS = ch-checkns.$(OBJEXT) ch_misc.$(OBJEXT) ch_checkns_OBJECTS = $(am_ch_checkns_OBJECTS) ch_checkns_LDADD = $(LDADD) am__ch_run_SOURCES_DIST = ch-run.c ch_core.h ch_core.c ch_misc.h \ - ch_misc.c ch_fuse.h ch_fuse.c json.h json.c + ch_misc.c ch_fuse.h ch_fuse.c am__objects_1 = ch_run-ch_fuse.$(OBJEXT) am_ch_run_OBJECTS = ch_run-ch-run.$(OBJEXT) ch_run-ch_core.$(OBJEXT) \ - ch_run-ch_misc.$(OBJEXT) ch_run-json.$(OBJEXT) $(am__objects_1) + ch_run-ch_misc.$(OBJEXT) $(am__objects_1) ch_run_OBJECTS = $(am_ch_run_OBJECTS) am__DEPENDENCIES_1 = ch_run_DEPENDENCIES = $(am__DEPENDENCIES_1) @@ -173,8 +173,7 @@ depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/ch-checkns.Po ./$(DEPDIR)/ch_misc.Po \ ./$(DEPDIR)/ch_run-ch-run.Po ./$(DEPDIR)/ch_run-ch_core.Po \ - ./$(DEPDIR)/ch_run-ch_fuse.Po ./$(DEPDIR)/ch_run-ch_misc.Po \ - ./$(DEPDIR)/ch_run-json.Po + ./$(DEPDIR)/ch_run-ch_fuse.Po ./$(DEPDIR)/ch_run-ch_misc.Po am__mv = mv -f AM_V_lt = $(am__v_lt_$(V)) am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) @@ -364,7 +363,7 @@ top_builddir = .. top_srcdir = .. ch_checkns_SOURCES = ch-checkns.c ch_misc.h ch_misc.c ch_run_SOURCES = ch-run.c ch_core.h ch_core.c ch_misc.h ch_misc.c \ - json.h json.c $(am__append_1) + $(am__append_1) ch_run_CFLAGS = $(CFLAGS) $(PTHREAD_CFLAGS) ch_run_LDADD = $(CH_RUN_LIBS) dist_bin_SCRIPTS = ch-convert \ @@ -557,7 +556,6 @@ include ./$(DEPDIR)/ch_run-ch-run.Po # am--include-marker include ./$(DEPDIR)/ch_run-ch_core.Po # am--include-marker include ./$(DEPDIR)/ch_run-ch_fuse.Po # am--include-marker include ./$(DEPDIR)/ch_run-ch_misc.Po # am--include-marker -include ./$(DEPDIR)/ch_run-json.Po # am--include-marker $(am__depfiles_remade): @$(MKDIR_P) $(@D) @@ -637,20 +635,6 @@ ch_run-ch_fuse.obj: ch_fuse.c # DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ # $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -c -o ch_run-ch_fuse.obj `if test -f 'ch_fuse.c'; then $(CYGPATH_W) 'ch_fuse.c'; else $(CYGPATH_W) '$(srcdir)/ch_fuse.c'; fi` -ch_run-json.o: json.c - $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -MT ch_run-json.o -MD -MP -MF $(DEPDIR)/ch_run-json.Tpo -c -o ch_run-json.o `test -f 'json.c' || echo '$(srcdir)/'`json.c - $(AM_V_at)$(am__mv) $(DEPDIR)/ch_run-json.Tpo $(DEPDIR)/ch_run-json.Po -# $(AM_V_CC)source='json.c' object='ch_run-json.o' libtool=no \ -# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ -# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -c -o ch_run-json.o `test -f 'json.c' || echo '$(srcdir)/'`json.c - -ch_run-json.obj: json.c - $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -MT ch_run-json.obj -MD -MP -MF $(DEPDIR)/ch_run-json.Tpo -c -o ch_run-json.obj `if test -f 'json.c'; then $(CYGPATH_W) 'json.c'; else $(CYGPATH_W) '$(srcdir)/json.c'; fi` - $(AM_V_at)$(am__mv) $(DEPDIR)/ch_run-json.Tpo $(DEPDIR)/ch_run-json.Po -# $(AM_V_CC)source='json.c' object='ch_run-json.obj' libtool=no \ -# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ -# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ch_run_CFLAGS) $(CFLAGS) -c -o ch_run-json.obj `if test -f 'json.c'; then $(CYGPATH_W) 'json.c'; else $(CYGPATH_W) '$(srcdir)/json.c'; fi` - ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am @@ -784,7 +768,6 @@ distclean: distclean-am -rm -f ./$(DEPDIR)/ch_run-ch_core.Po -rm -f ./$(DEPDIR)/ch_run-ch_fuse.Po -rm -f ./$(DEPDIR)/ch_run-ch_misc.Po - -rm -f ./$(DEPDIR)/ch_run-json.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-hdr distclean-tags @@ -837,7 +820,6 @@ maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/ch_run-ch_core.Po -rm -f ./$(DEPDIR)/ch_run-ch_fuse.Po -rm -f ./$(DEPDIR)/ch_run-ch_misc.Po - -rm -f ./$(DEPDIR)/ch_run-json.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic diff --git a/bin/ch-run.c b/bin/ch-run.c index e061038c4..067432ee5 100644 --- a/bin/ch-run.c +++ b/bin/ch-run.c @@ -15,7 +15,6 @@ #include "config.h" #include "ch_core.h" #include "ch_misc.h" -#include "json.h" /** Constants and macros **/ diff --git a/bin/json.c b/bin/json.c deleted file mode 100644 index deef49ff3..000000000 --- a/bin/json.c +++ /dev/null @@ -1,1057 +0,0 @@ -/* vim: set et ts=3 sw=3 sts=3 ft=c: - * - * Copyright (C) 2012-2021 the json-parser authors All rights reserved. - * https://github.com/json-parser/json-parser - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "json.h" - -#ifdef _MSC_VER - #ifndef _CRT_SECURE_NO_WARNINGS - #define _CRT_SECURE_NO_WARNINGS - #endif -#endif - -#include -#include -#include -#include -#include -#include - -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - /* C99 might give us uintptr_t and UINTPTR_MAX but they also might not be provided */ - #include -#endif - -#ifndef JSON_INT_T_OVERRIDDEN - #if defined(_MSC_VER) - /* https://docs.microsoft.com/en-us/cpp/cpp/data-type-ranges */ - #define JSON_INT_MAX 9223372036854775807LL - #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - /* C99 */ - #define JSON_INT_MAX INT_FAST64_MAX - #else - /* C89 */ - #include - #define JSON_INT_MAX LONG_MAX - #endif -#endif - -#ifndef JSON_INT_MAX -#define JSON_INT_MAX (json_int_t)(((unsigned json_int_t)(-1)) / (unsigned json_int_t)2); -#endif - -typedef unsigned int json_uchar; - -const struct _json_value json_value_none; - -static unsigned char hex_value (json_char c) -{ - if (isdigit((unsigned char)c)) - return c - '0'; - - switch (c) { - case 'a': case 'A': return 0x0A; - case 'b': case 'B': return 0x0B; - case 'c': case 'C': return 0x0C; - case 'd': case 'D': return 0x0D; - case 'e': case 'E': return 0x0E; - case 'f': case 'F': return 0x0F; - default: return 0xFF; - } -} - -static int would_overflow (json_int_t value, json_char b) -{ - return ((JSON_INT_MAX - (b - '0')) / 10 ) < value; -} - -typedef struct -{ - size_t used_memory; - - json_settings settings; - int first_pass; - - const json_char * ptr; - unsigned int cur_line, cur_col; - -} json_state; - -static void * default_alloc (size_t size, int zero, void * user_data) -{ - (void)user_data; /* ignore unused-parameter warn */ - return zero ? calloc (1, size) : malloc (size); -} - -static void default_free (void * ptr, void * user_data) -{ - (void)user_data; /* ignore unused-parameter warn */ - free (ptr); -} - -static void * json_alloc (json_state * state, size_t size, int zero) -{ - if ((ULONG_MAX - 8 - state->used_memory) < size) - return 0; - - if (state->settings.max_memory - && (state->used_memory += size) > state->settings.max_memory) - { - return 0; - } - - return state->settings.mem_alloc (size, zero, state->settings.user_data); -} - -static int new_value (json_state * state, - json_value ** top, json_value ** root, json_value ** alloc, - json_type type) -{ - json_value * value; - size_t values_size; - - if (!state->first_pass) - { - value = *top = *alloc; - *alloc = (*alloc)->_reserved.next_alloc; - - if (!*root) - *root = value; - - switch (value->type) - { - case json_array: - - if (value->u.array.length == 0) - break; - - if (! (value->u.array.values = (json_value **) json_alloc - (state, value->u.array.length * sizeof (json_value *), 0)) ) - { - return 0; - } - - value->u.array.length = 0; - break; - - case json_object: - - if (value->u.object.length == 0) - break; - - values_size = sizeof (*value->u.object.values) * value->u.object.length; - - if (! (value->u.object.values = (json_object_entry *) json_alloc - #ifdef UINTPTR_MAX - (state, values_size + ((uintptr_t) value->u.object.values), 0)) ) - #else - (state, values_size + ((size_t) value->u.object.values), 0)) ) - #endif - { - return 0; - } - - value->_reserved.object_mem = (void *) (((char *) value->u.object.values) + values_size); - - value->u.object.length = 0; - break; - - case json_string: - - if (! (value->u.string.ptr = (json_char *) json_alloc - (state, (value->u.string.length + 1) * sizeof (json_char), 0)) ) - { - return 0; - } - - value->u.string.length = 0; - break; - - default: - break; - }; - - return 1; - } - - if (! (value = (json_value *) json_alloc - (state, sizeof (json_value) + state->settings.value_extra, 1))) - { - return 0; - } - - if (!*root) - *root = value; - - value->type = type; - value->parent = *top; - - #ifdef JSON_TRACK_SOURCE - value->line = state->cur_line; - value->col = state->cur_col; - #endif - - if (*alloc) - (*alloc)->_reserved.next_alloc = value; - - *alloc = *top = value; - - return 1; -} - -#define whitespace \ - case '\n': ++ state.cur_line; state.cur_col = 0; /* FALLTHRU */ \ - case ' ': /* FALLTHRU */ case '\t': /* FALLTHRU */ case '\r' - -#define string_add(b) \ - do { if (!state.first_pass) string [string_length] = b; ++ string_length; } while (0); - -#define line_and_col \ - state.cur_line, state.cur_col - -static const long - flag_next = 1 << 0, - flag_reproc = 1 << 1, - flag_need_comma = 1 << 2, - flag_seek_value = 1 << 3, - flag_escaped = 1 << 4, - flag_string = 1 << 5, - flag_need_colon = 1 << 6, - flag_done = 1 << 7, - flag_num_negative = 1 << 8, - flag_num_zero = 1 << 9, - flag_num_e = 1 << 10, - flag_num_e_got_sign = 1 << 11, - flag_num_e_negative = 1 << 12, - flag_line_comment = 1 << 13, - flag_block_comment = 1 << 14, - flag_num_got_decimal = 1 << 15; - -json_value * json_parse_ex (json_settings * settings, - const json_char * json, - size_t length, - char * error_buf) -{ - char error [json_error_max]; - const json_char * end; - json_value * top, * root, * alloc = 0; - json_state state = { 0 }; - long flags = 0; - int num_digits = 0; - double num_e = 0, num_fraction = 0; - - /* Skip UTF-8 BOM - */ - if (length >= 3 && ((unsigned char) json [0]) == 0xEF - && ((unsigned char) json [1]) == 0xBB - && ((unsigned char) json [2]) == 0xBF) - { - json += 3; - length -= 3; - } - - error[0] = '\0'; - end = (json + length); - - memcpy (&state.settings, settings, sizeof (json_settings)); - - if (!state.settings.mem_alloc) - state.settings.mem_alloc = default_alloc; - - if (!state.settings.mem_free) - state.settings.mem_free = default_free; - - for (state.first_pass = 1; state.first_pass >= 0; -- state.first_pass) - { - json_uchar uchar; - unsigned char uc_b1, uc_b2, uc_b3, uc_b4; - json_char * string = 0; - unsigned int string_length = 0; - - top = root = 0; - flags = flag_seek_value; - - state.cur_line = 1; - - for (state.ptr = json ;; ++ state.ptr) - { - json_char b = (state.ptr == end ? 0 : *state.ptr); - - if (flags & flag_string) - { - if (!b) - { sprintf (error, "%u:%u: Unexpected EOF in string", line_and_col); - goto e_failed; - } - - if (string_length > UINT_MAX - 8) - goto e_overflow; - - if (flags & flag_escaped) - { - flags &= ~ flag_escaped; - - switch (b) - { - case 'b': string_add ('\b'); break; - case 'f': string_add ('\f'); break; - case 'n': string_add ('\n'); break; - case 'r': string_add ('\r'); break; - case 't': string_add ('\t'); break; - case 'u': - - if (end - state.ptr <= 4 || - (uc_b1 = hex_value (*++ state.ptr)) == 0xFF || - (uc_b2 = hex_value (*++ state.ptr)) == 0xFF || - (uc_b3 = hex_value (*++ state.ptr)) == 0xFF || - (uc_b4 = hex_value (*++ state.ptr)) == 0xFF) - { - sprintf (error, "%u:%u: Invalid character value `%c`", line_and_col, b); - goto e_failed; - } - - uc_b1 = (uc_b1 << 4) | uc_b2; - uc_b2 = (uc_b3 << 4) | uc_b4; - uchar = (uc_b1 << 8) | uc_b2; - - if ((uchar & 0xF800) == 0xD800) { - json_uchar uchar2; - - if (end - state.ptr <= 6 || (*++ state.ptr) != '\\' || (*++ state.ptr) != 'u' || - (uc_b1 = hex_value (*++ state.ptr)) == 0xFF || - (uc_b2 = hex_value (*++ state.ptr)) == 0xFF || - (uc_b3 = hex_value (*++ state.ptr)) == 0xFF || - (uc_b4 = hex_value (*++ state.ptr)) == 0xFF) - { - sprintf (error, "%u:%u: Invalid character value `%c`", line_and_col, b); - goto e_failed; - } - - uc_b1 = (uc_b1 << 4) | uc_b2; - uc_b2 = (uc_b3 << 4) | uc_b4; - uchar2 = (uc_b1 << 8) | uc_b2; - - uchar = 0x010000 | ((uchar & 0x3FF) << 10) | (uchar2 & 0x3FF); - } - - if (sizeof (json_char) >= sizeof (json_uchar) || (uchar <= 0x7F)) - { - string_add ((json_char) uchar); - break; - } - - if (uchar <= 0x7FF) - { - if (state.first_pass) - string_length += 2; - else - { string [string_length ++] = 0xC0 | (uchar >> 6); - string [string_length ++] = 0x80 | (uchar & 0x3F); - } - - break; - } - - if (uchar <= 0xFFFF) { - if (state.first_pass) - string_length += 3; - else - { string [string_length ++] = 0xE0 | (uchar >> 12); - string [string_length ++] = 0x80 | ((uchar >> 6) & 0x3F); - string [string_length ++] = 0x80 | (uchar & 0x3F); - } - - break; - } - - if (state.first_pass) - string_length += 4; - else - { string [string_length ++] = 0xF0 | (uchar >> 18); - string [string_length ++] = 0x80 | ((uchar >> 12) & 0x3F); - string [string_length ++] = 0x80 | ((uchar >> 6) & 0x3F); - string [string_length ++] = 0x80 | (uchar & 0x3F); - } - - break; - - default: - string_add (b); - }; - - continue; - } - - if (b == '\\') - { - flags |= flag_escaped; - continue; - } - - if (b == '"') - { - if (!state.first_pass) - string [string_length] = 0; - - flags &= ~ flag_string; - string = 0; - - switch (top->type) - { - case json_string: - - top->u.string.length = string_length; - flags |= flag_next; - - break; - - case json_object: - - if (state.first_pass) { - json_char **chars = (json_char **) &top->u.object.values; - chars[0] += string_length + 1; - } - else - { - top->u.object.values [top->u.object.length].name - = (json_char *) top->_reserved.object_mem; - - top->u.object.values [top->u.object.length].name_length - = string_length; - - (*(json_char **) &top->_reserved.object_mem) += string_length + 1; - } - - flags |= flag_seek_value | flag_need_colon; - continue; - - default: - break; - }; - } - else - { - string_add (b); - continue; - } - } - - if (state.settings.settings & json_enable_comments) - { - if (flags & (flag_line_comment | flag_block_comment)) - { - if (flags & flag_line_comment) - { - if (b == '\r' || b == '\n' || !b) - { - flags &= ~ flag_line_comment; - -- state.ptr; /* so null can be reproc'd */ - } - - continue; - } - - if (flags & flag_block_comment) - { - if (!b) - { sprintf (error, "%u:%u: Unexpected EOF in block comment", line_and_col); - goto e_failed; - } - - if (b == '*' && state.ptr < (end - 1) && state.ptr [1] == '/') - { - flags &= ~ flag_block_comment; - ++ state.ptr; /* skip closing sequence */ - } - - continue; - } - } - else if (b == '/') - { - if (! (flags & (flag_seek_value | flag_done)) && top->type != json_object) - { sprintf (error, "%u:%u: Comment not allowed here", line_and_col); - goto e_failed; - } - - if (++ state.ptr == end) - { sprintf (error, "%u:%u: EOF unexpected", line_and_col); - goto e_failed; - } - - switch (b = *state.ptr) - { - case '/': - flags |= flag_line_comment; - continue; - - case '*': - flags |= flag_block_comment; - continue; - - default: - sprintf (error, "%u:%u: Unexpected `%c` in comment opening sequence", line_and_col, b); - goto e_failed; - }; - } - } - - if (flags & flag_done) - { - if (!b) - break; - - switch (b) - { - whitespace: - continue; - - default: - - sprintf (error, "%u:%u: Trailing garbage: `%c`", - line_and_col, b); - - goto e_failed; - }; - } - - if (flags & flag_seek_value) - { - switch (b) - { - whitespace: - continue; - - case ']': - - if (top && top->type == json_array) - flags = (flags & ~ (flag_need_comma | flag_seek_value)) | flag_next; - else - { sprintf (error, "%u:%u: Unexpected `]`", line_and_col); - goto e_failed; - } - - break; - - default: - - if (flags & flag_need_comma) - { - if (b == ',') - { flags &= ~ flag_need_comma; - continue; - } - else - { - sprintf (error, "%u:%u: Expected `,` before `%c`", - line_and_col, b); - - goto e_failed; - } - } - - if (flags & flag_need_colon) - { - if (b == ':') - { flags &= ~ flag_need_colon; - continue; - } - else - { - sprintf (error, "%u:%u: Expected `:` before `%c`", - line_and_col, b); - - goto e_failed; - } - } - - flags &= ~ flag_seek_value; - - switch (b) - { - case '{': - - if (!new_value (&state, &top, &root, &alloc, json_object)) - goto e_alloc_failure; - - continue; - - case '[': - - if (!new_value (&state, &top, &root, &alloc, json_array)) - goto e_alloc_failure; - - flags |= flag_seek_value; - continue; - - case '"': - - if (!new_value (&state, &top, &root, &alloc, json_string)) - goto e_alloc_failure; - - flags |= flag_string; - - string = top->u.string.ptr; - string_length = 0; - - continue; - - case 't': - - if ((end - state.ptr) <= 3 || *(++ state.ptr) != 'r' || - *(++ state.ptr) != 'u' || *(++ state.ptr) != 'e') - { - goto e_unknown_value; - } - - if (!new_value (&state, &top, &root, &alloc, json_boolean)) - goto e_alloc_failure; - - top->u.boolean = 1; - - flags |= flag_next; - break; - - case 'f': - - if ((end - state.ptr) <= 4 || *(++ state.ptr) != 'a' || - *(++ state.ptr) != 'l' || *(++ state.ptr) != 's' || - *(++ state.ptr) != 'e') - { - goto e_unknown_value; - } - - if (!new_value (&state, &top, &root, &alloc, json_boolean)) - goto e_alloc_failure; - - flags |= flag_next; - break; - - case 'n': - - if ((end - state.ptr) <= 3 || *(++ state.ptr) != 'u' || - *(++ state.ptr) != 'l' || *(++ state.ptr) != 'l') - { - goto e_unknown_value; - } - - if (!new_value (&state, &top, &root, &alloc, json_null)) - goto e_alloc_failure; - - flags |= flag_next; - break; - - default: - - if (isdigit ((unsigned char) b) || b == '-') - { - if (!new_value (&state, &top, &root, &alloc, json_integer)) - goto e_alloc_failure; - - if (!state.first_pass) - { - while (isdigit ((unsigned char) b) || b == '+' || b == '-' - || b == 'e' || b == 'E' || b == '.') - { - if ( (++ state.ptr) == end) - { - b = 0; - break; - } - - b = *state.ptr; - } - - flags |= flag_next | flag_reproc; - break; - } - - flags &= ~ (flag_num_negative | flag_num_e | - flag_num_e_got_sign | flag_num_e_negative | - flag_num_zero); - - num_digits = 0; - num_fraction = 0; - num_e = 0; - - if (b != '-') - { - flags |= flag_reproc; - break; - } - - flags |= flag_num_negative; - continue; - } - else - { sprintf (error, "%u:%u: Unexpected `%c` when seeking value", line_and_col, b); - goto e_failed; - } - }; - }; - } - else - { - switch (top->type) - { - case json_object: - - switch (b) - { - whitespace: - continue; - - case '"': - - if (flags & flag_need_comma) - { sprintf (error, "%u:%u: Expected `,` before `\"`", line_and_col); - goto e_failed; - } - - flags |= flag_string; - - string = (json_char *) top->_reserved.object_mem; - string_length = 0; - - break; - - case '}': - - flags = (flags & ~ flag_need_comma) | flag_next; - break; - - case ',': - - if (flags & flag_need_comma) - { - flags &= ~ flag_need_comma; - break; - } /* FALLTHRU */ - - default: - sprintf (error, "%u:%u: Unexpected `%c` in object", line_and_col, b); - goto e_failed; - }; - - break; - - case json_integer: - case json_double: - - if (isdigit ((unsigned char)b)) - { - ++ num_digits; - - if (top->type == json_integer || flags & flag_num_e) - { - if (! (flags & flag_num_e)) - { - if (flags & flag_num_zero) - { sprintf (error, "%u:%u: Unexpected `0` before `%c`", line_and_col, b); - goto e_failed; - } - - if (num_digits == 1 && b == '0') - flags |= flag_num_zero; - } - else - { - flags |= flag_num_e_got_sign; - num_e = (num_e * 10) + (b - '0'); - continue; - } - - if (would_overflow(top->u.integer, b)) - { - json_int_t integer = top->u.integer; - -- num_digits; - -- state.ptr; - top->type = json_double; - top->u.dbl = (double)integer; - continue; - } - - top->u.integer = (top->u.integer * 10) + (b - '0'); - continue; - } - - if (flags & flag_num_got_decimal) - num_fraction = (num_fraction * 10) + (b - '0'); - else - top->u.dbl = (top->u.dbl * 10) + (b - '0'); - - continue; - } - - if (b == '+' || b == '-') - { - if ( (flags & flag_num_e) && !(flags & flag_num_e_got_sign)) - { - flags |= flag_num_e_got_sign; - - if (b == '-') - flags |= flag_num_e_negative; - - continue; - } - } - else if (b == '.' && top->type == json_integer) - { - json_int_t integer = top->u.integer; - - if (!num_digits) - { sprintf (error, "%u:%u: Expected digit before `.`", line_and_col); - goto e_failed; - } - - top->type = json_double; - top->u.dbl = (double) integer; - - flags |= flag_num_got_decimal; - num_digits = 0; - continue; - } - - if (! (flags & flag_num_e)) - { - if (top->type == json_double) - { - if (!num_digits) - { sprintf (error, "%u:%u: Expected digit after `.`", line_and_col); - goto e_failed; - } - - top->u.dbl += num_fraction / pow (10.0, num_digits); - } - - if (b == 'e' || b == 'E') - { - flags |= flag_num_e; - - if (top->type == json_integer) - { - json_int_t integer = top->u.integer; - top->type = json_double; - top->u.dbl = (double) integer; - } - - num_digits = 0; - flags &= ~ flag_num_zero; - - continue; - } - } - else - { - if (!num_digits) - { sprintf (error, "%u:%u: Expected digit after `e`", line_and_col); - goto e_failed; - } - - top->u.dbl *= pow (10.0, (flags & flag_num_e_negative ? - num_e : num_e)); - } - - if (flags & flag_num_negative) - { - if (top->type == json_integer) - top->u.integer = - top->u.integer; - else - top->u.dbl = - top->u.dbl; - } - - flags |= flag_next | flag_reproc; - break; - - default: - break; - }; - } - - if (flags & flag_reproc) - { - flags &= ~ flag_reproc; - -- state.ptr; - } - - if (flags & flag_next) - { - flags = (flags & ~ flag_next) | flag_need_comma; - - if (!top->parent) - { - /* root value done */ - - flags |= flag_done; - continue; - } - - if (top->parent->type == json_array) - flags |= flag_seek_value; - - if (!state.first_pass) - { - json_value * parent = top->parent; - - switch (parent->type) - { - case json_object: - - parent->u.object.values - [parent->u.object.length].value = top; - - break; - - case json_array: - - parent->u.array.values - [parent->u.array.length] = top; - - break; - - default: - break; - }; - } - - if ( (++ top->parent->u.array.length) > UINT_MAX - 8) - goto e_overflow; - - top = top->parent; - - continue; - } - } - - alloc = root; - } - - return root; - -e_unknown_value: - - sprintf (error, "%u:%u: Unknown value", line_and_col); - goto e_failed; - -e_alloc_failure: - - strcpy (error, "Memory allocation failure"); - goto e_failed; - -e_overflow: - - sprintf (error, "%u:%u: Too long (caught overflow)", line_and_col); - goto e_failed; - -e_failed: - - if (error_buf) - { - if (*error) - strcpy (error_buf, error); - else - strcpy (error_buf, "Unknown error"); - } - - if (state.first_pass) - alloc = root; - - while (alloc) - { - top = alloc->_reserved.next_alloc; - state.settings.mem_free (alloc, state.settings.user_data); - alloc = top; - } - - if (!state.first_pass) - json_value_free_ex (&state.settings, root); - - return 0; -} - -json_value * json_parse (const json_char * json, size_t length) -{ - json_settings settings = { 0 }; - return json_parse_ex (&settings, json, length, 0); -} - -void json_value_free_ex (json_settings * settings, json_value * value) -{ - json_value * cur_value; - - if (!value) - return; - - value->parent = 0; - - while (value) - { - switch (value->type) - { - case json_array: - - if (!value->u.array.length) - { - settings->mem_free (value->u.array.values, settings->user_data); - break; - } - - value = value->u.array.values [-- value->u.array.length]; - continue; - - case json_object: - - if (!value->u.object.length) - { - settings->mem_free (value->u.object.values, settings->user_data); - break; - } - - value = value->u.object.values [-- value->u.object.length].value; - continue; - - case json_string: - - settings->mem_free (value->u.string.ptr, settings->user_data); - break; - - default: - break; - }; - - cur_value = value; - value = value->parent; - settings->mem_free (cur_value, settings->user_data); - } -} - -void json_value_free (json_value * value) -{ - json_settings settings = { 0 }; - settings.mem_free = default_free; - json_value_free_ex (&settings, value); -} diff --git a/bin/json.h b/bin/json.h deleted file mode 100644 index 1f6431614..000000000 --- a/bin/json.h +++ /dev/null @@ -1,288 +0,0 @@ - -/* vim: set et ts=3 sw=3 sts=3 ft=c: - * - * Copyright (C) 2012-2021 the json-parser authors All rights reserved. - * https://github.com/json-parser/json-parser - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef _JSON_H -#define _JSON_H - -#ifndef json_char - #define json_char char -#endif - -#ifndef json_int_t - #undef JSON_INT_T_OVERRIDDEN - #if defined(_MSC_VER) - #define json_int_t __int64 - #elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined(__cplusplus) && __cplusplus >= 201103L) - /* C99 and C++11 */ - #include - #define json_int_t int_fast64_t - #else - /* C89 */ - #define json_int_t long - #endif -#else - #define JSON_INT_T_OVERRIDDEN 1 -#endif - -#include - -#ifdef __cplusplus - - #include - - extern "C" - { - -#endif - -typedef struct -{ - unsigned long max_memory; /* should be size_t, but would modify the API */ - int settings; - - /* Custom allocator support (leave null to use malloc/free) - */ - - void * (* mem_alloc) (size_t, int zero, void * user_data); - void (* mem_free) (void *, void * user_data); - - void * user_data; /* will be passed to mem_alloc and mem_free */ - - size_t value_extra; /* how much extra space to allocate for values? */ - -} json_settings; - -#define json_enable_comments 0x01 - -typedef enum -{ - json_none, - json_object, - json_array, - json_integer, - json_double, - json_string, - json_boolean, - json_null - -} json_type; - -extern const struct _json_value json_value_none; - -typedef struct _json_object_entry -{ - json_char * name; - unsigned int name_length; - - struct _json_value * value; - -} json_object_entry; - -typedef struct _json_value -{ - struct _json_value * parent; - - json_type type; - - union - { - int boolean; - json_int_t integer; - double dbl; - - struct - { - unsigned int length; - json_char * ptr; /* null terminated */ - - } string; - - struct - { - unsigned int length; - - json_object_entry * values; - - #if defined(__cplusplus) - json_object_entry * begin () const - { return values; - } - json_object_entry * end () const - { return values + length; - } - #endif - - } object; - - struct - { - unsigned int length; - struct _json_value ** values; - - #if defined(__cplusplus) - _json_value ** begin () const - { return values; - } - _json_value ** end () const - { return values + length; - } - #endif - - } array; - - } u; - - union - { - struct _json_value * next_alloc; - void * object_mem; - - } _reserved; - - #ifdef JSON_TRACK_SOURCE - - /* Location of the value in the source JSON - */ - unsigned int line, col; - - #endif - - - /* Some C++ operator sugar */ - - #ifdef __cplusplus - - public: - - inline _json_value () - { memset (this, 0, sizeof (_json_value)); - } - - inline const struct _json_value &operator [] (int index) const - { - if (type != json_array || index < 0 - || ((unsigned int) index) >= u.array.length) - { - return json_value_none; - } - - return *u.array.values [index]; - } - - inline const struct _json_value &operator [] (const char * index) const - { - if (type != json_object) - return json_value_none; - - for (unsigned int i = 0; i < u.object.length; ++ i) - if (!strcmp (u.object.values [i].name, index)) - return *u.object.values [i].value; - - return json_value_none; - } - - inline operator const char * () const - { - switch (type) - { - case json_string: - return u.string.ptr; - - default: - return ""; - }; - } - - inline operator json_int_t () const - { - switch (type) - { - case json_integer: - return u.integer; - - case json_double: - return (json_int_t) u.dbl; - - default: - return 0; - }; - } - - inline operator bool () const - { - if (type != json_boolean) - return false; - - return u.boolean != 0; - } - - inline operator double () const - { - switch (type) - { - case json_integer: - return (double) u.integer; - - case json_double: - return u.dbl; - - default: - return 0; - }; - } - - #endif - -} json_value; - -json_value * json_parse (const json_char * json, - size_t length); - -#define json_error_max 128 -json_value * json_parse_ex (json_settings * settings, - const json_char * json, - size_t length, - char * error); - -void json_value_free (json_value *); - - -/* Not usually necessary, unless you used a custom mem_alloc and now want to - * use a custom mem_free. - */ -void json_value_free_ex (json_settings * settings, - json_value *); - - -#ifdef __cplusplus - } /* extern "C" */ -#endif - -#endif From 94545fecc107b8e41a1298a8404442f2d93ce7aa Mon Sep 17 00:00:00 2001 From: Krishna Chilleri Date: Tue, 14 May 2024 16:03:25 -0600 Subject: [PATCH 09/12] add json parser test file --- bin/ch-run.c | 1 - bin/cjson-parser.c | 106 +++++++++++++++++++++++++++ bin/config.json | 176 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 282 insertions(+), 1 deletion(-) create mode 100644 bin/cjson-parser.c create mode 100644 bin/config.json diff --git a/bin/ch-run.c b/bin/ch-run.c index 067432ee5..0df198ef5 100644 --- a/bin/ch-run.c +++ b/bin/ch-run.c @@ -209,7 +209,6 @@ int main(int argc, char *argv[]) break; case IMG_OCI_BUNDLE: /* Parse config.json file -> containerize */ - /* OR call ch-run-oci to create and start/run container */ args.c.newroot = path_join(args.c.img_ref, "/rootfs"); break; case IMG_SQUASH: diff --git a/bin/cjson-parser.c b/bin/cjson-parser.c new file mode 100644 index 000000000..8299b5991 --- /dev/null +++ b/bin/cjson-parser.c @@ -0,0 +1,106 @@ + +#include +#include +#include +#include + +void readJSONFile(const char *filename); +void iterJSONFile(cJSON *json); + +int main() { + const char *filename = "config.json"; + readJSONFile(filename); + return 0; +} + +void iterJSONFile(cJSON *json) { + + cJSON *proc_key = cJSON_GetObjectItemCaseSensitive(json, "process"); + cJSON *root_key = cJSON_GetObjectItemCaseSensitive(json, "root"); + + json = json->child; + + while (json != NULL) { + if (strcmp(json->string, "ociVersion") == 0) { + // validate oci Version + printf("ociVersion: %s\n", json->valuestring); + } else if (strcmp(json->string, "process") == 0) { + // child: env - set environment to PATH value, cwd corresponds to --cd + cJSON *env_key = cJSON_GetObjectItemCaseSensitive(proc_key, "env"); + printf("process env: %s\n", env_key->child->valuestring); + printf("process env: %s\n", env_key->child->next->valuestring); + cJSON *cwd_key = cJSON_GetObjectItemCaseSensitive(proc_key, "cwd"); + printf("process cwd: %s\n", cwd_key->valuestring); + } else if (strcmp(json->string, "root") == 0) { + // child: path (map to newroot in ch-run.c), readonly (ignore for now) + cJSON *path_key = cJSON_GetObjectItemCaseSensitive(root_key, "path"); + printf("root path: %s\n", path_key->valuestring); + cJSON *read_key = cJSON_GetObjectItemCaseSensitive(root_key, "readonly"); + //printf("root readonly: %s\n", read_key->valuestring); + } else if (strcmp(json->string, "hostname") == 0) { + printf("hostname key identified.\n"); + // ignore + } else if (strcmp(json->string, "mounts") == 0) { + printf("mounts key identified.\n"); + // check mount(2) + } else if (strcmp(json->string, "linux") == 0) { + printf("linux key identified.\n"); + } else { + printf("key name %s NOT identified.\n", json->string); + } + json = json->next; + } +} + +void readJSONFile(const char *filename) { + + FILE *file = fopen(filename, "r"); + long length = 0; + char *buffer = NULL; + + if (file == NULL) { + fprintf(stderr, "Error: could not open file %s\n", filename); + return; + } + + // Get the file length + fseek(file, 0, SEEK_END); + length = ftell(file); + fseek(file, 0, SEEK_SET); + // Allocate content buffer + buffer = (char *)malloc((size_t)length + sizeof("")); + fread(buffer, sizeof(char), (size_t)length, file); + // Null-terminate the string + buffer[length] = '\0'; + + fclose(file); + + // Parse the JSON data + cJSON *json = cJSON_Parse(buffer); + // Check if parsing was successful + if (json == NULL) { + const char *error_ptr = cJSON_GetErrorPtr(); + if (error_ptr != NULL) { + fprintf(stderr, "Error before: %s\n", error_ptr); + } + cJSON_Delete(json); + free(buffer); + return; + } + + // Print the JSON data + char *json_tree = cJSON_Print(json); + if (json_tree == NULL) + { + fprintf(stderr, "Failed to print JSON tree.\n"); + } + //printf("%s\n", json_tree); + + // Process the JSON data + iterJSONFile(json); + + // Clean up + cJSON_Delete(json); + free(buffer); + free(json_tree); +} diff --git a/bin/config.json b/bin/config.json new file mode 100644 index 000000000..754fae2d1 --- /dev/null +++ b/bin/config.json @@ -0,0 +1,176 @@ +{ + "ociVersion": "1.0.2-dev", + "process": { + "terminal": true, + "user": {}, + + "args": [ + "sh", "redis-server", "--bind", "0.0.0.0" + ], + "env": [ + "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + "TERM=xterm" + ], + "cwd": "/", + "capabilities": { + "bounding": [ + "CAP_AUDIT_WRITE", + "CAP_KILL", + "CAP_NET_BIND_SERVICE" + ], + "effective": [ + "CAP_AUDIT_WRITE", + "CAP_KILL", + "CAP_NET_BIND_SERVICE" + ], + "permitted": [ + "CAP_AUDIT_WRITE", + "CAP_KILL", + "CAP_NET_BIND_SERVICE" + ], + "ambient": [ + "CAP_AUDIT_WRITE", + "CAP_KILL", + "CAP_NET_BIND_SERVICE" + ] + }, + "rlimits": [ + { + "type": "RLIMIT_NOFILE", + "hard": 1024, + "soft": 1024 + } + ], + "noNewPrivileges": true + }, + "root": { + "path": "rootfs", + "readonly": true + }, + "hostname": "runc", + "mounts": [ + { + "destination": "/proc", + "type": "proc", + "source": "proc" + }, + { + "destination": "/dev", + "type": "tmpfs", + "source": "tmpfs", + "options": [ + "nosuid", + "strictatime", + "mode=755", + "size=65536k" + ] + }, + { + "destination": "/dev/pts", + "type": "devpts", + "source": "devpts", + "options": [ + "nosuid", + "noexec", + "newinstance", + "ptmxmode=0666", + "mode=0620", + "gid=5" + ] + }, + { + "destination": "/dev/shm", + "type": "tmpfs", + "source": "shm", + "options": [ + "nosuid", + "noexec", + "nodev", + "mode=1777", + "size=65536k" + ] + }, + { + "destination": "/dev/mqueue", + "type": "mqueue", + "source": "mqueue", + "options": [ + "nosuid", + "noexec", + "nodev" + ] + }, + { + "destination": "/sys", + "type": "sysfs", + "source": "sysfs", + "options": [ + "nosuid", + "noexec", + "nodev", + "ro" + ] + }, + { + "destination": "/sys/fs/cgroup", + "type": "cgroup", + "source": "cgroup", + "options": [ + "nosuid", + "noexec", + "nodev", + "relatime", + "ro" + ] + } + ], + "linux": { + "resources": { + "devices": [ + { + "allow": false, + "access": "rwm" + } + ] + }, + "namespaces": [ + { + "type": "pid" + }, + { + "type": "network" + }, + { + "type": "ipc" + }, + { + "type": "uts" + }, + { + "type": "mount" + }, + { + "type": "cgroup" + } + ], + "maskedPaths": [ + "/proc/acpi", + "/proc/asound", + "/proc/kcore", + "/proc/keys", + "/proc/latency_stats", + "/proc/timer_list", + "/proc/timer_stats", + "/proc/sched_debug", + "/sys/firmware", + "/proc/scsi" + ], + "readonlyPaths": [ + "/proc/bus", + "/proc/fs", + "/proc/irq", + "/proc/sys", + "/proc/sysrq-trigger" + ] + } +} From beb4ee8116f7638249bfdf4e25089670490e2a99 Mon Sep 17 00:00:00 2001 From: Krishna Chilleri Date: Mon, 20 May 2024 10:29:36 -0600 Subject: [PATCH 10/12] adaptation of Reid's suggested table-based approach for iterating through JSON files using cJSON library --- bin/cjson-parser.c | 145 ++++++++++++++++++++++++++++++--------------- 1 file changed, 96 insertions(+), 49 deletions(-) diff --git a/bin/cjson-parser.c b/bin/cjson-parser.c index 8299b5991..0a9ad7436 100644 --- a/bin/cjson-parser.c +++ b/bin/cjson-parser.c @@ -4,8 +4,42 @@ #include #include + +struct json_dispatch { + char *name; + struct json_dispatch *children; + void (*f)(cJSON *); +}; + + void readJSONFile(const char *filename); void iterJSONFile(cJSON *json); +void visit(struct json_dispatch actions[], cJSON *json); +void dispatch(struct json_dispatch action, cJSON *json); +void oci_ociVersion(cJSON *json); +void oci_env(cJSON *json); +void oci_cwd(cJSON *json); +void oci_path(cJSON *json); +void oci_readonly(cJSON *json); + + +struct json_dispatch oci_process[] = { + { "env", NULL, oci_env }, + { "cwd", NULL, oci_cwd }, + { } +}; +struct json_dispatch oci_root[] = { + { "path", NULL, oci_path }, + { "readonly", NULL, oci_readonly }, + { } +}; +struct json_dispatch oci_top[] = { + { "ociVersion", NULL, oci_ociVersion }, + { "process", oci_process }, + { "root", oci_root }, + { } +}; + int main() { const char *filename = "config.json"; @@ -13,50 +47,12 @@ int main() { return 0; } -void iterJSONFile(cJSON *json) { - - cJSON *proc_key = cJSON_GetObjectItemCaseSensitive(json, "process"); - cJSON *root_key = cJSON_GetObjectItemCaseSensitive(json, "root"); - - json = json->child; - - while (json != NULL) { - if (strcmp(json->string, "ociVersion") == 0) { - // validate oci Version - printf("ociVersion: %s\n", json->valuestring); - } else if (strcmp(json->string, "process") == 0) { - // child: env - set environment to PATH value, cwd corresponds to --cd - cJSON *env_key = cJSON_GetObjectItemCaseSensitive(proc_key, "env"); - printf("process env: %s\n", env_key->child->valuestring); - printf("process env: %s\n", env_key->child->next->valuestring); - cJSON *cwd_key = cJSON_GetObjectItemCaseSensitive(proc_key, "cwd"); - printf("process cwd: %s\n", cwd_key->valuestring); - } else if (strcmp(json->string, "root") == 0) { - // child: path (map to newroot in ch-run.c), readonly (ignore for now) - cJSON *path_key = cJSON_GetObjectItemCaseSensitive(root_key, "path"); - printf("root path: %s\n", path_key->valuestring); - cJSON *read_key = cJSON_GetObjectItemCaseSensitive(root_key, "readonly"); - //printf("root readonly: %s\n", read_key->valuestring); - } else if (strcmp(json->string, "hostname") == 0) { - printf("hostname key identified.\n"); - // ignore - } else if (strcmp(json->string, "mounts") == 0) { - printf("mounts key identified.\n"); - // check mount(2) - } else if (strcmp(json->string, "linux") == 0) { - printf("linux key identified.\n"); - } else { - printf("key name %s NOT identified.\n", json->string); - } - json = json->next; - } -} void readJSONFile(const char *filename) { - FILE *file = fopen(filename, "r"); - long length = 0; + FILE *file = fopen(filename, "rb"); char *buffer = NULL; + size_t length, file_len; if (file == NULL) { fprintf(stderr, "Error: could not open file %s\n", filename); @@ -68,10 +64,9 @@ void readJSONFile(const char *filename) { length = ftell(file); fseek(file, 0, SEEK_SET); // Allocate content buffer - buffer = (char *)malloc((size_t)length + sizeof("")); - fread(buffer, sizeof(char), (size_t)length, file); - // Null-terminate the string - buffer[length] = '\0'; + buffer = malloc(length); + file_len = fread(buffer, 1, length, file); + printf("Read %lu bytes of %lu\n", file_len, length); fclose(file); @@ -83,9 +78,7 @@ void readJSONFile(const char *filename) { if (error_ptr != NULL) { fprintf(stderr, "Error before: %s\n", error_ptr); } - cJSON_Delete(json); - free(buffer); - return; + goto end; } // Print the JSON data @@ -97,10 +90,64 @@ void readJSONFile(const char *filename) { //printf("%s\n", json_tree); // Process the JSON data - iterJSONFile(json); + visit(oci_top, json); // Clean up +end: cJSON_Delete(json); free(buffer); - free(json_tree); +} + +void dispatch(struct json_dispatch action, cJSON *json) { + if (action.f != NULL) + action.f(json); + if (action.children != NULL) + visit(action.children, json); +} + + +void visit(struct json_dispatch actions[], cJSON *json) { + for (int i =0; actions[i].name != NULL; i++) { + cJSON *subtree = cJSON_GetObjectItem(json, actions[i].name); + if (cJSON_IsArray(subtree)) { + cJSON *elem; + cJSON_ArrayForEach(elem, subtree) + dispatch(actions[i], elem); + } else { + dispatch(actions[i], subtree); + } + } +} + +void oci_ociVersion(cJSON *json) { + printf("oci_ociVersion: %s\n", json->valuestring); +} + + +void oci_env(cJSON *json) { + printf("oci_env: %s\n", json->valuestring); +} + + +void oci_cwd(cJSON *json) { + printf("oci_cwd: %s\n", json->valuestring); +} + + +void oci_path(cJSON *json) { + printf("oci_path: %s\n", json->valuestring); +} + + +void oci_readonly(cJSON *json) { + // json->root->readonly is a boolean + const char *bool_to_str; + + if (cJSON_IsTrue(json)) { + bool_to_str = "true"; + } if (cJSON_IsFalse(json)) { + bool_to_str = "false"; + } + + printf("oci_readonly: %s\n", bool_to_str); } From 178208ad27d8bbb82bd4224bb6950bd54e1d9b26 Mon Sep 17 00:00:00 2001 From: Krishna Chilleri Date: Tue, 4 Jun 2024 15:03:25 -0600 Subject: [PATCH 11/12] map json file specs to Charliecloud arguments - issue --- bin/ch-run.c | 178 ++++++++++++++++++++++++++++++++++++++++++++- bin/ch_core.c | 9 ++- bin/cjson-parser.c | 153 -------------------------------------- 3 files changed, 181 insertions(+), 159 deletions(-) delete mode 100644 bin/cjson-parser.c diff --git a/bin/ch-run.c b/bin/ch-run.c index d47033f5a..8dc4c2b48 100644 --- a/bin/ch-run.c +++ b/bin/ch-run.c @@ -16,6 +16,8 @@ #include "ch_core.h" #include "ch_misc.h" +#include "cJSON.h" + /** Constants and macros **/ /* Environment variables used by --join parameters. */ @@ -62,6 +64,7 @@ const struct argp_option options[] = { { "test", -17, "TEST", 0, "do test TEST" }, { "mount", 'm', "DIR", 0, "SquashFS mount point"}, { "no-passwd", -9, 0, 0, "don't bind-mount /etc/{passwd,group}"}, + { "oci", 'o', 0, 0, "run as an oci bundle" }, { "private-tmp", 't', 0, 0, "use container-private /tmp" }, { "quiet", 'q', 0, 0, "print less output (can be repeated)"}, #ifdef HAVE_SECCOMP @@ -114,6 +117,38 @@ void privs_verify_invoking(); char *storage_default(void); extern void warnings_reprint(void); +struct json_dispatch { + char *name; + struct json_dispatch *children; + void (*f)(cJSON *, struct args *args); +}; + +void readJSONFile(const char *filename, struct args *args); +void visit(struct json_dispatch actions[], cJSON *json, struct args *args); +void dispatch(struct json_dispatch action, cJSON *json, struct args *args); +void oci_ociVersion(cJSON *json, struct args *args); +void oci_env(cJSON *json, struct args *args); +void oci_cwd(cJSON *json, struct args *args); +void oci_path(cJSON *json, struct args *args); +void oci_readonly(cJSON *json, struct args *args); + +struct json_dispatch oci_process[] = { + { "env", NULL, oci_env }, + { "cwd", NULL, oci_cwd }, + { } +}; +struct json_dispatch oci_root[] = { + { "path", NULL, oci_path }, + { "readonly", NULL, oci_readonly }, + { } +}; +struct json_dispatch oci_top[] = { + { "ociVersion", NULL, oci_ociVersion }, + { "process", oci_process }, + { "root", oci_root }, + { } +}; + /** Global variables **/ @@ -193,7 +228,10 @@ int main(int argc, char *argv[]) args.c.img_ref = argv[arg_next++]; args.c.newroot = realpath_(args.c.newroot, true); args.storage_dir = realpath_(args.storage_dir, true); - args.c.type = image_type(args.c.img_ref, args.storage_dir); + + if (args.c.type != IMG_OCI_BUNDLE) { + args.c.type = image_type(args.c.img_ref, args.storage_dir); + } switch (args.c.type) { case IMG_DIRECTORY: @@ -209,7 +247,15 @@ int main(int argc, char *argv[]) break; case IMG_OCI_BUNDLE: /* Parse config.json file -> containerize */ - args.c.newroot = path_join(args.c.img_ref, "/rootfs"); + char *rootfs = path_join(args.c.img_ref, "rootfs"); + char *conff = path_join(args.c.img_ref, "config.json"); + + Tf (path_exists(rootfs, NULL, true), "%s: No such file or directory", rootfs); + Tf (path_exists(conff, NULL, true), "%s: No such file or directory", conff); + //printf("initial dir before: %s\n", args.initial_dir); + readJSONFile(conff, &args); + //args.c.newroot = rootfs; + printf("args.initial_dir is: %s\n", args.initial_dir); break; case IMG_SQUASH: #ifndef HAVE_LIBSQUASHFUSE @@ -531,6 +577,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) } break; case 'c': // --cd + printf("key is: %d\n", key); args->initial_dir = arg; break; case 'g': // --gid @@ -545,6 +592,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) Ze ((arg[0] == '\0'), "mount point can't be empty string"); args->c.newroot = arg; break; + case 'o': // --oci + args->c.type = IMG_OCI_BUNDLE; + break; case 's': // --storage args->storage_dir = arg; if (!path_exists(arg, NULL, false)) @@ -649,3 +699,127 @@ char *storage_default(void) return storage; } + +void readJSONFile(const char *filename, struct args *args) { + + FILE *file = fopen(filename, "rb"); + char *buffer = NULL; + size_t length; + size_t file_len; + + if (file == NULL) { + fprintf(stderr, "Error: could not open file %s\n", filename); + return; + } + + // Get the file length + fseek(file, 0, SEEK_END); + length = ftell(file); + fseek(file, 0, SEEK_SET); + // Allocate content buffer + buffer = malloc(length); + file_len = fread(buffer, 1, length, file); + printf("Read %lu bytes of %lu\n", file_len, length); + + fclose(file); + + // Parse the JSON data + cJSON *json = cJSON_Parse(buffer); + // Check if parsing was successful + if (json == NULL) { + const char *error_ptr = cJSON_GetErrorPtr(); + if (error_ptr != NULL) { + fprintf(stderr, "Error before: %s\n", error_ptr); + } + goto end; + } + + // Print the JSON data + char *json_tree = cJSON_Print(json); + if (json_tree == NULL) + { + fprintf(stderr, "Failed to print JSON tree.\n"); + } + //printf("%s\n", json_tree); + + // Process the JSON data + visit(oci_top, json, args); + + // Clean up +end: + cJSON_Delete(json); + free(buffer); +} + +void dispatch(struct json_dispatch action, cJSON *json, struct args *args) { + if (action.f != NULL) + action.f(json, args); + if (action.children != NULL) + visit(action.children, json, args); +} + + +void visit(struct json_dispatch actions[], cJSON *json, struct args *args) { + for (int i =0; actions[i].name != NULL; i++) { + cJSON *subtree = cJSON_GetObjectItem(json, actions[i].name); + if (cJSON_IsArray(subtree)) { + cJSON *elem; + cJSON_ArrayForEach(elem, subtree) + dispatch(actions[i], elem, args); + } else { + dispatch(actions[i], subtree, args); + } + } +} + +void oci_ociVersion(cJSON *json, struct args *args) { + // Need to validate this version. Not sure how just yet. + printf("oci_ociVersion: %s\n", json->valuestring); +} + + +void oci_env(cJSON *json, struct args *args) { + // TO DO: corresponds to --set-env + printf("oci_env: %s\n", json->valuestring); +} + + +void oci_cwd(cJSON *json, struct args *args) { + // corresponds to --cd + //printf("oci_cwd: %s\n", json->valuestring); + if (args->initial_dir == NULL) { + args->initial_dir = json->valuestring; + } + //printf("after assignment in oci_cwd: %c\n",json->valuestring); + printf("oci_cwd is: %s\n", args->initial_dir); +} + + +void oci_path(cJSON *json, struct args *args) { + //printf("oci_path: %s\n", json->valuestring); + + args->c.newroot = json->valuestring; + + if (!path_exists(args->c.newroot, NULL, true)) { + args->c.newroot = path_join(args->c.img_ref, json->valuestring); + } + + //printf("args.c.newroot in oci_path function is: %s\n", args->c.newroot); +} + + +void oci_readonly(cJSON *json, struct args *args) { + /*const char *bool_to_str; + + if (cJSON_IsTrue(json)) { + bool_to_str = "true"; + } if (cJSON_IsFalse(json)) { + bool_to_str = "false"; + }*/ + + //printf("oci_readonly: %s\n", bool_to_str); + + if (cJSON_IsFalse(json)) { + args->c.writable = true; + } +} diff --git a/bin/ch_core.c b/bin/ch_core.c index 747a4310e..7be315280 100644 --- a/bin/ch_core.c +++ b/bin/ch_core.c @@ -391,8 +391,8 @@ enum img_type image_type(const char *ref, const char *storage_dir) struct stat st; FILE *fp; char magic[4]; // four bytes, not a string - char *conff = path_join(ref, "/config.json"); - char *rootfs = path_join(ref, "/rootfs"); + //char *conff = path_join(ref, "/config.json"); + //char *rootfs = path_join(ref, "/rootfs"); // If there’s a directory in storage where we would expect there to be if // ref were an image name, assume it really is an image name. @@ -406,11 +406,12 @@ enum img_type image_type(const char *ref, const char *storage_dir) // If ref is the path to a directory that contains rootfs directory // and config.json file, assume it is an oci bundle if (S_ISDIR(st.st_mode)) { - if (path_exists(rootfs, NULL, true) && path_exists(conff, NULL, true)) { + /*if (path_exists(rootfs, NULL, true) && path_exists(conff, NULL, true)) { return IMG_OCI_BUNDLE; } else { return IMG_DIRECTORY; - } + }*/ + return IMG_DIRECTORY; } // Now we know it’s file-like enough to read. See if it has the SquashFS diff --git a/bin/cjson-parser.c b/bin/cjson-parser.c deleted file mode 100644 index 0a9ad7436..000000000 --- a/bin/cjson-parser.c +++ /dev/null @@ -1,153 +0,0 @@ - -#include -#include -#include -#include - - -struct json_dispatch { - char *name; - struct json_dispatch *children; - void (*f)(cJSON *); -}; - - -void readJSONFile(const char *filename); -void iterJSONFile(cJSON *json); -void visit(struct json_dispatch actions[], cJSON *json); -void dispatch(struct json_dispatch action, cJSON *json); -void oci_ociVersion(cJSON *json); -void oci_env(cJSON *json); -void oci_cwd(cJSON *json); -void oci_path(cJSON *json); -void oci_readonly(cJSON *json); - - -struct json_dispatch oci_process[] = { - { "env", NULL, oci_env }, - { "cwd", NULL, oci_cwd }, - { } -}; -struct json_dispatch oci_root[] = { - { "path", NULL, oci_path }, - { "readonly", NULL, oci_readonly }, - { } -}; -struct json_dispatch oci_top[] = { - { "ociVersion", NULL, oci_ociVersion }, - { "process", oci_process }, - { "root", oci_root }, - { } -}; - - -int main() { - const char *filename = "config.json"; - readJSONFile(filename); - return 0; -} - - -void readJSONFile(const char *filename) { - - FILE *file = fopen(filename, "rb"); - char *buffer = NULL; - size_t length, file_len; - - if (file == NULL) { - fprintf(stderr, "Error: could not open file %s\n", filename); - return; - } - - // Get the file length - fseek(file, 0, SEEK_END); - length = ftell(file); - fseek(file, 0, SEEK_SET); - // Allocate content buffer - buffer = malloc(length); - file_len = fread(buffer, 1, length, file); - printf("Read %lu bytes of %lu\n", file_len, length); - - fclose(file); - - // Parse the JSON data - cJSON *json = cJSON_Parse(buffer); - // Check if parsing was successful - if (json == NULL) { - const char *error_ptr = cJSON_GetErrorPtr(); - if (error_ptr != NULL) { - fprintf(stderr, "Error before: %s\n", error_ptr); - } - goto end; - } - - // Print the JSON data - char *json_tree = cJSON_Print(json); - if (json_tree == NULL) - { - fprintf(stderr, "Failed to print JSON tree.\n"); - } - //printf("%s\n", json_tree); - - // Process the JSON data - visit(oci_top, json); - - // Clean up -end: - cJSON_Delete(json); - free(buffer); -} - -void dispatch(struct json_dispatch action, cJSON *json) { - if (action.f != NULL) - action.f(json); - if (action.children != NULL) - visit(action.children, json); -} - - -void visit(struct json_dispatch actions[], cJSON *json) { - for (int i =0; actions[i].name != NULL; i++) { - cJSON *subtree = cJSON_GetObjectItem(json, actions[i].name); - if (cJSON_IsArray(subtree)) { - cJSON *elem; - cJSON_ArrayForEach(elem, subtree) - dispatch(actions[i], elem); - } else { - dispatch(actions[i], subtree); - } - } -} - -void oci_ociVersion(cJSON *json) { - printf("oci_ociVersion: %s\n", json->valuestring); -} - - -void oci_env(cJSON *json) { - printf("oci_env: %s\n", json->valuestring); -} - - -void oci_cwd(cJSON *json) { - printf("oci_cwd: %s\n", json->valuestring); -} - - -void oci_path(cJSON *json) { - printf("oci_path: %s\n", json->valuestring); -} - - -void oci_readonly(cJSON *json) { - // json->root->readonly is a boolean - const char *bool_to_str; - - if (cJSON_IsTrue(json)) { - bool_to_str = "true"; - } if (cJSON_IsFalse(json)) { - bool_to_str = "false"; - } - - printf("oci_readonly: %s\n", bool_to_str); -} From 192b2d1dbae5a0447a1624f1847ab00ce6851a10 Mon Sep 17 00:00:00 2001 From: Krishna Chilleri Date: Mon, 10 Jun 2024 13:27:38 -0600 Subject: [PATCH 12/12] working version [skip ci] --- bin/ch-run.c | 64 ++++++++++++++++----------------------------------- bin/ch_core.c | 9 -------- 2 files changed, 20 insertions(+), 53 deletions(-) diff --git a/bin/ch-run.c b/bin/ch-run.c index 8dc4c2b48..e207cb016 100644 --- a/bin/ch-run.c +++ b/bin/ch-run.c @@ -98,6 +98,7 @@ struct args { #ifdef HAVE_SECCOMP bool seccomp_p; #endif + char *oci_version; char *storage_dir; bool unsafe; }; @@ -117,6 +118,9 @@ void privs_verify_invoking(); char *storage_default(void); extern void warnings_reprint(void); + +/** Types and function prototypes for running an OCI bundle */ + struct json_dispatch { char *name; struct json_dispatch *children; @@ -206,6 +210,7 @@ int main(int argc, char *argv[]) #ifdef HAVE_SECCOMP .seccomp_p = false, #endif + .oci_version = NULL, .storage_dir = storage_default(), .unsafe = false }; @@ -246,16 +251,14 @@ int main(int argc, char *argv[]) "--write invalid when running by name"); break; case IMG_OCI_BUNDLE: - /* Parse config.json file -> containerize */ + // Parse config.json file and distribute argument values to container char *rootfs = path_join(args.c.img_ref, "rootfs"); char *conff = path_join(args.c.img_ref, "config.json"); Tf (path_exists(rootfs, NULL, true), "%s: No such file or directory", rootfs); Tf (path_exists(conff, NULL, true), "%s: No such file or directory", conff); - //printf("initial dir before: %s\n", args.initial_dir); + readJSONFile(conff, &args); - //args.c.newroot = rootfs; - printf("args.initial_dir is: %s\n", args.initial_dir); break; case IMG_SQUASH: #ifndef HAVE_LIBSQUASHFUSE @@ -577,7 +580,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) } break; case 'c': // --cd - printf("key is: %d\n", key); args->initial_dir = arg; break; case 'g': // --gid @@ -705,7 +707,6 @@ void readJSONFile(const char *filename, struct args *args) { FILE *file = fopen(filename, "rb"); char *buffer = NULL; size_t length; - size_t file_len; if (file == NULL) { fprintf(stderr, "Error: could not open file %s\n", filename); @@ -718,8 +719,7 @@ void readJSONFile(const char *filename, struct args *args) { fseek(file, 0, SEEK_SET); // Allocate content buffer buffer = malloc(length); - file_len = fread(buffer, 1, length, file); - printf("Read %lu bytes of %lu\n", file_len, length); + fread(buffer, 1, length, file); fclose(file); @@ -734,21 +734,13 @@ void readJSONFile(const char *filename, struct args *args) { goto end; } - // Print the JSON data - char *json_tree = cJSON_Print(json); - if (json_tree == NULL) - { - fprintf(stderr, "Failed to print JSON tree.\n"); - } - //printf("%s\n", json_tree); - // Process the JSON data visit(oci_top, json, args); - // Clean up + // Clean up end: - cJSON_Delete(json); - free(buffer); + cJSON_Delete(json); + free(buffer); } void dispatch(struct json_dispatch action, cJSON *json, struct args *args) { @@ -773,52 +765,36 @@ void visit(struct json_dispatch actions[], cJSON *json, struct args *args) { } void oci_ociVersion(cJSON *json, struct args *args) { - // Need to validate this version. Not sure how just yet. - printf("oci_ociVersion: %s\n", json->valuestring); + // Log oci version just in case + args->oci_version = strdup(json->valuestring); } void oci_env(cJSON *json, struct args *args) { - // TO DO: corresponds to --set-env - printf("oci_env: %s\n", json->valuestring); + // Corresponds to --set-env + parse_set_env(args, json->valuestring, '\n'); } void oci_cwd(cJSON *json, struct args *args) { - // corresponds to --cd - //printf("oci_cwd: %s\n", json->valuestring); + // Corresponds to --cd if (args->initial_dir == NULL) { - args->initial_dir = json->valuestring; + args->initial_dir = strdup(json->valuestring); } - //printf("after assignment in oci_cwd: %c\n",json->valuestring); - printf("oci_cwd is: %s\n", args->initial_dir); } void oci_path(cJSON *json, struct args *args) { - //printf("oci_path: %s\n", json->valuestring); - - args->c.newroot = json->valuestring; - + args->c.newroot = strdup(json->valuestring); + // Takes care of absolute/relative paths if (!path_exists(args->c.newroot, NULL, true)) { args->c.newroot = path_join(args->c.img_ref, json->valuestring); } - - //printf("args.c.newroot in oci_path function is: %s\n", args->c.newroot); } void oci_readonly(cJSON *json, struct args *args) { - /*const char *bool_to_str; - - if (cJSON_IsTrue(json)) { - bool_to_str = "true"; - } if (cJSON_IsFalse(json)) { - bool_to_str = "false"; - }*/ - - //printf("oci_readonly: %s\n", bool_to_str); - + // Corresponds to --write if readonly is false if (cJSON_IsFalse(json)) { args->c.writable = true; } diff --git a/bin/ch_core.c b/bin/ch_core.c index 7be315280..a19dc72d1 100644 --- a/bin/ch_core.c +++ b/bin/ch_core.c @@ -391,8 +391,6 @@ enum img_type image_type(const char *ref, const char *storage_dir) struct stat st; FILE *fp; char magic[4]; // four bytes, not a string - //char *conff = path_join(ref, "/config.json"); - //char *rootfs = path_join(ref, "/rootfs"); // If there’s a directory in storage where we would expect there to be if // ref were an image name, assume it really is an image name. @@ -403,14 +401,7 @@ enum img_type image_type(const char *ref, const char *storage_dir) Zf (stat(ref, &st), "can't stat: %s", ref); // If ref is the path to a directory, then it’s a directory. - // If ref is the path to a directory that contains rootfs directory - // and config.json file, assume it is an oci bundle if (S_ISDIR(st.st_mode)) { - /*if (path_exists(rootfs, NULL, true) && path_exists(conff, NULL, true)) { - return IMG_OCI_BUNDLE; - } else { - return IMG_DIRECTORY; - }*/ return IMG_DIRECTORY; }