Skip to content

sd-json: add sd_json_parse_fd() + flags#42136

Merged
bluca merged 6 commits into
systemd:mainfrom
poettering:sd-json-parse-fd
May 18, 2026
Merged

sd-json: add sd_json_parse_fd() + flags#42136
bluca merged 6 commits into
systemd:mainfrom
poettering:sd-json-parse-fd

Conversation

@poettering
Copy link
Copy Markdown
Member

In particular in the recent LUO work we started to read JSON a lot from fds, let's add some helpers to make that simpler.

No change in behaviour, just helpers to shorten code.

@poettering poettering added tree-wide please-review PR is ready for (re-)review by a maintainer sd-json claude-review labels May 17, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 17, 2026

Claude review of PR #42136 (914c41a)

Must fix

  • Unused FILE *f variablesrc/shared/luo-util.c:142 — the _cleanup_fclose_ FILE *f declaration is now unused after switching to sd_json_parse_fd(), will fail with -Werror

Suggestions

  • Missing fd validationsrc/libsystemd/sd-json/sd-json.c:3540sd_json_parse_fd() lacks the assert_return(fd >= 0, -EBADF) that other public API functions consistently use
  • Inaccurate file offset documentationman/sd_json_parse.xml:165 — claims the caller's fd offset is left untouched, but F_DUPFD_CLOEXEC shares the offset with the original
  • Missing history entriesman/sd_json_parse.xml:300SD_JSON_PARSE_MUST_BE_OBJECT and SD_JSON_PARSE_MUST_BE_ARRAY have v261 markers in the body but are missing from the History section

Nits

  • Stale flags passed downstreamsrc/libsystemd/sd-json/sd-json.c:3565 — fd-specific flags are passed to sd_json_parse_file where they're meaningless; should be stripped like SD_JSON_PARSE_SEEK0 is
  • Misleading error on fd reopen failuresrc/resolve/resolved-static-records.c:99 — collapsing open+parse into one call means an fd reopen failure reports as "Failed to parse JSON file"
  • Trivially-true ASSERT_NULL in tests (dismissed)

Workflow run

Comment thread src/shared/luo-util.c
Comment thread src/libsystemd/sd-json/sd-json.c
Comment thread man/sd_json_parse.xml Outdated
Comment thread src/libsystemd/sd-json/sd-json.c
Copy link
Copy Markdown
Member

@yuwata yuwata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except for the missing assertion and unused f reported by Claude, and clang-tidy test failures.

@yuwata yuwata added good-to-merge/with-minor-suggestions and removed please-review PR is ready for (re-)review by a maintainer labels May 17, 2026
@yuwata yuwata added this to the v261 milestone May 17, 2026
Comment thread man/sd_json_parse.xml Outdated
Comment thread src/resolve/resolved-static-records.c
@poettering poettering added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed good-to-merge/with-minor-suggestions labels May 18, 2026
Comment thread src/libsystemd/sd-json/test-json.c
@bluca
Copy link
Copy Markdown
Member

bluca commented May 18, 2026

1 warning generated.
../src/core/luo.c:8:1: error: included header fileio.h is not used directly [misc-include-cleaner,-warnings-as-errors]
    8 | #include "fileio.h"
      | ^~~~~~~~~~~~~~~~~~~
    9 | #include "json-util.h"
Suppressed 1 warnings (1 NOLINT).
1 warning treated as error
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

2019/2838 clang-tidy - systemd:clang-tidy-networkd-serialize.c                        FAIL            0.35s   exit status 1
>>> ASAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1 MALLOC_PERTURB_=189 UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 MSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 MESON_TEST_ITERATION=1 /usr/sbin/clang-tidy -p /home/runner/work/systemd/systemd/build /home/runner/work/systemd/systemd/build/../src/network/networkd-serialize.c
――――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――――――――――――――――――――
1 warning generated.
../src/network/networkd-serialize.c:8:1: error: included header fileio.h is not used directly [misc-include-cleaner,-warnings-as-errors]
    8 | #include "fileio.h"
      | ^~~~~~~~~~~~~~~~~~~
    9 | #include "hashmap.h"
Suppressed 1 warnings (1 NOLINT).
1 warning treated as error

@bluca bluca force-pushed the sd-json-parse-fd branch from 3fc8b47 to 914c41a Compare May 18, 2026 09:39
@bluca
Copy link
Copy Markdown
Member

bluca commented May 18, 2026

1 warning generated.
../src/core/luo.c:8:1: error: included header fileio.h is not used directly [misc-include-cleaner,-warnings-as-errors]
    8 | #include "fileio.h"
      | ^~~~~~~~~~~~~~~~~~~
    9 | #include "json-util.h"
Suppressed 1 warnings (1 NOLINT).
1 warning treated as error
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

2019/2838 clang-tidy - systemd:clang-tidy-networkd-serialize.c                        FAIL            0.35s   exit status 1
>>> ASAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1 MALLOC_PERTURB_=189 UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 MSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 MESON_TEST_ITERATION=1 /usr/sbin/clang-tidy -p /home/runner/work/systemd/systemd/build /home/runner/work/systemd/systemd/build/../src/network/networkd-serialize.c
――――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――――――――――――――――――――
1 warning generated.
../src/network/networkd-serialize.c:8:1: error: included header fileio.h is not used directly [misc-include-cleaner,-warnings-as-errors]
    8 | #include "fileio.h"
      | ^~~~~~~~~~~~~~~~~~~
    9 | #include "hashmap.h"
Suppressed 1 warnings (1 NOLINT).
1 warning treated as error

fixed it myself so we can move on with rc1

@bluca bluca merged commit a7a7b1a into systemd:main May 18, 2026
48 of 53 checks passed
@github-actions github-actions Bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants