Thread (13 messages) 13 messages, 2 authors, 2021-12-11

Re: [PATCH 3/4] xfs_quota: don't exit on fs_table_insert_project_path failure

From: "Darrick J. Wong" <djwong@kernel.org>
Date: 2021-12-11 00:22:01

On Fri, Dec 10, 2021 at 02:21:36PM -0600, Eric Sandeen wrote:
quoted hunk ↗ jump to hunk
From: Eric Sandeen <redacted>

If "project -p" fails in fs_table_insert_project_path, it
calls exit() today which is quite unfriendly. Return an error
and return to the command prompt as expected.

Signed-off-by: Eric Sandeen <redacted>
Signed-off-by: Eric Sandeen <redacted>
---
 libfrog/paths.c | 7 +++----
 libfrog/paths.h | 2 +-
 quota/project.c | 4 +++-
 3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/libfrog/paths.c b/libfrog/paths.c
index d679376..6c0fee2 100644
--- a/libfrog/paths.c
+++ b/libfrog/paths.c
@@ -546,7 +546,7 @@ out_error:
 		progname, strerror(error));
 }
 
-void
+int
 fs_table_insert_project_path(
 	char		*dir,
 	prid_t		prid)
@@ -561,9 +561,8 @@ fs_table_insert_project_path(
 	else
 		error = ENOENT;
 
-	if (error) {
+	if (error)
 		fprintf(stderr, _("%s: cannot setup path for project dir %s: %s\n"),
 				progname, dir, strerror(error));
Why not move this to the (sole) caller?  Libraries (even pseudolibraries
like libfrog) usually aren't supposed to go around fprintfing things.

--D
quoted hunk ↗ jump to hunk
-		exit(1);
-	}
+	return error;
 }
diff --git a/libfrog/paths.h b/libfrog/paths.h
index c08e373..f20a2c3 100644
--- a/libfrog/paths.h
+++ b/libfrog/paths.h
@@ -40,7 +40,7 @@ extern char *mtab_file;
 extern void fs_table_initialise(int, char *[], int, char *[]);
 extern void fs_table_destroy(void);
 
-extern void fs_table_insert_project_path(char *__dir, uint __projid);
+extern int fs_table_insert_project_path(char *__dir, uint __projid);
 
 
 extern fs_path_t *fs_table_lookup(const char *__dir, uint __flags);
diff --git a/quota/project.c b/quota/project.c
index 03ae10d..bed0dc5 100644
--- a/quota/project.c
+++ b/quota/project.c
@@ -281,7 +281,9 @@ project_f(
 			break;
 		case 'p':
 			ispath = 1;
-			fs_table_insert_project_path(optarg, -1);
+			/* fs_table_insert_project_path prints the failure */
+			if (fs_table_insert_project_path(optarg, -1))
+				return 0;
 			break;
 		case 's':
 			type = SETUP_PROJECT;
-- 
1.8.3.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help