Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions libnvme/src/nvme/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,9 @@ int json_update_config(struct nvme_global_ctx *ctx, int fd)
ret = json_object_to_fd(fd, json_root,
JSON_C_TO_STRING_PRETTY |
JSON_C_TO_STRING_NOSLASHESCAPE);
write(fd, "\n", 1);
if (ret < 0) {
if (ret < 0 || write(fd, "\n", 1) < 0) {
Copy link
Copy Markdown
Collaborator

@igaw igaw Feb 18, 2026

Choose a reason for hiding this comment

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

The log message could then be missleading when json_object_to_fd is succesfull and then the write fails. In this case json_util_get_last_error will not be correct.

something like this here would be less confusing

	ret = json_object_to_fd(fd, json_root,
				JSON_C_TO_STRING_PRETTY |
				JSON_C_TO_STRING_NOSLASHESCAPE);
	if (ret < 0) {
		nvme_msg(ctx, LOG_ERR, "Failed to write JSON config file: %s\n",
			 json_util_get_last_err());
		[...]
	};

	ret = write(...)
	if (ret < 0) {
		nvme_msg(...);
	}

(though highly unlikely to happen)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How about this?

		nvme_msg(ctx, LOG_ERR, "Failed to write JSON config file: %s\n",
			  ret ? json_util_get_last_err() : strerror());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yes, that's fine too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just fixed as commented. Thank you.

nvme_msg(ctx, LOG_ERR, "Failed to write JSON config file: %s\n",
json_util_get_last_err());
ret ? json_util_get_last_err() : strerror(errno));
ret = -EIO;
}
json_object_put(json_root);
Expand Down