git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"Johannes Sixt" <j6t@kdbg.org>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 20/21] config.c: handle error on failing to fopen()
Date: Wed,  3 May 2017 17:17:05 +0700	[thread overview]
Message-ID: <20170503101706.9223-21-pclouds@gmail.com> (raw)
In-Reply-To: <20170503101706.9223-1-pclouds@gmail.com>

In the first case, we already correctly return -1 if fopen() fails to
open. But we should report something so people know what's wrong.

In the second case, config_file == NULL does not necessarily mean "no
config file". Bail out if needed.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 config.c              | 5 ++++-
 t/t1308-config-set.sh | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/config.c b/config.c
index b4a3205da3..e54d99d519 100644
--- a/config.c
+++ b/config.c
@@ -1422,7 +1422,7 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
 	int ret = -1;
 	FILE *f;
 
-	f = fopen(filename, "r");
+	f = fopen_or_warn(filename, "r");
 	if (f) {
 		flockfile(f);
 		ret = do_config_from_file(fn, CONFIG_ORIGIN_FILE, filename, filename, f, data);
@@ -2640,6 +2640,9 @@ int git_config_rename_section_in_file(const char *config_filename,
 	}
 
 	if (!(config_file = fopen(config_filename, "rb"))) {
+		ret = warn_on_fopen_errors(config_filename);
+		if (ret)
+			goto out;
 		/* no config file means nothing to rename, no error */
 		goto commit_and_out;
 	}
diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh
index ff50960cca..13e95561f4 100755
--- a/t/t1308-config-set.sh
+++ b/t/t1308-config-set.sh
@@ -187,7 +187,9 @@ test_expect_success POSIXPERM,SANITY 'proper error on non-accessible files' '
 	chmod -r .git/config &&
 	test_when_finished "chmod +r .git/config" &&
 	echo "Error (-1) reading configuration file .git/config." >expect &&
-	test_expect_code 2 test-config configset_get_value foo.bar .git/config 2>actual &&
+	test_expect_code 2 test-config configset_get_value foo.bar .git/config 2>output &&
+	grep "^warning:" output &&
+	grep "^Error" output >actual &&
 	test_cmp expect actual
 '
 
-- 
2.11.0.157.gd943d85


  parent reply	other threads:[~2017-05-03 10:20 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-20 11:25 [PATCH 00/15] Handle fopen() errors Nguyễn Thái Ngọc Duy
2017-04-20 11:25 ` [PATCH 01/15] config.mak.uname: set FREAD_READS_DIRECTORIES for Linux and FreeBSD Nguyễn Thái Ngọc Duy
2017-04-20 11:25 ` [PATCH 02/15] bisect: report on fopen() error Nguyễn Thái Ngọc Duy
2017-04-20 11:25 ` [PATCH 03/15] blame: report error on open if graft_file is a directory Nguyễn Thái Ngọc Duy
2017-04-20 11:25 ` [PATCH 04/15] clone: use xfopen() instead of fopen() Nguyễn Thái Ngọc Duy
2017-04-20 11:25 ` [PATCH 05/15] log: report errno on failure to fopen() a file Nguyễn Thái Ngọc Duy
2017-04-21  6:33   ` Jeff King
2017-04-20 11:26 ` [PATCH 06/15] commit.c: report error on failure to fopen() the graft file Nguyễn Thái Ngọc Duy
2017-04-20 11:26 ` [PATCH 07/15] remote.c: report error on failure to fopen() Nguyễn Thái Ngọc Duy
2017-04-26 16:59   ` Johannes Sixt
2017-04-27  0:57     ` Junio C Hamano
2017-04-27  5:07       ` Johannes Sixt
2017-04-27  9:14         ` Duy Nguyen
2017-04-27 17:49           ` Johannes Sixt
2017-04-20 11:26 ` [PATCH 08/15] rerere.c: " Nguyễn Thái Ngọc Duy
2017-04-20 11:26 ` [PATCH 09/15] rerere.c: report correct errno Nguyễn Thái Ngọc Duy
2017-04-20 11:26 ` [PATCH 10/15] sequencer.c: report error on failure to fopen() Nguyễn Thái Ngọc Duy
2017-04-20 11:26 ` [PATCH 11/15] server-info: " Nguyễn Thái Ngọc Duy
2017-04-20 11:26 ` [PATCH 12/15] wt-status.c: " Nguyễn Thái Ngọc Duy
2017-04-20 11:26 ` [PATCH 13/15] xdiff-interface.c: report errno on failure to stat() or fopen() Nguyễn Thái Ngọc Duy
2017-04-20 11:26 ` [PATCH 14/15] config.c: handle error on failing to fopen() Nguyễn Thái Ngọc Duy
2017-04-20 11:26 ` [PATCH 15/15] t1308: add a test case on open a config directory Nguyễn Thái Ngọc Duy
2017-04-21  1:47 ` [PATCH 00/15] Handle fopen() errors Junio C Hamano
2017-04-21  3:41   ` Junio C Hamano
2017-04-21  6:29     ` Jeff King
2017-04-21 11:04       ` Duy Nguyen
2017-04-21 11:52         ` Junio C Hamano
2017-04-21 12:27           ` Duy Nguyen
2017-04-21 17:07             ` Jeff King
2017-04-24  0:45               ` Junio C Hamano
2017-05-03 10:16 ` [PATCH v2 00/21] Nguyễn Thái Ngọc Duy
2017-05-03 10:16   ` [PATCH v2 01/21] Use xfopen() in more places Nguyễn Thái Ngọc Duy
2017-05-03 10:16   ` [PATCH v2 02/21] clone: use xfopen() instead of fopen() Nguyễn Thái Ngọc Duy
2017-05-03 15:02     ` Johannes Schindelin
2017-05-03 10:16   ` [PATCH v2 03/21] config.mak.uname: set FREAD_READS_DIRECTORIES for Linux and FreeBSD Nguyễn Thái Ngọc Duy
2017-05-03 10:16   ` [PATCH v2 04/21] wrapper.c: add warn_on_fopen_errors() Nguyễn Thái Ngọc Duy
2017-05-03 15:07     ` Johannes Schindelin
2017-05-04  5:35     ` Junio C Hamano
2017-05-03 10:16   ` [PATCH v2 05/21] wrapper.c: add fopen_or_warn() Nguyễn Thái Ngọc Duy
2017-05-03 10:16   ` [PATCH v2 06/21] attr.c: use fopen_or_warn() Nguyễn Thái Ngọc Duy
2017-05-03 15:09     ` Johannes Schindelin
2017-05-03 10:16   ` [PATCH v2 07/21] ident.c: " Nguyễn Thái Ngọc Duy
2017-05-03 10:16   ` [PATCH v2 08/21] bisect: report on fopen() error Nguyễn Thái Ngọc Duy
2017-05-03 15:12     ` Johannes Schindelin
2017-05-03 10:16   ` [PATCH v2 09/21] blame: report error on open if graft_file is a directory Nguyễn Thái Ngọc Duy
2017-05-03 15:15     ` Johannes Schindelin
2017-05-03 10:16   ` [PATCH v2 10/21] log: report errno on failure to fopen() a file Nguyễn Thái Ngọc Duy
2017-05-03 15:19     ` Johannes Schindelin
2017-05-03 10:16   ` [PATCH v2 11/21] log: fix memory leak in open_next_file() Nguyễn Thái Ngọc Duy
2017-05-03 10:16   ` [PATCH v2 12/21] commit.c: report error on failure to fopen() the graft file Nguyễn Thái Ngọc Duy
2017-05-03 10:16   ` [PATCH v2 13/21] remote.c: report error on failure to fopen() Nguyễn Thái Ngọc Duy
2017-05-03 15:22     ` Johannes Schindelin
2017-05-09 10:16       ` Duy Nguyen
2017-05-09 12:56         ` Johannes Schindelin
2017-05-03 10:16   ` [PATCH v2 14/21] rerere.c: " Nguyễn Thái Ngọc Duy
2017-05-03 10:17   ` [PATCH v2 15/21] rerere.c: report correct errno Nguyễn Thái Ngọc Duy
2017-05-03 15:24     ` Johannes Schindelin
2017-05-03 10:17   ` [PATCH v2 16/21] sequencer.c: report error on failure to fopen() Nguyễn Thái Ngọc Duy
2017-05-03 10:17   ` [PATCH v2 17/21] server-info: " Nguyễn Thái Ngọc Duy
2017-05-03 10:17   ` [PATCH v2 18/21] wt-status.c: " Nguyễn Thái Ngọc Duy
2017-05-03 10:17   ` [PATCH v2 19/21] xdiff-interface.c: report errno on failure to stat() or fopen() Nguyễn Thái Ngọc Duy
2017-05-03 10:17   ` Nguyễn Thái Ngọc Duy [this message]
2017-05-03 15:29     ` [PATCH v2 20/21] config.c: handle error on failing to fopen() Johannes Schindelin
2017-05-03 10:17   ` [PATCH v2 21/21] t1308: add a test case on open a config directory Nguyễn Thái Ngọc Duy
2017-05-03 15:33     ` Johannes Schindelin
2017-05-04  5:45   ` [PATCH v2 00/21] Junio C Hamano
2017-05-07  4:20     ` Junio C Hamano
2017-05-09 10:22       ` Duy Nguyen
2017-05-09 22:52         ` Junio C Hamano
2017-05-10  5:12           ` [PATCH] config.mak.uname: set FREAD_READS_DIRECTORIES for Darwin, too Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170503101706.9223-21-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).