From 2a8177345ceebba615245172d39df3d5ca79302c Mon Sep 17 00:00:00 2001
From: Danny Auble <da@schedmd.com>
Date: Thu, 26 May 2016 15:23:37 -0700
Subject: [PATCH] Make it so --mail-type=NONE didn't throw an invalid error.

---
 NEWS                   | 1 +
 src/common/proc_args.c | 2 +-
 src/salloc/opt.c       | 2 +-
 src/sbatch/opt.c       | 8 +++++---
 src/srun/libsrun/opt.c | 2 +-
 5 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/NEWS b/NEWS
index 9cdf6448b04..3c6df7d923c 100644
--- a/NEWS
+++ b/NEWS
@@ -38,6 +38,7 @@ documents those changes that are of interest to users and administrators.
  -- Prevent infinite loop in slurmstepd if execve fails.
  -- Prevent multiple responses to REQUEST_UPDATE_JOB_STEP message.
  -- Prevent possible deadlock in acct_gather_filesystem/lustre on error.
+ -- Make it so --mail-type=NONE didn't throw an invalid error.
 
 * Changes in Slurm 15.08.11
 ===========================
diff --git a/src/common/proc_args.c b/src/common/proc_args.c
index a30d7cb316c..58b437b2e89 100644
--- a/src/common/proc_args.c
+++ b/src/common/proc_args.c
@@ -981,7 +981,7 @@ bool verify_hint(const char *arg, int *min_sockets, int *min_cores,
 uint16_t parse_mail_type(const char *arg)
 {
 	char *buf, *tok, *save_ptr = NULL;
-	uint16_t rc = 0;
+	uint16_t rc = (uint16_t)INFINITE;
 
 	if (!arg)
 		return rc;
diff --git a/src/salloc/opt.c b/src/salloc/opt.c
index 062a39ec091..2bb40a01383 100644
--- a/src/salloc/opt.c
+++ b/src/salloc/opt.c
@@ -1035,7 +1035,7 @@ void set_options(const int argc, char **argv)
 			break;
 		case LONG_OPT_MAIL_TYPE:
 			opt.mail_type |= parse_mail_type(optarg);
-			if (opt.mail_type == 0) {
+			if (opt.mail_type == (uint16_t)INFINITE) {
 				error("--mail-type=%s invalid", optarg);
 				exit(error_exit);
 			}
diff --git a/src/sbatch/opt.c b/src/sbatch/opt.c
index d57e97d93d0..81f51d8ad6a 100644
--- a/src/sbatch/opt.c
+++ b/src/sbatch/opt.c
@@ -1502,7 +1502,7 @@ static void _set_options(int argc, char **argv)
 			break;
 		case LONG_OPT_MAIL_TYPE:
 			opt.mail_type |= parse_mail_type(optarg);
-			if (opt.mail_type == 0) {
+			if (opt.mail_type == (uint16_t)INFINITE) {
 				error("--mail-type=%s invalid", optarg);
 				exit(error_exit);
 			}
@@ -1889,7 +1889,7 @@ static void _set_pbs_options(int argc, char **argv)
 			break;
 		case 'm':
 			opt.mail_type |= _parse_pbs_mail_type(optarg);
-			if ((opt.mail_type == 0) && strcasecmp(optarg, "n")) {
+			if (opt.mail_type == (uint16_t)INFINITE) {
 				error("-m=%s invalid", optarg);
 				exit(error_exit);
 			}
@@ -2686,7 +2686,7 @@ static bool _opt_verify(void)
 
 static uint16_t _parse_pbs_mail_type(const char *arg)
 {
-	uint16_t rc =  0;
+	uint16_t rc = (uint16_t)INFINITE;
 
 	if (strchr(arg, 'b') || strchr(arg, 'B'))
 		rc |= MAIL_JOB_BEGIN;
@@ -2694,6 +2694,8 @@ static uint16_t _parse_pbs_mail_type(const char *arg)
 		rc |= MAIL_JOB_END;
 	if (strchr(arg, 'a') || strchr(arg, 'A'))
 		rc |= MAIL_JOB_FAIL;
+	if (strchr(arg, 'n') || strchr(arg, 'N'))
+		rc = 0;
 
 	return rc;
 }
diff --git a/src/srun/libsrun/opt.c b/src/srun/libsrun/opt.c
index e16e4ff6e47..6404f55be59 100644
--- a/src/srun/libsrun/opt.c
+++ b/src/srun/libsrun/opt.c
@@ -1474,7 +1474,7 @@ static void _set_options(const int argc, char **argv)
 			break;
 		case LONG_OPT_MAIL_TYPE:
 			opt.mail_type |= parse_mail_type(optarg);
-			if (opt.mail_type == 0) {
+			if (opt.mail_type == (uint16_t)INFINITE) {
 				error("--mail-type=%s invalid", optarg);
 				exit(error_exit);
 			}
-- 
GitLab