diff --git a/NEWS b/NEWS
index a09fee8b4981924d0408422c9bb38a235bdf945e..cf31c362da09d78f64a9c28393d7ca38b917739c 100644
--- a/NEWS
+++ b/NEWS
@@ -70,6 +70,9 @@ documents those changes that are of interest to users and administrators.
     oversubscription of CPUs.
  -- Fix the pty window manager in slurmstepd not to retry IO operation with
     srun if it read EOF from the connection with it.
+ -- sbatch --ntasks option to take precedence over --ntasks-per-node plus node
+    count, as documented. Set SLURM_NTASKS/SLURM_NPROCS environment variables
+    accordingly.
 
 * Changes in Slurm 15.08.1
 ==========================
diff --git a/doc/man/man1/sbatch.1 b/doc/man/man1/sbatch.1
index 19df4ed6be24075c806af85c6cdf8f3364e5dd88..6985ac843eaf4e605ce0dab7a52ce1c2bc6dd7a3 100644
--- a/doc/man/man1/sbatch.1
+++ b/doc/man/man1/sbatch.1
@@ -1068,9 +1068,10 @@ ignored if \fISchedulerType=sched/wiki\fR or
 
 .TP
 \fB\-\-no\-requeue\fR
-Specifies that the batch job should not be requeued after node failure.
+Specifies that the batch job should never be requeued under any circumstances.
 Setting this option will prevent system administrators from being able
-to restart the job (for example, after a scheduled downtime).
+to restart the job (for example, after a scheduled downtime), recover from
+a node failure, or be requeued upon preemption by a higher priority job.
 When a job is requeued, the batch script is initiated from its beginning.
 Also see the \fB\-\-requeue\fR option.
 The \fIJobRequeue\fR configuration parameter controls the default
@@ -1275,7 +1276,9 @@ silently ignored.
 
 .TP
 \fB\-\-requeue\fR
-Specifies that the batch job should be requeued after node failure.
+Specifies that the batch job should eligible to being requeue.
+The job may be requeued explicitly by a system administrator, after node
+failure, or upon preemption by a higher priority job.
 When a job is requeued, the batch script is initiated from its beginning.
 Also see the \fB\-\-no\-requeue\fR option.
 The \fIJobRequeue\fR configuration parameter controls the default
diff --git a/doc/man/man5/slurm.conf.5 b/doc/man/man5/slurm.conf.5
index 79bec02110f16bbc7ceb2508130269ee11ba5b6d..a0091f4c1305cd8ae209f3e04cb400d281690cad 100644
--- a/doc/man/man5/slurm.conf.5
+++ b/doc/man/man5/slurm.conf.5
@@ -1192,11 +1192,13 @@ By default, any existing file is truncated.
 
 .TP
 \fBJobRequeue\fR
-This option controls what to do by default after a node failure.
-If \fBJobRequeue\fR is set to a value of 1, then any batch job running
-on the failed node will be requeued for execution on different nodes.
-If \fBJobRequeue\fR is set to a value of 0, then any job running
-on the failed node will be terminated.
+This option controls the default ability for batch jobs to be requeued.
+Jobs may be requeued explicitly by a system administrator, after node
+failure, or upon preemption by a higher priority job.
+If \fBJobRequeue\fR is set to a value of 1, then batch job may be requeued
+unless explicitly disabled by the user.
+If \fBJobRequeue\fR is set to a value of 0, then batch job will not be requeued
+unless explicitly enabled by the user.
 Use the \fBsbatch\fR \fI\-\-no\-requeue\fR or \fI\-\-requeue\fR
 option to change the default behavior for individual jobs.
 The default value is 1.
diff --git a/src/common/env.c b/src/common/env.c
index 4dd9c661730c8a0818f2c55fb928cf7b2a83dca0..4542c17e1e50ee820f20aefbcf840997a0b8eea1 100644
--- a/src/common/env.c
+++ b/src/common/env.c
@@ -1205,11 +1205,9 @@ env_array_for_batch_job(char ***dest, const batch_job_launch_msg_t *batch,
 		cpus_per_task = 1;	/* default value */
 
 	if (num_tasks) {
-		env_array_overwrite_fmt(dest, "SLURM_NTASKS", "%u",
-					num_tasks);
+		env_array_append_fmt(dest, "SLURM_NTASKS", "%u", num_tasks);
 		/* keep around for old scripts */
-		env_array_overwrite_fmt(dest, "SLURM_NPROCS", "%u",
-					num_tasks);
+		env_array_append_fmt(dest, "SLURM_NPROCS", "%u", num_tasks);
 	} else {
 		num_tasks = num_cpus / cpus_per_task;
 	}
diff --git a/src/plugins/accounting_storage/mysql/as_mysql_rollup.c b/src/plugins/accounting_storage/mysql/as_mysql_rollup.c
index 1cfa43f7696388401d3f6e608b927f427a8a6c0d..84fe858694e59fea1aa308a1fbd83c66000257c1 100644
--- a/src/plugins/accounting_storage/mysql/as_mysql_rollup.c
+++ b/src/plugins/accounting_storage/mysql/as_mysql_rollup.c
@@ -968,8 +968,6 @@ extern int as_mysql_hourly_rollup(mysql_conn_t *mysql_conn,
 	while (curr_start < end) {
 		int last_id = -1;
 		int last_wckeyid = -1;
-		int seconds = 0;
-		int tot_time = 0;
 
 		if (debug_flags & DEBUG_FLAG_DB_USAGE)
 			DB_DEBUG(mysql_conn->conn,
@@ -1032,7 +1030,7 @@ extern int as_mysql_hourly_rollup(mysql_conn_t *mysql_conn,
 			time_t row_start = slurm_atoul(row[RESV_REQ_START]);
 			time_t row_end = slurm_atoul(row[RESV_REQ_END]);
 			uint32_t row_flags = slurm_atoul(row[RESV_REQ_FLAGS]);
-			int seconds;
+			int resv_seconds;
 			if (row_start < curr_start)
 				row_start = curr_start;
 
@@ -1042,7 +1040,7 @@ extern int as_mysql_hourly_rollup(mysql_conn_t *mysql_conn,
 			/* Don't worry about it if the time is less
 			 * than 1 second.
 			 */
-			if ((seconds = (row_end - row_start)) < 1)
+			if ((resv_seconds = (row_end - row_start)) < 1)
 				continue;
 
 			r_usage = xmalloc(sizeof(local_resv_usage_t));
@@ -1055,7 +1053,7 @@ extern int as_mysql_hourly_rollup(mysql_conn_t *mysql_conn,
 				list_create(_destroy_local_tres_usage);
 
 			_add_tres_2_list(r_usage->loc_tres,
-					 row[RESV_REQ_TRES], seconds);
+					 row[RESV_REQ_TRES], resv_seconds);
 
 			r_usage->start = row_start;
 			r_usage->end = row_end;
@@ -1132,7 +1130,7 @@ extern int as_mysql_hourly_rollup(mysql_conn_t *mysql_conn,
 			List loc_tres = NULL;
 			uint64_t row_energy = 0;
 			int loc_seconds = 0;
-			seconds = 0;
+			int seconds = 0;
 
 			if (row[JOB_REQ_ENERGY])
 				row_energy = slurm_atoull(row[JOB_REQ_ENERGY]);
@@ -1175,6 +1173,7 @@ extern int as_mysql_hourly_rollup(mysql_conn_t *mysql_conn,
 				}
 				xfree(query);
 				while ((row2 = mysql_fetch_row(result2))) {
+					int tot_time = 0;
 					time_t local_start = slurm_atoul(
 						row2[SUSPEND_REQ_START]);
 					time_t local_end = slurm_atoul(
@@ -1432,6 +1431,7 @@ extern int as_mysql_hourly_rollup(mysql_conn_t *mysql_conn,
 					loc_tres->time_alloc;
 				char *assoc = NULL;
 				ListIterator tmp_itr = NULL;
+				int resv_unused_secs;
 
 				if (idle <= 0)
 					break; /* since this will be
@@ -1440,11 +1440,12 @@ extern int as_mysql_hourly_rollup(mysql_conn_t *mysql_conn,
 				/* now divide that time by the number of
 				   associations in the reservation and add
 				   them to each association */
-				seconds = idle /
+				resv_unused_secs = idle /
 					list_count(r_usage->local_assocs);
 				/* info("resv %d got %d seconds for TRES %u " */
 				/*      "for %d assocs", */
-				/*      r_usage->id, seconds, loc_tres->id, */
+				/*      r_usage->id, resv_unused_secs, */
+				/*      loc_tres->id, */
 				/*      list_count(r_usage->local_assocs)); */
 				tmp_itr = list_iterator_create(
 					r_usage->local_assocs);
@@ -1467,7 +1468,7 @@ extern int as_mysql_hourly_rollup(mysql_conn_t *mysql_conn,
 
 					_add_time_tres(a_usage->loc_tres,
 						       TIME_ALLOC, loc_tres->id,
-						       seconds, 0);
+						       resv_unused_secs, 0);
 				}
 				list_iterator_destroy(tmp_itr);
 			}
diff --git a/src/sbatch/opt.c b/src/sbatch/opt.c
index ea9cba06583e9ac2fab2a1e9e37a721fd2f33064..c21c8ce43c6475b4723b70b41ca4858b8f46af95 100644
--- a/src/sbatch/opt.c
+++ b/src/sbatch/opt.c
@@ -2340,6 +2340,11 @@ static bool _opt_verify(void)
 		verified = false;
 	}
 
+	if (opt.ntasks_set && (opt.ntasks > 0)) {
+		setenvf(NULL, "SLURM_NPROCS", "%d", opt.ntasks);
+		setenvf(NULL, "SLURM_NTASKS", "%d", opt.ntasks);
+	}
+
 	_fullpath(&opt.efname, opt.cwd);
 	_fullpath(&opt.ifname, opt.cwd);
 	_fullpath(&opt.ofname, opt.cwd);
diff --git a/src/slurmd/slurmstepd/io.c b/src/slurmd/slurmstepd/io.c
index 9ee7907a735a1e95266f804ff89db2a5b097c0ed..5f73eec4b186f253a9574d3b05b6dc999bee9328 100644
--- a/src/slurmd/slurmstepd/io.c
+++ b/src/slurmd/slurmstepd/io.c
@@ -846,9 +846,11 @@ static void *_window_manager(void *arg)
 		if ((len == -1) && ((errno == EINTR) || (errno == EAGAIN)))
 			continue;
 		if (len < 4) {
-		    if (errno != SLURM_PROTOCOL_SOCKET_ZERO_BYTES_SENT)
-			error("%s: read window size error: %m", __func__);
-		    return NULL;
+			if (errno != SLURM_PROTOCOL_SOCKET_ZERO_BYTES_SENT) {
+				error("%s: read window size error: %m",
+				      __func__);
+			}
+			return NULL;
 		}
 		memcpy(&winsz.cols, buf, 2);
 		memcpy(&winsz.rows, buf+2, 2);