Skip to content

Commit e8004d4

Browse files
committed
broker: run rc scripts directly
Problem: rc1, rc3 scripts are run with shell -c <script> but they could be executed directly. Run scripts directly. Adjust one test.
1 parent 06d97b9 commit e8004d4

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

src/broker/broker.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -757,11 +757,11 @@ static int create_runat_phases (broker_ctx_t *ctx)
757757
/* rc1 - initialization
758758
*/
759759
if (rc1 && strlen (rc1) > 0) {
760-
if (runat_push_shell_command (ctx->runat,
761-
"rc1",
762-
rc1,
763-
RUNAT_FLAG_LOG_STDIO) < 0) {
764-
log_err ("runat_push_shell_command rc1");
760+
if (runat_push_command_line (ctx->runat,
761+
"rc1",
762+
rc1,
763+
RUNAT_FLAG_LOG_STDIO) < 0) {
764+
log_err ("runat_push_command_line rc1");
765765
return -1;
766766
}
767767
}
@@ -780,23 +780,23 @@ static int create_runat_phases (broker_ctx_t *ctx)
780780
/* shutdown - clean up in preparation for instance shutdown
781781
*/
782782
if (ctx->rank == 0 && shutdown && strlen (shutdown) > 0) {
783-
if (runat_push_shell_command (ctx->runat,
784-
"shutdown",
783+
if (runat_push_command_line (ctx->runat,
784+
"shutdown",
785785
shutdown,
786786
RUNAT_FLAG_LOG_STDIO) < 0) {
787-
log_err ("runat_push_shell_command shutdown");
787+
log_err ("runat_push_command_line shutdown");
788788
return -1;
789789
}
790790
}
791791

792792
/* rc3 - finalization
793793
*/
794794
if (rc3 && strlen (rc3) > 0) {
795-
if (runat_push_shell_command (ctx->runat,
796-
"rc3",
797-
rc3,
798-
RUNAT_FLAG_LOG_STDIO) < 0) {
799-
log_err ("runat_push_shell_command rc3");
795+
if (runat_push_command_line (ctx->runat,
796+
"rc3",
797+
rc3,
798+
RUNAT_FLAG_LOG_STDIO) < 0) {
799+
log_err ("runat_push_command_line rc3");
800800
return -1;
801801
}
802802
}

src/broker/runat.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "src/common/libczmqcontainers/czmq_containers.h"
3838
#include "src/common/libutil/log.h"
3939
#include "src/common/libutil/monotime.h"
40+
#include "src/common/libutil/errno_safe.h"
4041
#include "ccan/str/str.h"
4142

4243
#include "runat.h"
@@ -552,6 +553,29 @@ int runat_push_command (struct runat *r,
552553
return -1;
553554
}
554555

556+
int runat_push_command_line (struct runat *r,
557+
const char *name,
558+
const char *cmdline,
559+
int flags)
560+
{
561+
int rc;
562+
char *argz = NULL;
563+
size_t argz_len = 0;
564+
565+
if (!cmdline) {
566+
errno = EINVAL;
567+
return -1;
568+
}
569+
rc = argz_create_sep (cmdline, ' ', &argz, &argz_len);
570+
if (rc != 0) {
571+
errno = rc;
572+
return -1;
573+
}
574+
rc = runat_push_command (r, name, argz, argz_len, flags);
575+
ERRNO_SAFE_WRAP (free, argz);
576+
return rc;
577+
}
578+
555579
int runat_get_exit_code (struct runat *r, const char *name, int *rc)
556580
{
557581
struct runat_entry *entry;

src/broker/runat.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ int runat_push_command (struct runat *r,
5454
size_t argz_len,
5555
int flags);
5656

57+
/* Same but with command specified by cmdline.
58+
*/
59+
int runat_push_command_line (struct runat *r,
60+
const char *name,
61+
const char *cmdline,
62+
int flags);
63+
5764
/* Get exit code of completed command list.
5865
* If multiple commands fail, the exit code is that of the first failure.
5966
*/

t/t0014-runlevel.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test_expect_success 'rc1 failure causes instance failure' '
2828
test_expect_success 'rc1 bad path handled same as failure' '
2929
(
3030
SHELL=/bin/sh &&
31-
test_expect_code 127 flux start \
31+
test_expect_code 1 flux start \
3232
-o,-Sbroker.rc1_path=rc1-nonexist \
3333
-o,-Sbroker.rc3_path= \
3434
-o,-Sbroker.shutdown_path= \

0 commit comments

Comments
 (0)