]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-json: add SD_JSON_PARSE_SEEK0 flag
authorLennart Poettering <lennart@amutable.com>
Thu, 14 May 2026 06:45:35 +0000 (08:45 +0200)
committerLennart Poettering <lennart@amutable.com>
Mon, 18 May 2026 06:51:09 +0000 (08:51 +0200)
src/libsystemd/sd-json/sd-json.c
src/systemd/sd-json.h

index a7ff526bc8ed8ec937ca3cf483e466d9d993dddf..e95ff685228df7acd53e2ed348040d7ce1b2d04a 100644 (file)
@@ -3502,9 +3502,12 @@ _public_ int sd_json_parse_file_at(
         _cleanup_free_ char *text = NULL;
         int r;
 
-        if (f)
+        if (f) {
+                if (FLAGS_SET(flags, SD_JSON_PARSE_SEEK0) && fseek(f, /* offset= */ 0, SEEK_SET) < 0)
+                        return -errno;
+
                 r = read_full_stream(f, &text, NULL);
-        else
+        else
                 r = read_full_file_full(dir_fd, path, UINT64_MAX, SIZE_MAX, 0, NULL, &text, NULL);
         if (r < 0)
                 return r;
index 6a1977549098f65c140234161a31195009d80807..dc71871872ec7294fb29c00aa376ee4aa6f2613b 100644 (file)
@@ -184,6 +184,7 @@ __extension__ typedef enum _SD_ENUM_TYPE_S64(sd_json_parse_flags_t) {
         SD_JSON_PARSE_SENSITIVE      = 1 << 0, /* mark variant as "sensitive", i.e. something containing secret key material or such */
         SD_JSON_PARSE_MUST_BE_OBJECT = 1 << 1, /* refuse parsing if top-level is not an object */
         SD_JSON_PARSE_MUST_BE_ARRAY  = 1 << 2, /* refuse parsing if top-level is not an array */
+        SD_JSON_PARSE_SEEK0          = 1 << 3, /* seek to offset 0 before reading */
         _SD_ENUM_FORCE_S64(JSON_PARSE_FLAGS)
 } sd_json_parse_flags_t;