Blame SOURCES/0006-tools-entry-remove-errx-from-parse_option.patch

59dcbd
From d9912e19e48ec482351b9c384140ad71922ec5c0 Mon Sep 17 00:00:00 2001
59dcbd
From: Sumit Bose <sbose@redhat.com>
59dcbd
Date: Mon, 8 Apr 2019 17:22:00 +0200
59dcbd
Subject: [PATCH 6/7] tools: entry - remove errx from parse_option
59dcbd
59dcbd
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596
59dcbd
---
59dcbd
 tools/entry.c | 70 ++++++++++++++++++++++++++++++++++-----------------
59dcbd
 1 file changed, 47 insertions(+), 23 deletions(-)
59dcbd
59dcbd
diff --git a/tools/entry.c b/tools/entry.c
59dcbd
index 97ec6e7..f361845 100644
59dcbd
--- a/tools/entry.c
59dcbd
+++ b/tools/entry.c
59dcbd
@@ -81,7 +81,7 @@ static adcli_tool_desc common_usages[] = {
59dcbd
 	{ 0 },
59dcbd
 };
59dcbd
 
59dcbd
-static void
59dcbd
+static int
59dcbd
 parse_option (Option opt,
59dcbd
               const char *optarg,
59dcbd
               adcli_conn *conn)
59dcbd
@@ -93,54 +93,58 @@ parse_option (Option opt,
59dcbd
 	switch (opt) {
59dcbd
 	case opt_login_ccache:
59dcbd
 		adcli_conn_set_login_ccache_name (conn, optarg);
59dcbd
-		return;
59dcbd
+		return ADCLI_SUCCESS;
59dcbd
 	case opt_login_user:
59dcbd
 		adcli_conn_set_login_user (conn, optarg);
59dcbd
-		return;
59dcbd
+		return ADCLI_SUCCESS;
59dcbd
 	case opt_domain:
59dcbd
 		adcli_conn_set_domain_name (conn, optarg);
59dcbd
-		return;
59dcbd
+		return ADCLI_SUCCESS;
59dcbd
 	case opt_domain_realm:
59dcbd
 		adcli_conn_set_domain_realm (conn, optarg);
59dcbd
-		return;
59dcbd
+		return ADCLI_SUCCESS;
59dcbd
 	case opt_domain_controller:
59dcbd
 		adcli_conn_set_domain_controller (conn, optarg);
59dcbd
-		return;
59dcbd
+		return ADCLI_SUCCESS;
59dcbd
 	case opt_no_password:
59dcbd
 		if (stdin_password || prompt_password) {
59dcbd
-			errx (EUSAGE, "cannot use --no-password argument with %s",
59dcbd
-			      stdin_password ? "--stdin-password" : "--prompt-password");
59dcbd
+			warnx ("cannot use --no-password argument with %s",
59dcbd
+			       stdin_password ? "--stdin-password" : "--prompt-password");
59dcbd
+			return EUSAGE;
59dcbd
 		} else {
59dcbd
 			adcli_conn_set_password_func (conn, NULL, NULL, NULL);
59dcbd
 			no_password = 1;
59dcbd
 		}
59dcbd
-		return;
59dcbd
+		return ADCLI_SUCCESS;
59dcbd
 	case opt_prompt_password:
59dcbd
 		if (stdin_password || no_password) {
59dcbd
-			errx (EUSAGE, "cannot use --prompt-password argument with %s",
59dcbd
-			      stdin_password ? "--stdin-password" : "--no-password");
59dcbd
+			warnx ("cannot use --prompt-password argument with %s",
59dcbd
+			       stdin_password ? "--stdin-password" : "--no-password");
59dcbd
+			return EUSAGE;
59dcbd
 		} else {
59dcbd
 			adcli_conn_set_password_func (conn, adcli_prompt_password_func, NULL, NULL);
59dcbd
 			prompt_password = 1;
59dcbd
 		}
59dcbd
-		return;
59dcbd
+		return ADCLI_SUCCESS;
59dcbd
 	case opt_stdin_password:
59dcbd
 		if (prompt_password || no_password) {
59dcbd
-			errx (EUSAGE, "cannot use --stdin-password argument with %s",
59dcbd
-			      prompt_password ? "--prompt-password" : "--no-password");
59dcbd
+			warnx ("cannot use --stdin-password argument with %s",
59dcbd
+			       prompt_password ? "--prompt-password" : "--no-password");
59dcbd
+			return EUSAGE;
59dcbd
 		} else {
59dcbd
 			adcli_conn_set_password_func (conn, adcli_read_password_func, NULL, NULL);
59dcbd
 			stdin_password = 1;
59dcbd
 		}
59dcbd
-		return;
59dcbd
+		return ADCLI_SUCCESS;
59dcbd
 	case opt_verbose:
59dcbd
-		return;
59dcbd
+		return ADCLI_SUCCESS;
59dcbd
 	default:
59dcbd
 		assert (0 && "not reached");
59dcbd
 		break;
59dcbd
 	}
59dcbd
 
59dcbd
-	errx (EUSAGE, "failure to parse option '%c'", opt);
59dcbd
+	warnx ("failure to parse option '%c'", opt);
59dcbd
+	return EUSAGE;
59dcbd
 }
59dcbd
 
59dcbd
 int
59dcbd
@@ -224,7 +228,11 @@ adcli_tool_user_create (adcli_conn *conn,
59dcbd
 			adcli_attrs_free (attrs);
59dcbd
 			return opt == 'h' ? 0 : 2;
59dcbd
 		default:
59dcbd
-			parse_option ((Option)opt, optarg, conn);
59dcbd
+			res = parse_option ((Option)opt, optarg, conn);
59dcbd
+			if (res != ADCLI_SUCCESS) {
59dcbd
+				adcli_attrs_free (attrs);
59dcbd
+				return res;
59dcbd
+			}
59dcbd
 			break;
59dcbd
 		}
59dcbd
 	}
59dcbd
@@ -322,7 +330,10 @@ adcli_tool_user_delete (adcli_conn *conn,
59dcbd
 			adcli_tool_usage (options, common_usages);
59dcbd
 			return opt == 'h' ? 0 : 2;
59dcbd
 		default:
59dcbd
-			parse_option ((Option)opt, optarg, conn);
59dcbd
+			res = parse_option ((Option)opt, optarg, conn);
59dcbd
+			if (res != ADCLI_SUCCESS) {
59dcbd
+				return res;
59dcbd
+			}
59dcbd
 			break;
59dcbd
 		}
59dcbd
 	}
59dcbd
@@ -417,7 +428,11 @@ adcli_tool_group_create (adcli_conn *conn,
59dcbd
 			adcli_attrs_free (attrs);
59dcbd
 			return opt == 'h' ? 0 : 2;
59dcbd
 		default:
59dcbd
-			parse_option ((Option)opt, optarg, conn);
59dcbd
+			res = parse_option ((Option)opt, optarg, conn);
59dcbd
+			if (res != ADCLI_SUCCESS) {
59dcbd
+				adcli_attrs_free (attrs);
59dcbd
+				return res;
59dcbd
+			}
59dcbd
 			break;
59dcbd
 		}
59dcbd
 	}
59dcbd
@@ -505,7 +520,10 @@ adcli_tool_group_delete (adcli_conn *conn,
59dcbd
 			adcli_tool_usage (options, common_usages);
59dcbd
 			return opt == 'h' ? 0 : 2;
59dcbd
 		default:
59dcbd
-			parse_option ((Option)opt, optarg, conn);
59dcbd
+			res = parse_option ((Option)opt, optarg, conn);
59dcbd
+			if (res != ADCLI_SUCCESS) {
59dcbd
+				return res;
59dcbd
+			}
59dcbd
 			break;
59dcbd
 		}
59dcbd
 	}
59dcbd
@@ -628,7 +646,10 @@ adcli_tool_member_add (adcli_conn *conn,
59dcbd
 			adcli_tool_usage (options, common_usages);
59dcbd
 			return opt == 'h' ? 0 : 2;
59dcbd
 		default:
59dcbd
-			parse_option ((Option)opt, optarg, conn);
59dcbd
+			res = parse_option ((Option)opt, optarg, conn);
59dcbd
+			if (res != ADCLI_SUCCESS) {
59dcbd
+				return res;
59dcbd
+			}
59dcbd
 			break;
59dcbd
 		}
59dcbd
 	}
59dcbd
@@ -725,7 +746,10 @@ adcli_tool_member_remove (adcli_conn *conn,
59dcbd
 			adcli_tool_usage (options, common_usages);
59dcbd
 			return opt == 'h' ? 0 : 2;
59dcbd
 		default:
59dcbd
-			parse_option ((Option)opt, optarg, conn);
59dcbd
+			res = parse_option ((Option)opt, optarg, conn);
59dcbd
+			if (res != ADCLI_SUCCESS) {
59dcbd
+				return res;
59dcbd
+			}
59dcbd
 			break;
59dcbd
 		}
59dcbd
 	}
59dcbd
-- 
59dcbd
2.20.1
59dcbd