* Recommendations for adding strerror() in log statament
@ 2018-10-17 8:34 牛旭
0 siblings, 0 replies; only message in thread
From: 牛旭 @ 2018-10-17 8:34 UTC (permalink / raw)
To: git
Hi,
Our team works on enhance logging practices by learning from historical log revisions in evolution.
And we find 2 patches that add strerror() to the log statement which is printed when the return value of commit_lock_file() is smaller than 0.
While applying this rule to git-2.14.2, we find 3 missed spots.
We suggest to add strerror() or just use error_errno() instead of error().
Here are the missed spots:
1) Line 307 in file git-2.14.2/sequencer.c:
static int write_message(const void *buf, size_t len, const char *filename,
int append_eol)
{
...
if (append_eol && write(msg_fd, "\n", 1) < 0) {
rollback_lock_file(&msg_file);
return error_errno(_("could not write eol to '%s'"), filename);
}
if (commit_lock_file(&msg_file) < 0) {
rollback_lock_file(&msg_file);
return error(_("failed to finalize '%s'."), filename);
}
2) Line 1582 in file git-2.14.2/sequencer.c:
static int save_head(const char *head)
{
...
strbuf_addf(&buf, "%s\n", head);
if (write_in_full(fd, buf.buf, buf.len) < 0) {
rollback_lock_file(&head_lock);
return error_errno(_("could not write to '%s'"),
git_path_head_file());
}
if (commit_lock_file(&head_lock) < 0) {
rollback_lock_file(&head_lock);
return error(_("failed to finalize '%s'."), git_path_head_file());
}
3) Line 1706 in file git-2.14.2/sequencer.c:
static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
{
...
if (write_in_full(fd, todo_list->buf.buf + offset,
todo_list->buf.len - offset) < 0)
return error_errno(_("could not write to '%s'"), todo_path);
if (commit_lock_file(&todo_lock) < 0)
return error(_("failed to finalize '%s'."), todo_path);
Following are the 2 patches that support our opinion:
1) Line 2147 in file git-2.6.4/config.c:
if (commit_lock_file(lock) < 0) {
- error("could not commit config file %s", config_filename);
+ error("could not write config file %s: %s", config_filename,
+ strerror(errno));
ret = CONFIG_NO_WRITE;
lock = NULL;
goto out_free;
}
2) Line 2333 in file git-2.6.4/config.c:
unlock_and_out:
if (commit_lock_file(lock) < 0)
- ret = error("could not commit config file %s", config_filename);
+ ret = error("could not write config file %s: %s",
+ config_filename, strerror(errno));
out:
free(filename_buf);
Thanks for reading, we are looking forward to your reply about the correctness of our suggestion~
May you a good day ^^
Best regards,
Xu
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-10-17 8:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-17 8:34 Recommendations for adding strerror() in log statament 牛旭
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).