From 79f0e94e27f9304ffdd65465a7e16aa5176aa211 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Wed, 21 Aug 2024 08:51:08 -0500 Subject: [PATCH] edit-util: EditFileContext: avoid reserved 'stdin' The identifier 'stdin' is reserved in C. It can be #defined to any statement that evaluates to a FILE*. We do not want that for our field, so change to a more descriptive name. --- src/network/networkctl-config-file.c | 2 +- src/shared/edit-util.c | 12 ++++++------ src/shared/edit-util.h | 2 +- src/systemctl/systemctl-edit.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/network/networkctl-config-file.c b/src/network/networkctl-config-file.c index 1bfc185f7cc..6d60d7eb99e 100644 --- a/src/network/networkctl-config-file.c +++ b/src/network/networkctl-config-file.c @@ -402,7 +402,7 @@ int verb_edit(int argc, char *argv[], void *userdata) { .marker_start = DROPIN_MARKER_START, .marker_end = DROPIN_MARKER_END, .remove_parent = !!arg_drop_in, - .stdin = arg_stdin, + .read_from_stdin = arg_stdin, }; _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL; ReloadFlags reload = 0; diff --git a/src/shared/edit-util.c b/src/shared/edit-util.c index 89ca9459e06..e37609c2e1c 100644 --- a/src/shared/edit-util.c +++ b/src/shared/edit-util.c @@ -112,7 +112,7 @@ int edit_files_add( static int populate_edit_temp_file(EditFile *e, FILE *f, const char *filename) { assert(e); assert(e->context); - assert(!e->context->stdin); + assert(!e->context->read_from_stdin); assert(e->path); assert(f); assert(filename); @@ -200,7 +200,7 @@ static int create_edit_temp_file(EditFile *e, const char *contents, size_t conte assert(e->path); assert(!e->comment_paths || (e->context->marker_start && e->context->marker_end)); assert(contents || contents_size == 0); - assert(e->context->stdin == !!contents); + assert(e->context->read_from_stdin == !!contents); if (e->temp) return 0; @@ -216,7 +216,7 @@ static int create_edit_temp_file(EditFile *e, const char *contents, size_t conte if (fchmod(fileno(f), 0644) < 0) return log_error_errno(errno, "Failed to change mode of temporary file '%s': %m", temp); - if (e->context->stdin) { + if (e->context->read_from_stdin) { if (fwrite(contents, 1, contents_size, f) != contents_size) return log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to write stdin data to temporary file '%s'.", temp); @@ -331,7 +331,7 @@ static int strip_edit_temp_file(EditFile *e) { if (!tmp) return log_oom(); - with_marker = e->context->marker_start && !e->context->stdin; + with_marker = e->context->marker_start && !e->context->read_from_stdin; if (with_marker) { /* Trim out the lines between the two markers */ @@ -457,7 +457,7 @@ int do_edit_files_and_install(EditFileContext *context) { if (context->n_files == 0) return log_debug_errno(SYNTHETIC_ERRNO(ENOENT), "Got no files to edit."); - if (context->stdin) { + if (context->read_from_stdin) { r = read_full_stream(stdin, &stdin_data, &stdin_size); if (r < 0) return log_error_errno(r, "Failed to read stdin: %m"); @@ -476,7 +476,7 @@ int do_edit_files_and_install(EditFileContext *context) { _cleanup_close_ int stdin_data_fd = -EBADF; FOREACH_ARRAY(editfile, context->files, context->n_files) { - if (context->stdin) { + if (context->read_from_stdin) { r = edit_file_install_one_stdin(editfile, stdin_data, stdin_size, &stdin_data_fd); if (r == 0) { log_notice("Stripped stdin content is empty, not writing file."); diff --git a/src/shared/edit-util.h b/src/shared/edit-util.h index 9d9c890f2a9..2affa7eab16 100644 --- a/src/shared/edit-util.h +++ b/src/shared/edit-util.h @@ -15,7 +15,7 @@ typedef struct EditFileContext { const char *marker_end; bool remove_parent; bool overwrite_with_origin; /* Always overwrite target with original file. */ - bool stdin; /* Read contents from stdin instead of launching an editor. */ + bool read_from_stdin; /* Read contents from stdin instead of launching an editor. */ } EditFileContext; void edit_file_context_done(EditFileContext *context); diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c index 880bd4d742e..c42a31153dc 100644 --- a/src/systemctl/systemctl-edit.c +++ b/src/systemctl/systemctl-edit.c @@ -317,7 +317,7 @@ int verb_edit(int argc, char *argv[], void *userdata) { .marker_end = DROPIN_MARKER_END, .remove_parent = !arg_full, .overwrite_with_origin = true, - .stdin = arg_stdin, + .read_from_stdin = arg_stdin, }; _cleanup_strv_free_ char **names = NULL; sd_bus *bus;