diff --git a/source/libs/sgeobj/sge_jsv_script.cc b/source/libs/sgeobj/sge_jsv_script.cc index e3b8604ba..5d0bca152 100644 --- a/source/libs/sgeobj/sge_jsv_script.cc +++ b/source/libs/sgeobj/sge_jsv_script.cc @@ -34,6 +34,8 @@ #include #include +#include +#include #include "uti/sge_binding_parse.h" #include "uti/sge_dstring.h" @@ -43,8 +45,6 @@ #include "uti/sge_string.h" #include "uti/sge_time.h" -#include "sge_daemonize.h" - #include "sgeobj/cull_parse_util.h" #include "sgeobj/sge_answer.h" #include "sgeobj/sge_ckpt.h" @@ -65,13 +65,15 @@ #include "symbols.h" #include "msg_common.h" +#include + /* * defines the timeout how long a client/qmaster would wait maximally for * a response from a JSV script after a command string has been send */ #define JSV_CMD_TIMEOUT (10) -typedef bool (*jsv_command_f)(lListElem *jsv, lList **answer_list, dstring *c, dstring *s, dstring *a); +typedef bool (*jsv_command_f)(lListElem *jsv, lList **answer_list, const dstring *c, const dstring *s, const dstring *a); typedef struct jsv_command_t_ jsv_command_t; @@ -81,26 +83,18 @@ struct jsv_command_t_ { }; static bool -jsv_split_commandline(const char *input, dstring *command, dstring *subcommand, dstring *args) -{ - bool ret = true; - +jsv_split_commandline(const char *input, dstring *command, dstring *subcommand, dstring *args) { DENTER(TOP_LAYER); if (input != nullptr) { - struct saved_vars_s *cntx = nullptr; - const char *token1 = sge_strtok_r(input, " ", &cntx); - - if (token1 != nullptr) { - const char *token2; + struct saved_vars_s *ctx = nullptr; + if (const char *token1 = sge_strtok_r(input, " ", &ctx); token1 != nullptr) { sge_dstring_append(command, token1); - token2 = sge_strtok_r(nullptr, " ", &cntx); - if (token2 != nullptr) { - bool first = true; - const char *arg = nullptr; + if (const char *token2 = sge_strtok_r(nullptr, " ", &ctx); token2 != nullptr) { + bool first = true; sge_dstring_append(subcommand, token2); - arg = sge_strtok_r(nullptr, " ", &cntx); + const char *arg = sge_strtok_r(nullptr, " ", &ctx); while (arg != nullptr) { if (first) { first = false; @@ -108,32 +102,27 @@ jsv_split_commandline(const char *input, dstring *command, dstring *subcommand, sge_dstring_append(args, " "); } sge_dstring_append(args, arg); - arg = sge_strtok_r(nullptr, " ", &cntx); + arg = sge_strtok_r(nullptr, " ", &ctx); } } } - sge_free_saved_vars(cntx); + sge_free_saved_vars(ctx); } - DRETURN(ret); + DRETURN(true); } static bool -jsv_split_token(dstring *input, dstring *token, dstring *args) -{ - const char *i = sge_dstring_get_string(input); - bool ret = true; - +jsv_split_token(const dstring *input, dstring *token, dstring *args) { DENTER(TOP_LAYER); - if (i != nullptr) { - struct saved_vars_s *cntx = nullptr; - const char *token1 = sge_strtok_r(i, " ", &cntx); - if (token1 != nullptr) { + if (const char *i = sge_dstring_get_string(input); i != nullptr) { + struct saved_vars_s *ctx = nullptr; + + if (const char *token1 = sge_strtok_r(i, " ", &ctx); token1 != nullptr) { bool first = true; - const char *arg = nullptr; sge_dstring_append(token, token1); - arg = sge_strtok_r(nullptr, " ", &cntx); + const char *arg = sge_strtok_r(nullptr, " ", &ctx); while (arg != nullptr) { if (first) { first = false; @@ -141,17 +130,16 @@ jsv_split_token(dstring *input, dstring *token, dstring *args) sge_dstring_append(args, " "); } sge_dstring_append(args, arg); - arg = sge_strtok_r(nullptr, " ", &cntx); + arg = sge_strtok_r(nullptr, " ", &ctx); } } - sge_free_saved_vars(cntx); + sge_free_saved_vars(ctx); } - DRETURN(ret); + DRETURN(true); } static bool -jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstring *s, dstring *a) -{ +jsv_handle_param_command(lListElem *jsv, lList **answer_list, const dstring *c, const dstring *s, const dstring *a) { bool ret = true; const char *param = sge_dstring_get_string(s); const char *value = sge_dstring_get_string(a); @@ -160,7 +148,7 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin if (param != nullptr) { bool skip_check = false; lList *local_answer_list = nullptr; - lListElem *new_job = (lListElem *)lGetRef(jsv, JSV_new_job); + auto *new_job = static_cast(lGetRef(jsv, JSV_new_job)); /* * If we get a "__JSV_TEST_RESULT" then this code is triggered as part of a @@ -187,8 +175,7 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin while (read_only_param[i] != nullptr) { if (strcmp(param, read_only_param[i]) == 0) { - answer_list_add_sprintf(&local_answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_READ_S, param); + answer_list_add_sprintf(&local_answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_READ_S, param); ret = false; break; } @@ -212,12 +199,10 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin if (strcmp(param, read_only_param[i]) == 0) { is_readonly = true; if (value == nullptr) { - answer_list_add_sprintf(&local_answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_BOOL_S, param); + answer_list_add_sprintf(&local_answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_BOOL_S, param); ret = false; } else if (strcmp(value, "y") != 0 && strcmp(value, "n") != 0) { - answer_list_add_sprintf(&local_answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_VAL_SS, param, value); + answer_list_add_sprintf(&local_answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_VAL_SS, param, value); ret = false; } break; @@ -238,8 +223,7 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin } else if (strcmp(param, "shell") == 0) { job_set_no_shell(new_job, strcmp(value, "y") == 0 ? true : false); } else { - answer_list_add_sprintf(&local_answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_VAL_SS, param); + answer_list_add_sprintf(&local_answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_VAL_SS, param); ret = false; } } @@ -251,14 +235,8 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin */ if (ret) { int i = 0; - const char *string_param[] = { - "A", "ckpt", "cwd", "N", "pe_name", "P", - nullptr - }; - const int string_attribute[] = { - JB_account, JB_checkpoint_name, JB_cwd, JB_job_name, JB_pe, JB_project, - 0 - }; + const char *string_param[] = {"A", "ckpt", "cwd", "N", "pe_name", "P", nullptr}; + constexpr int string_attribute[] = {JB_account, JB_checkpoint_name, JB_cwd, JB_job_name, JB_pe, JB_project, 0}; while (string_param[i] != nullptr) { int attribute = string_attribute[i]; @@ -270,8 +248,7 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin * - resetting ckpt name also resets ckpt attribute */ if (strcmp(param, "N") == 0) { - answer_list_add_sprintf(&local_answer_list, STATUS_DENIED, - ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_NAME_S, param); + answer_list_add_sprintf(&local_answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_NAME_S, param); ret = false; } else if (strcmp(param, "ckpt") == 0) { lSetUlong(new_job, JB_checkpoint_attr, NO_CHECKPOINT); @@ -294,14 +271,8 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin */ if (ret) { int i = 0; - const char *path_list_param[] = { - "o", "i", "e", "S", - nullptr - }; - const int path_list_attribute[] = { - JB_stdout_path_list, JB_stdin_path_list, JB_stderr_path_list, JB_shell_list, - 0 - }; + const char *path_list_param[] = {"o", "i", "e", "S", nullptr}; + constexpr int path_list_attribute[] = {JB_stdout_path_list, JB_stdin_path_list, JB_stderr_path_list, JB_shell_list, 0}; while (path_list_param[i] != nullptr) { if (strcmp(path_list_param[i], param) == 0) { @@ -309,12 +280,8 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin int attribute = path_list_attribute[i]; if (value != nullptr) { - int lret = cull_parse_path_list(&path_list, value); - - if (lret) { - answer_list_add_sprintf(&local_answer_list, STATUS_DENIED, - ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_VAL_SS, - param, value); + if (int local_ret = cull_parse_path_list(&path_list, value); local_ret != 0) { + answer_list_add_sprintf(&local_answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_VAL_SS, param, value); ret = false; } } @@ -331,26 +298,23 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin { if (ret && strncmp("CMDARG", param, 6) == 0) { lList *arg_list = lGetListRW(new_job, JB_job_args); - lListElem *elem; u_long32 id = 0; - u_long32 length, i; - const char *id_string = param + 6; - if (!isdigit(id_string[0])) { + u_long32 length; + if (const char *id_string = param + 6; !isdigit(id_string[0])) { if (value) { - u_long32 to_create = 0; - u_long32 to_remove = 0; length = lGetNumberOfElem(arg_list); ret &= ulong_parse_from_string(&id, &local_answer_list, value); if (ret) { if (id > length) { - to_create = id - length; + u_long32 to_create = id - length; + while (to_create > 0) { lAddElemStr(&arg_list, ST_name, "", ST_Type); to_create--; } } else { - to_remove = length - id; + u_long32 to_remove = length - id; while (to_remove > 0) { lListElem *tmp = lLastRW(arg_list); lRemoveElem(arg_list, &tmp); @@ -360,11 +324,11 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin } } } else { - u_long32 to_create = 0; length = lGetNumberOfElem(arg_list); ret &= ulong_parse_from_string(&id, &local_answer_list, id_string); if (id > length) { + u_long32 to_create = 0; to_create = id - length + 1; while (to_create > 0) { lAddElemStr(&arg_list, ST_name, "", ST_Type); @@ -373,7 +337,8 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin } length = lGetNumberOfElem(arg_list); - elem = lFirstRW(arg_list); + lListElem *elem = lFirstRW(arg_list); + u_long32 i; for (i = 0; i <= length - 1; i++) { if (i == id) { lSetString(elem, ST_name, (value != nullptr) ? value : ""); @@ -391,9 +356,7 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin u_long32 timeval = 0; if (value != nullptr) { - int lret = ulong_parse_date_time_from_string(&timeval, &local_answer_list, value); - - if (!lret) { + if (int local_ret = ulong_parse_date_time_from_string(&timeval, &local_answer_list, value); !local_ret) { ret = false; } } @@ -410,9 +373,7 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin lList *context_list = nullptr; if (value != nullptr) { - int lret = var_list_parse_from_string(&context_list, value, 0); - - if (lret) { + if (int local_ret = var_list_parse_from_string(&context_list, value, 0); local_ret != 0) { answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_VAL_SS, param, value); ret = false; @@ -433,9 +394,7 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin lList *ar_id_list = nullptr; ret &= ulong_list_parse_from_string(&ar_id_list, &local_answer_list, value, ","); if (ret) { - const lListElem *first = lFirst(ar_id_list); - - if (first != nullptr) { + if (const lListElem *first = lFirst(ar_id_list); first != nullptr) { id = lGetUlong(first, ULNG_value); } } @@ -454,9 +413,7 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin u_long32 timeval = 0; if (value != nullptr) { - int lret = ulong_parse_date_time_from_string(&timeval, &local_answer_list, value); - - if (!lret) { + if (int local_ret = ulong_parse_date_time_from_string(&timeval, &local_answer_list, value); !local_ret) { ret = false; } } @@ -465,13 +422,10 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin } } if (ret && strcmp("c_occasion", param) == 0) { - int lret = sge_parse_checkpoint_attr(value); - - if (lret != 0) { - lSetUlong(new_job, JB_checkpoint_interval, lret); + if (int local_ret = sge_parse_checkpoint_attr(value); local_ret != 0) { + lSetUlong(new_job, JB_checkpoint_interval, local_ret); } else { - answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_VAL_SS, param, value); + answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_VAL_SS, param, value); ret = false; } } @@ -502,9 +456,7 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin u_long32 timeval = 0; if (value != nullptr) { - int lret = ulong_parse_date_time_from_string(&timeval, &local_answer_list, value); - - if (!lret) { + if (int local_ret = ulong_parse_date_time_from_string(&timeval, &local_answer_list, value); !local_ret) { ret = false; } } @@ -548,9 +500,8 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin const lListElem *jid_str; if (value != nullptr) { - int lret = cull_parse_jid_hold_list(&hold_list, value); - if (lret) { + if (int local_ret = cull_parse_jid_hold_list(&hold_list, value); local_ret) { answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_VAL_SS, param, value); ret = false; @@ -569,17 +520,14 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin if (ret && strcmp("hold_jid_ad", param) == 0) { lList *hold_list = nullptr; lList *jref_list = nullptr; - const lListElem *jid_str; if (value != nullptr) { - int lret = cull_parse_jid_hold_list(&hold_list, value); - - if (lret) { - answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_VAL_SS, param, value); + if (int local_ret = cull_parse_jid_hold_list(&hold_list, value); local_ret) { + answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_VAL_SS, param, value); ret = false; } } + const lListElem *jid_str; for_each_ep(jid_str, hold_list) { lAddElemStr(&jref_list, JRE_job_name, lGetString(jid_str, ST_name), JRE_Type); } @@ -607,160 +555,132 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin } /* -l */ - { - if (ret && strcmp("l_hard", param) == 0) { - lList *resource_list = nullptr; - - if (value != nullptr) { - resource_list = centry_list_parse_from_string(nullptr, value, false); - - if (!resource_list) { - answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_VAL_SS, param, value); - ret = false; - } - } - if (ret) { - job_set_hard_resource_list(new_job, resource_list); - } + if (ret) { + bool is_l_request = true; + bool is_hard = true; + int scope = JRS_SCOPE_GLOBAL; + + if (strcmp("global_l_hard", param) == 0 || strcmp("l_hard", param) == 0) { + is_hard = true; + scope = JRS_SCOPE_GLOBAL; + } else if (strcmp("global_l_soft", param) == 0 || strcmp("l_soft", param) == 0) { + is_hard = false; + scope = JRS_SCOPE_GLOBAL; + } else if (strcmp("master_l_hard", param) == 0) { + is_hard = true; + scope = JRS_SCOPE_MASTER; + } else if (strcmp("slave_l_hard", param) == 0) { + is_hard = true; + scope = JRS_SCOPE_SLAVE; + } else { + is_l_request = false; } - if (ret && strcmp("l_soft", param) == 0) { + + if (is_l_request) { lList *resource_list = nullptr; if (value != nullptr) { resource_list = centry_list_parse_from_string(nullptr, value, false); - - if (!resource_list) { - answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_VAL_SS, param, value); + if (resource_list == nullptr) { + answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_VAL_SS, param, value); ret = false; } } - if (ret) { - job_set_soft_resource_list(new_job, resource_list); - } + job_set_resource_list(new_job, resource_list, scope, is_hard); } } /* -m */ - { - if (ret && strcmp("m", param) == 0) { - int mail_options = NO_MAIL; + if (ret && strcmp("m", param) == 0) { + int mail_options = NO_MAIL; - if (value != nullptr) { - mail_options = sge_parse_mail_options(&local_answer_list, value, QSUB); - if (!mail_options) { - ret = false; - } + if (value != nullptr) { + mail_options = sge_parse_mail_options(&local_answer_list, value, QSUB); + if (!mail_options) { + ret = false; } - if (ret) { - if (mail_options & NO_MAIL) { - lSetUlong(new_job, JB_mail_options, 0); - } else { - lSetUlong(new_job, JB_mail_options, mail_options); - } + } + if (ret) { + if (mail_options & NO_MAIL) { + lSetUlong(new_job, JB_mail_options, 0); + } else { + lSetUlong(new_job, JB_mail_options, mail_options); } } } /* -masterq ; -soft -q ; -hard -q*/ - { - if (ret && strcmp("masterq", param) == 0) { - lList *id_list = nullptr; - - if (value != nullptr) { - int lret = cull_parse_destination_identifier_list(&id_list, value); - - if (lret) { - answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, - MSG_PARSE_WRONGDESTIDLISTFORMATXSPECTOXOPTION_SS, - value, "-masterq"); - ret = false; - } - } - if (ret) { - job_set_master_hard_queue_list(new_job, id_list); - } - } else if (ret && strcmp("q_hard", param) == 0) { - lList *id_list = nullptr; - - if (value != nullptr) { - int lret = cull_parse_destination_identifier_list(&id_list, value); + if (ret) { + bool is_q_request = true; + bool is_hard = true; + int scope = JRS_SCOPE_GLOBAL; + + if (strcmp("global_q_hard", param) == 0 || strcmp("q_hard", param) == 0) { + is_hard = true; + scope = JRS_SCOPE_GLOBAL; + } else if (strcmp("global_q_soft", param) == 0 || strcmp("q_soft", param) == 0) { + is_hard = false; + scope = JRS_SCOPE_GLOBAL; + } else if (strcmp("master_q_hard", param) == 0 || strcmp("masterq", param) == 0) { + is_hard = true; + scope = JRS_SCOPE_MASTER; + } else if (strcmp("slave_q_hard", param) == 0) { + is_hard = true; + scope = JRS_SCOPE_SLAVE; + } else { + is_q_request = false; + } - if (lret) { - answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, - MSG_PARSE_WRONGDESTIDLISTFORMATXSPECTOXOPTION_SS, - value, "-q"); - ret = false; - } - } - if (ret) { - job_set_hard_queue_list(new_job, id_list); - } - } else if (ret && strcmp("q_soft", param) == 0) { + if (is_q_request) { lList *id_list = nullptr; if (value != nullptr) { - int lret = cull_parse_destination_identifier_list(&id_list, value); - - if (lret) { + if (int local_ret = cull_parse_destination_identifier_list(&id_list, value); local_ret != 0) { answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, - MSG_PARSE_WRONGDESTIDLISTFORMATXSPECTOXOPTION_SS, - value, "-q"); + MSG_PARSE_WRONGDESTIDLISTFORMATXSPECTOXOPTION_SS, value, param); ret = false; } } - if (ret) { - job_set_soft_queue_list(new_job, id_list); - } + job_set_queue_list(new_job, id_list, scope, is_hard); } } /* -M */ - { - if (ret && strcmp("M", param) == 0) { - lList *mail_list = nullptr; + if (ret && strcmp("M", param) == 0) { + lList *mail_list = nullptr; - if (value != nullptr) { - int lret = mailrec_parse(&mail_list, value); - - if (lret) { - answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_VAL_SS, param, value); - ret = false; - } - } - if (ret) { - lSetList(new_job, JB_mail_list, mail_list); + if (value != nullptr) { + if (int local_ret = mailrec_parse(&mail_list, value); local_ret) { + answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_VAL_SS, param, value); + ret = false; } } + if (ret) { + lSetList(new_job, JB_mail_list, mail_list); + } } /* -p */ - { - if (ret && strcmp("p", param) == 0) { - int priority = 0; + if (ret && strcmp("p", param) == 0) { + int priority = 0; - if (value != nullptr) { - ret = ulong_parse_priority(&local_answer_list, &priority, value); - } - if (ret) { - lSetUlong(new_job, JB_priority, BASE_PRIORITY + priority); - } + if (value != nullptr) { + ret = ulong_parse_priority(&local_answer_list, &priority, value); + } + if (ret) { + lSetUlong(new_job, JB_priority, BASE_PRIORITY + priority); } } /* -tc */ - { - if (ret && strcmp("tc", param) == 0) { - int max_tasks = 0; + if (ret && strcmp("tc", param) == 0) { + int max_tasks = 0; - if (value != nullptr) { - ret = ulong_parse_task_concurrency(&local_answer_list, &max_tasks, value); - } - if (ret) { - lSetUlong(new_job, JB_ja_task_concurrency, max_tasks); - } + if (value != nullptr) { + ret = ulong_parse_task_concurrency(&local_answer_list, &max_tasks, value); + } + if (ret) { + lSetUlong(new_job, JB_ja_task_concurrency, max_tasks); } } @@ -947,7 +867,6 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin } /* 4) */ if (ret) { - bool do_resize = false; const char *old_param_exp_value = lGetString(binding_elem, BN_parameter_explicit); ret &= binding_explicit_extract_sockets_cores(old_param_exp_value, @@ -966,14 +885,16 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin ret = true; } if (ret) { + bool do_resize = false; + if (has_new_length) { do_resize = true; } - if (has_new_socket && new_socket_id + 1 > (u_long32)sockets) { + if (has_new_socket && new_socket_id + 1 > static_cast(sockets)) { do_resize = true; new_length = new_socket_id + 1; } - if (has_new_core && new_core_id + 1 > (u_long32)cores) { + if (has_new_core && new_core_id + 1 > static_cast(cores)) { do_resize = true; new_length = new_core_id + 1; } @@ -981,8 +902,8 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin if (do_resize) { size_t i; - socket_array = (int *)realloc(socket_array, new_length * sizeof(int)); - core_array = (int *)realloc(core_array, new_length * sizeof(int)); + socket_array = static_cast(realloc(socket_array, new_length * sizeof(int))); + core_array = static_cast(realloc(core_array, new_length * sizeof(int))); for (i = sockets; i < new_length; i++) { socket_array[i] = 0; } @@ -1004,11 +925,8 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin if (ret) { dstring socket_core_string = DSTRING_INIT; - binding_printf_explicit_sockets_cores(&socket_core_string, - socket_array, sockets, - core_array, cores); - lSetString(binding_elem, BN_parameter_explicit, - sge_dstring_get_string(&socket_core_string)); + binding_printf_explicit_sockets_cores(&socket_core_string, socket_array, sockets, core_array, cores); + lSetString(binding_elem, BN_parameter_explicit, sge_dstring_get_string(&socket_core_string)); sge_dstring_free(&socket_core_string); } @@ -1021,56 +939,52 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin /* * -pe name n-m */ - { - if (ret && strcmp("pe_name", param) == 0) { - if (value) { - lSetString(new_job, JB_pe, value); - } else { - lSetString(new_job, JB_pe, nullptr); - } + if (ret && strcmp("pe_name", param) == 0) { + if (value) { + lSetString(new_job, JB_pe, value); + } else { + lSetString(new_job, JB_pe, nullptr); } - if (ret && strcmp("pe_min", param) == 0) { - u_long32 min = 0; + } + if (ret && strcmp("pe_min", param) == 0) { + u_long32 min = 0; - if (value != nullptr) { - if (!parse_ulong_val(nullptr, &min, TYPE_INT, value, nullptr, 0)) { - answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_VAL_SS, param, value); - ret = false; - } + if (value != nullptr) { + if (!parse_ulong_val(nullptr, &min, TYPE_INT, value, nullptr, 0)) { + answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_VAL_SS, param, value); + ret = false; } - if (ret) { - const lList *range_list = lGetList(new_job, JB_pe_range); - lListElem *range = lFirstRW(range_list); + } + if (ret) { + const lList *range_list = lGetList(new_job, JB_pe_range); + lListElem *range = lFirstRW(range_list); - if (range == nullptr) { - range = lAddSubUlong(new_job, RN_min, min, JB_pe_range, RN_Type); - } - if (range != nullptr) { - lSetUlong(range, RN_min, min); - } + if (range == nullptr) { + range = lAddSubUlong(new_job, RN_min, min, JB_pe_range, RN_Type); + } + if (range != nullptr) { + lSetUlong(range, RN_min, min); } } - if (ret && strcmp("pe_max", param) == 0) { - u_long32 max = 0; + } + if (ret && strcmp("pe_max", param) == 0) { + u_long32 max = 0; - if (value != nullptr) { - if (!parse_ulong_val(nullptr, &max, TYPE_INT, value, nullptr, 0)) { - answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_VAL_SS, param, value); - ret = false; - } + if (value != nullptr) { + if (!parse_ulong_val(nullptr, &max, TYPE_INT, value, nullptr, 0)) { + answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_VAL_SS, param, value); + ret = false; } - if (ret) { - const lList *range_list = lGetList(new_job, JB_pe_range); - lListElem *range = lFirstRW(range_list); + } + if (ret) { + const lList *range_list = lGetList(new_job, JB_pe_range); + lListElem *range = lFirstRW(range_list); - if (range == nullptr) { - range = lAddSubUlong(new_job, RN_max, max, JB_pe_range, RN_Type); - } - if (range != nullptr) { - lSetUlong(range, RN_max, max); - } + if (range == nullptr) { + range = lAddSubUlong(new_job, RN_max, max, JB_pe_range, RN_Type); + } + if (range != nullptr) { + lSetUlong(range, RN_max, max); } } } @@ -1078,85 +992,78 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin /* *-t n-m:s */ - { - if (ret && strcmp("t_min", param) == 0) { - if (value != nullptr) { - u_long32 min; - if (!parse_ulong_val(nullptr, &min, TYPE_INT, value, nullptr, 0)) { - answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, - "invalid t_min " SFQ " was passed by JSV", value); - ret = false; - } else { - const lList *range_list = lGetList(new_job, JB_ja_structure); - lListElem *range = lFirstRW(range_list); + if (ret && strcmp("t_min", param) == 0) { + if (value != nullptr) { + u_long32 min; + if (!parse_ulong_val(nullptr, &min, TYPE_INT, value, nullptr, 0)) { + answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, "invalid t_min " SFQ " was passed by JSV", value); + ret = false; + } else { + const lList *range_list = lGetList(new_job, JB_ja_structure); + lListElem *range = lFirstRW(range_list); - if (range == nullptr) { - range = lAddSubUlong(new_job, RN_min, min, JB_ja_structure, RN_Type); - } - if (range != nullptr) { - lSetUlong(range, RN_min, min); - } + if (range == nullptr) { + range = lAddSubUlong(new_job, RN_min, min, JB_ja_structure, RN_Type); + } + if (range != nullptr) { + lSetUlong(range, RN_min, min); } } } - if (ret && strcmp("t_max", param) == 0) { - if (value != nullptr) { - u_long32 max; - if (!parse_ulong_val(nullptr, &max, TYPE_INT, value, nullptr, 0)) { - answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_VAL_SS, param, value); - ret = false; - } else { - const lList *range_list = lGetList(new_job, JB_ja_structure); - lListElem *range = lFirstRW(range_list); + } + if (ret && strcmp("t_max", param) == 0) { + if (value != nullptr) { + u_long32 max; + if (!parse_ulong_val(nullptr, &max, TYPE_INT, value, nullptr, 0)) { + answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_VAL_SS, param, value); + ret = false; + } else { + const lList *range_list = lGetList(new_job, JB_ja_structure); + lListElem *range = lFirstRW(range_list); - if (range == nullptr) { - range = lAddSubUlong(new_job, RN_max, max, JB_ja_structure, RN_Type); - } - if (range != nullptr) { - lSetUlong(range, RN_max, max); - } + if (range == nullptr) { + range = lAddSubUlong(new_job, RN_max, max, JB_ja_structure, RN_Type); + } + if (range != nullptr) { + lSetUlong(range, RN_max, max); } } } - if (ret && strcmp("t_step", param) == 0) { - if (value != nullptr) { - u_long32 step; - if (!parse_ulong_val(nullptr, &step, TYPE_INT, value, nullptr, 0)) { - answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_VAL_SS, param, value); - ret = false; - } else { - const lList *range_list = lGetList(new_job, JB_ja_structure); - lListElem *range = lFirstRW(range_list); + } + if (ret && strcmp("t_step", param) == 0) { + if (value != nullptr) { + u_long32 step; + if (!parse_ulong_val(nullptr, &step, TYPE_INT, value, nullptr, 0)) { + answer_list_add_sprintf(&local_answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, + MSG_JSV_PARSE_VAL_SS, param, value); + ret = false; + } else { + const lList *range_list = lGetList(new_job, JB_ja_structure); + lListElem *range = lFirstRW(range_list); - if (range == nullptr) { - range = lAddSubUlong(new_job, RN_step, step, JB_ja_structure, RN_Type); - } - if (range != nullptr) { - lSetUlong(range, RN_step, step); - } + if (range == nullptr) { + range = lAddSubUlong(new_job, RN_step, step, JB_ja_structure, RN_Type); + } + if (range != nullptr) { + lSetUlong(range, RN_step, step); } } } } /* -w */ - { - if (ret && strcmp("w", param) == 0) { - int level = 0; + if (ret && strcmp("w", param) == 0) { + int level = 0; - if (value != nullptr) { - ret = job_parse_validation_level(&level, value, QSUB, &local_answer_list); + if (value != nullptr) { + ret = job_parse_validation_level(&level, value, QSUB, &local_answer_list); - DPRINTF("result of parsing is %d\n", ret); - - } - if (ret) { - lSetUlong(new_job, JB_verify_suitable_queues, level); - } - } + DPRINTF("result of parsing is %d\n", ret); + } + if (ret) { + lSetUlong(new_job, JB_verify_suitable_queues, level); + } } /* @@ -1168,17 +1075,13 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin */ if (lGetBool(jsv, JSV_test) && !skip_check) { const char *result_string = lGetString(jsv, JSV_result); - u_long32 result_pos = lGetUlong(jsv, JSV_test_pos); - if (strlen(result_string) > result_pos) { + if (u_long32 result_pos = lGetUlong(jsv, JSV_test_pos); strlen(result_string) > result_pos) { char result_char = result_string[result_pos]; - bool result = (result_char == '1') ? true : false; - if (result != ret) { - answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - "\"PARAM %s %s\" was unexcpectedly %s\n", - param, value != nullptr ? value : " ", - ret ? "accepted" : "rejected"); + if (bool result = (result_char == '1') ? true : false; result != ret) { + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, "\"PARAM %s %s\" was unexcpectedly %s\n", + param, value != nullptr ? value : " ", ret ? "accepted" : "rejected"); ret = false; } else { ret = true; @@ -1192,21 +1095,18 @@ jsv_handle_param_command(lListElem *jsv, lList **answer_list, dstring *c, dstrin } static bool -jsv_handle_send_command(lListElem *jsv, lList **answer_list, dstring *c, dstring *s, dstring *a) -{ +jsv_handle_send_command(lListElem *jsv, lList **answer_list, const dstring *c, const dstring *s, const dstring *a) { + DENTER(TOP_LAYER); bool ret = true; - const char *subcommand = sge_dstring_get_string(s); - DENTER(TOP_LAYER); - if (strcmp(subcommand, "ENV") == 0) { + if (const char *subcommand = sge_dstring_get_string(s); strcmp(subcommand, "ENV") == 0) { lSetBool(jsv, JSV_send_env, true); } else { /* * Invalid subcommand. JSV seems to wait for information which * is not available in this version. Job will be rejected. */ - answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - MSG_JSV_PARSE_OBJECT_S, sge_dstring_get_string(s)); + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, MSG_JSV_PARSE_OBJECT_S, sge_dstring_get_string(s)); lSetBool(jsv, JSV_send_env, false); ret = false; @@ -1215,20 +1115,17 @@ jsv_handle_send_command(lListElem *jsv, lList **answer_list, dstring *c, dstring } static bool -jsv_handle_result_command(lListElem *jsv, lList **answer_list, dstring *c, dstring *s, dstring *a) -{ +jsv_handle_result_command(lListElem *jsv, lList **answer_list, const dstring *c, const dstring *s, const dstring *a) { + DENTER(TOP_LAYER); bool ret = true; + dstring m = DSTRING_INIT; dstring st = DSTRING_INIT; - const char *sub_command = nullptr; - const char *state = nullptr; - const char *message = nullptr; - - DENTER(TOP_LAYER); - sub_command = sge_dstring_get_string(s); jsv_split_token(a, &st, &m); - state = sge_dstring_get_string(&st); - message = sge_dstring_get_string(&m); + + const char *sub_command = sge_dstring_get_string(s); + const char *state = sge_dstring_get_string(&st); + const char *message = sge_dstring_get_string(&m); if (sub_command != nullptr && strcmp(sub_command, "STATE") == 0 && state != nullptr) { if (strcmp(state, "ACCEPT") == 0) { DPRINTF("Job is accepted\n"); @@ -1241,33 +1138,27 @@ jsv_handle_result_command(lListElem *jsv, lList **answer_list, dstring *c, dstri } else if (strcmp(state, "REJECT") == 0) { DPRINTF("Job is rejected\n"); if (message != nullptr) { - answer_list_add_sprintf(answer_list, STATUS_DENIED, - ANSWER_QUALITY_ERROR, message); + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, message); } else { - answer_list_add_sprintf(answer_list, STATUS_DENIED, - ANSWER_QUALITY_ERROR, MSG_JSV_REJECTED); + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, MSG_JSV_REJECTED); } lSetBool(jsv, JSV_accept, false); lSetBool(jsv, JSV_done, true); } else if (strcmp(state, "REJECT_WAIT") == 0) { DPRINTF("Job is rejected temporarily\n"); if (message != nullptr) { - answer_list_add_sprintf(answer_list, STATUS_DENIED, - ANSWER_QUALITY_ERROR, message); + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, message); } else { - answer_list_add_sprintf(answer_list, STATUS_DENIED, - ANSWER_QUALITY_ERROR, MSG_JSV_TMPREJECT); + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, MSG_JSV_TMPREJECT); } lSetBool(jsv, JSV_accept, false); lSetBool(jsv, JSV_done, true); } else { - answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - MSG_JSV_STATE_S, a); + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, MSG_JSV_STATE_S, a); ret = false; } } else { - answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - MSG_JSV_COMMAND_S, sub_command); + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, MSG_JSV_COMMAND_S, sub_command); ret = false; } @@ -1280,84 +1171,113 @@ jsv_handle_result_command(lListElem *jsv, lList **answer_list, dstring *c, dstri } static bool -jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstring *s, dstring *a) -{ - const char *prefix = "PARAM"; +jsv_send_queue_list(lListElem *jsv, lList **answer_list, const char *prefix, const char *name, const lList *queue_list) { + DENTER(TOP_LAYER); + + if (queue_list != nullptr) { + dstring buffer = DSTRING_INIT; + sge_dstring_sprintf(&buffer, "%s %s", prefix, name); + + bool first = true; + const lListElem *queue; + for_each_ep(queue, queue_list) { + const char *queue_pattern = lGetString(queue, QR_name); + + sge_dstring_append_char(&buffer, first ? ' ' : ','); + sge_dstring_sprintf_append(&buffer, "%s", queue_pattern); + first = false; + } + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); + sge_dstring_free(&buffer); + } + DRETURN(true); +} + +static bool +jsv_send_resource_list(lListElem *jsv, lList **answer_list, const char *prefix, const char *name, const lList *resource_list) { + DENTER(TOP_LAYER); + if (resource_list != nullptr) { + dstring buffer = DSTRING_INIT; + sge_dstring_sprintf(&buffer, "%s %s ", prefix, name); + centry_list_append_to_dstring(resource_list, &buffer); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); + sge_dstring_free(&buffer); + } + DRETURN(true); +} + +static bool +jsv_send_path_list(lListElem *jsv, lList **answer_list, const char *prefix, const char *name, const lList *path_list) { + DENTER(TOP_LAYER); dstring buffer = DSTRING_INIT; - bool ret = true; - lListElem *old_job = (lListElem *)lGetRef(jsv, JSV_old_job); + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s %s", prefix, name); + + const lListElem *shell; + bool first = true; + for_each_ep(shell, path_list) { + sge_dstring_append_char(&buffer, first ? ' ' : ','); + if (const char *hostname = lGetHost(shell, PN_host); + hostname != nullptr) { + sge_dstring_append(&buffer, hostname); + sge_dstring_append_char(&buffer, ':'); + } + sge_dstring_append(&buffer, lGetString(shell, PN_path)); + first = false; + } + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); + sge_dstring_free(&buffer); + DRETURN(true); +} +static bool +jsv_handle_started_command(lListElem *jsv, lList **answer_list, const dstring *c, const dstring *s, const dstring *a) { DENTER(TOP_LAYER); + const auto prefix = "PARAM"; + dstring buffer = DSTRING_INIT; + bool ret = true; + auto *old_job = static_cast(lGetRef(jsv, JSV_old_job)); - /* reset variables which are only used in test cases */ + // reset variables which are only used in test cases lSetBool(jsv, JSV_test, false); lSetString(jsv, JSV_result, ""); - /* - * JSV VERSION . - * read-only - */ + // JSV VERSION . (read-only) sge_dstring_clear(&buffer); sge_dstring_sprintf(&buffer, "%s VERSION 1.0", prefix); jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - /* - * JSV CONTEXT "client"|"server" - * read-only - */ + // JSV CONTEXT "client"|"server" (read-only) sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s CONTEXT %s", prefix, - (strcmp(lGetString(jsv, JSV_context), JSV_CONTEXT_CLIENT) == 0 ? "client" : "server")); + sge_dstring_sprintf(&buffer, "%s CONTEXT %s", prefix, (strcmp(lGetString(jsv, JSV_context), JSV_CONTEXT_CLIENT) == 0 ? "client" : "server")); jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - /* - * JSV CLIENT - * read-only - */ - { - u_long32 progid = component_get_component_id(); - - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s CLIENT %s", prefix, prognames[progid]); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + // JSV CLIENT (read-only) + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s CLIENT %s", prefix, prognames[component_get_component_id()]); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - /* - * JSV USER - * read-only - */ + // JSV USER (read-only) sge_dstring_clear(&buffer); sge_dstring_sprintf(&buffer, "%s USER %s", prefix, lGetString(old_job, JB_owner)); jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - /* - * JSV GROUP - * read-only - */ + // JSV GROUP (read-only) sge_dstring_clear(&buffer); sge_dstring_sprintf(&buffer, "%s GROUP %s", prefix, lGetString(old_job, JB_group)); jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - /* - * JSV JOB_ID - * optional; read-only - */ - { - u_long32 jid = lGetUlong(old_job, JB_job_number); - - if (jid > 0) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s JOB_ID " sge_u32, prefix, jid); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + // JSV JOB_ID (optional; read-only) + if (u_long32 jid = lGetUlong(old_job, JB_job_number); jid > 0) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s JOB_ID " sge_u32, prefix, jid); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* - * JSV COMMAND - * -b y ... => format := - * -b n ... => format := - * -b n => format := "STDIN" - */ + // JSV COMMAND + // -b y ... => format := + // -b n ... => format := + // -b n => format := "STDIN" { const char *script_name = lGetString(old_job, JB_script_file); @@ -1366,9 +1286,7 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* - * JSV SCRIPT_ARGS - */ + // JSV SCRIPT_ARGS { const lList *list = lGetList(old_job, JB_job_args); const lListElem *elem; @@ -1386,413 +1304,234 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr } } - /* - * -a - * PARAM a (optional; := CCYYMMDDhhmm.SS) - */ - { - time_t clocks = (time_t) lGetUlong64(old_job, JB_execution_time) / 1000000; - - if (clocks > 0) { - struct tm time_struct; + // -a + // PARAM a (optional; := CCYYMMDDhhmm.SS) + if (time_t clocks = static_cast(lGetUlong64(old_job, JB_execution_time)) / 1000000; clocks > 0) { + struct tm time_struct = {0}; - localtime_r(&clocks, &time_struct); - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s a %04d%02d%02d%02d%02d.%02d", prefix, - time_struct.tm_year + 1900, time_struct.tm_mon, - time_struct.tm_mday, time_struct.tm_hour, - time_struct.tm_min, time_struct.tm_sec); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + localtime_r(&clocks, &time_struct); + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s a %04d%02d%02d%02d%02d.%02d", prefix, time_struct.tm_year + 1900, time_struct.tm_mon, + time_struct.tm_mday, time_struct.tm_hour, time_struct.tm_min, time_struct.tm_sec); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* - * -ac variable[=value],... (optional; also contains result of -dc and -sc options) - */ - { - const lList *context_list = lGetList(old_job, JB_context); + // -ac variable[=value],... (optional; also contains result of -dc and -sc options) + if (const lList *context_list = lGetList(old_job, JB_context); context_list != nullptr) { + lListElem *tmp_job = lCopyElem(old_job); + lList* tmp = nullptr; + lXchgList(tmp_job, JB_context, &tmp); + set_context(tmp, tmp_job); + context_list = lGetList(tmp_job, JB_context); if (context_list != nullptr) { - lListElem *tmp_job = lCopyElem(old_job); - const lListElem *context = nullptr; - lList* tmp = nullptr; - - lXchgList(tmp_job, JB_context, &tmp); - set_context(tmp, tmp_job); - context_list = lGetList(tmp_job, JB_context); - if (context_list != nullptr) { - bool first = true; + bool first = true; - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "PARAM ac"); - for_each_ep(context, context_list) { - const char *name = lGetString(context, VA_variable); - const char *value = lGetString(context, VA_value); + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "PARAM ac"); + const lListElem *context = nullptr; + for_each_ep(context, context_list) { + const char *name = lGetString(context, VA_variable); + const char *value = lGetString(context, VA_value); - sge_dstring_sprintf_append(&buffer, (first) ? " " : ","); - first = false; - if (value != nullptr) { - sge_dstring_sprintf_append(&buffer, "%s=%s", name, value); - } else { - sge_dstring_sprintf_append(&buffer, "%s", name); - } + sge_dstring_sprintf_append(&buffer, (first) ? " " : ","); + first = false; + if (value != nullptr) { + sge_dstring_sprintf_append(&buffer, "%s=%s", name, value); + } else { + sge_dstring_sprintf_append(&buffer, "%s", name); } - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - lFreeList(&tmp); - lFreeElem(&tmp_job); - } - } - - /* - * -ar - * PARAM ar - * optional - */ - { - u_long32 ar_id = lGetUlong(old_job, JB_ar); - - if (ar_id > 0) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s ar " sge_u32, prefix, ar_id); jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } + lFreeList(&tmp); + lFreeElem(&tmp_job); } - /* - * -A (optional) - */ - { - const char *account_string = lGetString(old_job, JB_account); + // -ar (optional) + if (u_long32 ar_id = lGetUlong(old_job, JB_ar); ar_id > 0) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s ar " sge_u32, prefix, ar_id); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); + } - if (account_string != nullptr) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s A %s", prefix, account_string); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + // -A (optional) + if (const char *account_string = lGetString(old_job, JB_account); account_string != nullptr) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s A %s", prefix, account_string); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* - * -b y|n - * PARAM b y|n (optional; only available if -b y was specified) - */ + // -b y|n + // PARAM b y|n (optional; only available if -b y was specified) if (job_is_binary(old_job)) { sge_dstring_clear(&buffer); sge_dstring_sprintf(&buffer, "%s b %c", prefix, job_is_binary(old_job) ? 'y' : 'n'); jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* - * -c n|s|m|x or - * -c - * - * PARAM c_occasion (optional; := ['n']['s']['m']['x'] - * PARAM c_interval (optional; := <2_digits>:<2_digits>:<2_digits>) - */ - { - u_long32 interval = lGetUlong(old_job, JB_checkpoint_interval); - u_long32 attr = lGetUlong(old_job, JB_checkpoint_attr); - - if (interval > 0) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s c_interval ", prefix); - double_print_time_to_dstring((double)interval, &buffer); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } - if (attr > 0) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s c_occasion ", prefix); - job_get_ckpt_attr(attr, &buffer); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + // -c n|s|m|x or + // -c + // PARAM c_occasion (optional; := ['n']['s']['m']['x'] + // PARAM c_interval (optional; := <2_digits>:<2_digits>:<2_digits>) + if (u_long32 interval = lGetUlong(old_job, JB_checkpoint_interval); interval > 0) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s c_interval ", prefix); + double_print_time_to_dstring((double)interval, &buffer); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - - /* - * -ckpt name - * PARAM ckpt (optional); - */ - { - const char *ckpt = lGetString(old_job, JB_checkpoint_name); - - if (ckpt != nullptr) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s ckpt %s", prefix, ckpt); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + if (u_long32 attr = lGetUlong(old_job, JB_checkpoint_attr); attr > 0) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s c_occasion ", prefix); + job_get_ckpt_attr(attr, &buffer); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* - * -cwd - * - * Different to commandline. If -cwd was specified it will be exported to the - * JSV by passing the complete path. To remove the path the JSV has to - * pass an empty path. - * - * PARAM cwd (optional) - */ - { - const char *cwd = lGetString(old_job, JB_cwd); + // -ckpt name (optional) + if (const char *ckpt = lGetString(old_job, JB_checkpoint_name); ckpt != nullptr) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s ckpt %s", prefix, ckpt); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); + } - if (cwd != nullptr) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s cwd %s", prefix, cwd); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + // -cwd + // Different to commandline. If -cwd was specified it will be exported to the JSV by passing + // the complete path. To remove the path the JSV has to pass an empty path. (optional) + if (const char *cwd = lGetString(old_job, JB_cwd); cwd != nullptr) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s cwd %s", prefix, cwd); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } /* -C (not handled in JSV) */ /* -dc (handled as part of -ac parameter) */ /* -display (handled below where -v/-V is handled) */ - /* - * -dl - * optional - */ - { - time_t clocks = (time_t) lGetUlong64(old_job, JB_deadline) / 1000000; - - if (clocks > 0) { - struct tm time_struct; - - localtime_r(&clocks, &time_struct); - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s dl %04d%02d%02d%02d%02d.%02d", prefix, - time_struct.tm_year + 1900, time_struct.tm_mon, - time_struct.tm_mday, time_struct.tm_hour, - time_struct.tm_min, time_struct.tm_sec); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } - } + // -dl (optional) + if (time_t clocks = static_cast(lGetUlong64(old_job, JB_deadline)) / 1000000; clocks > 0) { + struct tm time_struct = {0}; - /* - * -e - */ - { - const lList *shell_list = lGetList(old_job, JB_stderr_path_list); - - if (shell_list != nullptr) { - const lListElem *shell; - bool first = true; - - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s e", prefix); - for_each_ep(shell, shell_list) { - const char *hostname = lGetHost(shell, PN_host); - const char *path = lGetString(shell, PN_path); - - - sge_dstring_append_char(&buffer, first ? ' ' : ','); - if (hostname != nullptr) { - sge_dstring_append(&buffer, hostname); - sge_dstring_append_char(&buffer, ':'); - sge_dstring_append(&buffer, path); - } else { - sge_dstring_append(&buffer, path); - } - first = false; - } - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + localtime_r(&clocks, &time_struct); + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s dl %04d%02d%02d%02d%02d.%02d", prefix, time_struct.tm_year + 1900, time_struct.tm_mon, + time_struct.tm_mday, time_struct.tm_hour, time_struct.tm_min, time_struct.tm_sec); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* -hard (handled as l_hard and q_hard below) */ + /* -hard (handled as [global|master|server]_[l|q]_hard */ - /* - * -hold_jid wc_job_list - * optional - */ - { - const lList *hold_jid_list = lGetList(old_job, JB_jid_request_list); - - if (hold_jid_list != nullptr) { - const lListElem *hold_jid; - bool first = true; - - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s hold_jid", prefix); - for_each_ep(hold_jid, hold_jid_list) { - const char *name = lGetString(hold_jid, JRE_job_name); - u_long32 jid = lGetUlong(hold_jid, JRE_job_number); - - sge_dstring_append_char(&buffer, first ? ' ' : ','); - if (name != nullptr) { - sge_dstring_sprintf_append(&buffer, "%s", name); - } else { - sge_dstring_sprintf_append(&buffer, sge_U32CFormat, sge_u32c(jid)); - } - first = false; + // -hold_jid wc_job_list (optional) + if (const lList *hold_jid_list = lGetList(old_job, JB_jid_request_list); hold_jid_list != nullptr) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s hold_jid", prefix); + const lListElem *hold_jid; + bool first = true; + for_each_ep(hold_jid, hold_jid_list) { + sge_dstring_append_char(&buffer, first ? ' ' : ','); + if (const char *name = lGetString(hold_jid, JRE_job_name); name != nullptr) { + sge_dstring_sprintf_append(&buffer, "%s", name); + } else { + sge_dstring_sprintf_append(&buffer, sge_U32CFormat, sge_u32c(lGetUlong(hold_jid, JRE_job_number))); } - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); + first = false; } + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* - * -hold_jid_ad wc_job_list - * optional - */ - { - const lList *hold_jid_list = lGetList(old_job, JB_ja_ad_request_list); - - if (hold_jid_list != nullptr) { - const lListElem *hold_jid; - bool first = true; - - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s hold_jid_ad", prefix); - for_each_ep(hold_jid, hold_jid_list) { - const char *name = lGetString(hold_jid, JRE_job_name); + // -hold_jid_ad wc_job_list (optional) + if (const lList *hold_jid_list = lGetList(old_job, JB_ja_ad_request_list); hold_jid_list != nullptr) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s hold_jid_ad", prefix); + bool first = true; + const lListElem *hold_jid; + for_each_ep(hold_jid, hold_jid_list) { + sge_dstring_append_char(&buffer, first ? ' ' : ','); + if (const char *name = lGetString(hold_jid, JRE_job_name); name != nullptr) { + sge_dstring_sprintf_append(&buffer, "%s", name); + } else { u_long32 jid = lGetUlong(hold_jid, JRE_job_number); - - sge_dstring_append_char(&buffer, first ? ' ' : ','); - if (name != nullptr) { - sge_dstring_sprintf_append(&buffer, "%s", name); - } else { - sge_dstring_sprintf_append(&buffer, sge_U32CFormat, sge_u32c(jid)); - } - first = false; + sge_dstring_sprintf_append(&buffer, sge_U32CFormat, sge_u32c(jid)); } - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } - } - - /* - * -h (optional; only available if job is in user hold) - * - * in difference with the qsub -h switch the setting is provided as - * - * PARAM h u|n - * - * where 'u' means "user hold" - * and 'n' whould mean "no hold" - */ - { - const lList *hold_list = lGetList(old_job, JB_ja_u_h_ids); - - if (hold_list != nullptr) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s h %c", prefix, (hold_list != nullptr) ? 'u' : 'n'); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); + first = false; } + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* - * -i (optional) - */ - { - const lList *shell_list = lGetList(old_job, JB_stdin_path_list); - - if (shell_list != nullptr) { - const lListElem *shell; - bool first = true; - - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s i", prefix); - for_each_ep(shell, shell_list) { - const char *hostname = lGetHost(shell, PN_host); - const char *path = lGetString(shell, PN_path); - - sge_dstring_append_char(&buffer, first ? ' ' : ','); - if (hostname != nullptr) { - sge_dstring_append(&buffer, hostname); - sge_dstring_append_char(&buffer, ':'); - sge_dstring_append(&buffer, path); - } else { - sge_dstring_append(&buffer, path); - } - first = false; - } - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + // -h (optional; only available if job is in user hold) + // + // in difference with the qsub -h switch the setting is provided as (PARAM h u) where 'u' means "user hold" + // 'n' would mean "no hold" but in this case the parameter is not provided to the JSV script + if (const lList *hold_list = lGetList(old_job, JB_ja_u_h_ids); hold_list != nullptr) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s h u", prefix); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* -inherit (not handled in JSV) */ + // -inherit (not handled in JSV) - /* - * -j y | n - * PARAM j y | n - * optional; only available when -j y was specified - */ - if (lGetBool(old_job, JB_merge_stderr)) { + // -j y | n (optional; only available when -j y was specified) + if (const bool merge = lGetBool(old_job, JB_merge_stderr)) { sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s j %c", prefix, lGetBool(old_job, JB_merge_stderr) ? 'y' : 'n'); + sge_dstring_sprintf(&buffer, "%s j %c", prefix, merge ? 'y' : 'n'); jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* - * -js job_share (optional) - */ - { - u_long32 job_share = lGetUlong(old_job, JB_jobshare); - - if (job_share > 0) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s js " sge_U32CFormat, prefix, sge_u32c(job_share)); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + // -js job_share (optional) + if (u_long32 job_share = lGetUlong(old_job, JB_jobshare); job_share > 0) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s js " sge_U32CFormat, prefix, sge_u32c(job_share)); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* - * -l (optional) - * - * -soft -l => - * PARAM l_soft - * - * -hard -l => - * PARAM l_hard - */ + // -l (optional) + // + // -scope GLOBAL -hard -l => + // PARAM global_l_hard + // PARAM l_hard (to be compatible with old JSV scripts) + // + // -scope GLOBAL -soft -l => + // PARAM global_l_soft + // PARAM l_soft (to be compatible with old JSV scripts) + // + // -scope MASTER -hard -l => + // PARAM master_l_hard + // + // -scope SLAVE -hard -l => + // PARAM slave_l_hard { - const lList *l_hard_list = job_get_hard_resource_list(old_job); - - if (l_hard_list != nullptr) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s l_hard ", prefix); - centry_list_append_to_dstring(l_hard_list, &buffer); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } - } - { - const lList *l_soft_list = job_get_soft_resource_list(old_job); - - if (l_soft_list != nullptr) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s l_soft ", prefix); - centry_list_append_to_dstring(l_soft_list, &buffer); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); + const std::vector>> resource_table = { + std::make_tuple(JRS_SCOPE_GLOBAL, true, std::vector{"global_l_hard", "l_hard"}), + std::make_tuple(JRS_SCOPE_GLOBAL, false, std::vector{"global_l_soft", "l_soft"}), + std::make_tuple(JRS_SCOPE_MASTER, true, std::vector{"master_l_hard"}), + std::make_tuple(JRS_SCOPE_SLAVE, true, std::vector{"slave_l_hard"}), + }; + for (const auto&[scope, hard, attr_names] : resource_table) { + const lList *resource_list = job_get_resource_list(old_job, scope, hard); + for (const auto &attr_name : attr_names) { + jsv_send_resource_list(jsv, answer_list, prefix, attr_name.c_str(), resource_list); + } } } - /* - * -m [b][e][a][s] or n (optional; only provided to JSV script if != 'n' - */ - { - u_long32 mail_options = lGetUlong(old_job, JB_mail_options); - - if (mail_options > 0) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s m ", prefix); - sge_mailopt_to_dstring(mail_options, &buffer); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + // -m [b][e][a][s] or n (optional; only provided to JSV script if != 'n' + if (u_long32 mail_options = lGetUlong(old_job, JB_mail_options); mail_options > 0) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s m ", prefix); + sge_mailopt_to_dstring(mail_options, &buffer); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* - * -M , ... - * optional - */ - { - const lList *mail_list = lGetList(old_job, JB_mail_list); - const lListElem *mail; - bool first = true; - + // -M , ... (optional) + if (const lList *mail_list = lGetList(old_job, JB_mail_list); mail_list != nullptr) { sge_dstring_clear(&buffer); sge_dstring_sprintf(&buffer, "%s M", prefix); + const lListElem *mail; + bool first = true; for_each_ep(mail, mail_list) { const char *user = lGetString(mail, MR_user); - const char *host = lGetHost(mail, MR_host); - sge_dstring_append_char(&buffer, first ? ' ' : ','); sge_dstring_append(&buffer, user); - if (host != nullptr) { + if (const char *host = lGetHost(mail, MR_host); host != nullptr) { sge_dstring_sprintf_append(&buffer, "@%s", host); } first = false; @@ -1800,127 +1539,62 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* - * -masterq wc_queue_list (optional) - */ - { - const lList *master_hard_queue_list = job_get_master_hard_queue_list(old_job); - - if (master_hard_queue_list != nullptr) { - const lListElem *queue; - bool first = true; - - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s masterq", prefix); - for_each_ep(queue, master_hard_queue_list) { - const char *queue_pattern = lGetString(queue, QR_name); - - sge_dstring_append_char(&buffer, first ? ' ' : ','); - sge_dstring_sprintf_append(&buffer, "%s", queue_pattern); - first = false; - } - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } - } - - /* - * -notify y|n - * PARAM notify y|n (optional; only available when -notify y was specified) - */ - if (lGetBool(old_job, JB_notify)) { + // -notify y|n (optional; only available when -notify y was specified) + if (const bool notify = lGetBool(old_job, JB_notify); notify) { sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s notify %c", prefix, lGetBool(old_job, JB_notify) ? 'y' : 'n'); + sge_dstring_sprintf(&buffer, "%s notify %c", prefix, notify ? 'y' : 'n'); jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* -now y|n (not available in JSV) */ + // -now y|n (not available in JSV) - /* - * -N - * optional; only abaiable if specified during job submission - */ - { - const char *name = lGetString(old_job, JB_job_name); - - if (name != nullptr) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s N %s", prefix, name); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + // -N + // optional; only available if specified during job submission + if (const char *name = lGetString(old_job, JB_job_name); name != nullptr) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s N %s", prefix, name); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* -noshell y | n (not handled in JSV) */ - /* -nostdin (not handled in JSV) */ - - /* - * -o (optional) - * TODO: EB: summarize with -S -e -i - */ - { - const lList *shell_list = lGetList(old_job, JB_stdout_path_list); - - if (shell_list != nullptr) { - const lListElem *shell; - - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s o ", prefix); - for_each_ep(shell, shell_list) { - const char *hostname = lGetHost(shell, PN_host); - const char *path = lGetString(shell, PN_path); - - if (hostname != nullptr) { - sge_dstring_append(&buffer, hostname); - sge_dstring_append_char(&buffer, ':'); - sge_dstring_append(&buffer, path); - } else { - sge_dstring_append(&buffer, path); - } - } - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); + // -noshell y | n (not handled in JSV) + // -nostdin (not handled in JSV) + + // -o (optional) + // -e (optional) + // -i (optional) + // -S (optional) + // path_list := [hostname':']path,... + std::vector> path_list_types = { + {JB_stdout_path_list, "o"}, + {JB_stderr_path_list, "e"}, + {JB_stdin_path_list, "i"}, + {JB_shell_list, "S"} + }; + for (const auto&[fst, snd] : path_list_types) { + if (const lList *path_list = lGetList(old_job, fst); path_list != nullptr) { + jsv_send_path_list(jsv, answer_list, prefix, snd.c_str(), path_list); } } - /* -ot override_tickets - * (handled in JSV) - */ - - /* - * -P project_name (optional; only available if specified during submission) - */ - { - const char *project = lGetString(old_job, JB_project); - - if (project != nullptr) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s P %s", prefix, project); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + // -P project_name (optional; only available if specified during submission) + if (const char *project = lGetString(old_job, JB_project); project != nullptr) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s P %s", prefix, project); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - - /* -p priority - * optional; only provided if specified during submission and != 0) - */ - { - int priority = (int) lGetUlong(old_job, JB_priority) - 1024; - if (priority != 0) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s p %d", prefix, priority); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + // -p priority (optional; only provided if specified during submission and != 0) + if (int priority = static_cast(lGetUlong(old_job, JB_priority)) - 1024; priority != 0) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s p %d", prefix, priority); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } - /* -tc task concurency - * optional; only provided if specified during submission - */ - { - int max_tasks = (int) lGetUlong(old_job, JB_ja_task_concurrency); - - if (max_tasks != 0) { - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s tc %d", prefix, max_tasks); - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } + // -tc task concurrency (optional; only provided if specified during submission + if (int max_tasks = static_cast(lGetUlong(old_job, JB_ja_task_concurrency)); max_tasks != 0) { + sge_dstring_clear(&buffer); + sge_dstring_sprintf(&buffer, "%s tc %d", prefix, max_tasks); + jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } /* @@ -1937,9 +1611,9 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr { const lList *list = lGetList(old_job, JB_binding); const lListElem *binding = ((list != nullptr) ? lFirst(list) : nullptr); - const char *strategy = ((binding != nullptr) ? lGetString(binding, BN_strategy) : nullptr); - if (strategy != nullptr && strcmp(strategy, "no_job_binding") != 0) { + if (const char *strategy = ((binding != nullptr) ? lGetString(binding, BN_strategy) : nullptr); + strategy != nullptr && strcmp(strategy, "no_job_binding") != 0) { const char *strategy_without_automatic = strategy; /* binding_strategy */ @@ -1956,7 +1630,7 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr /* binding_type */ sge_dstring_clear(&buffer); sge_dstring_sprintf(&buffer, "%s binding_type ", prefix); - binding_type_to_string((binding_type_t)lGetUlong(binding, BN_type), &buffer); + binding_type_to_string(static_cast(lGetUlong(binding, BN_type)), &buffer); jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); if (strcmp("linear", strategy_without_automatic) == 0 || strcmp("striding", strategy_without_automatic) == 0) { @@ -1985,7 +1659,7 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr } /* - * Only within striding strategy stepsize parameter is allowed + * Only within striding strategy step size parameter is allowed */ if (strcmp("striding", strategy_without_automatic) == 0) { /* binding_step */ @@ -2067,54 +1741,43 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr /* -pty y|n (not available in JSV) */ - /* - * -q wc_queue_list (optional; see man page sge_types(1) for wc_queue_list specification) - * - * -soft -q => - * PARAM q_soft (see man page sge_types(1) for wc_queue_list specification) - * - * -hard -q => - * PARAM q_hard - * - * TODO: EB: CLEANUP: make a function for the code blocks of -soft -q, -hard -q and -masterq - */ + // -q wc_queue_list (optional; see man page sge_types(1) for wc_queue_list specification) + // + // -scope GLOBAL -hard -q => + // PARAM global_q_hard + // PARAM q_hard (for compatibility) + // + // -scope GLOBAL -soft -q => + // PARAM global_q_soft + // PARAM q_soft (for compatibility) + // + // -scope MASTER (-hard) -q => + // PARAM master_q_hard + // PARAM masterq (for compatibility) + // + // -scope SLAVE (-hard) -q => + // PARAM slave_q_hard { - const lList *hard_queue_list = job_get_hard_queue_list(old_job); - - if (hard_queue_list != nullptr) { - const lListElem *queue; - bool first = true; - - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s q_hard", prefix); - for_each_ep(queue, hard_queue_list) { - const char *queue_pattern = lGetString(queue, QR_name); - - sge_dstring_append_char(&buffer, first ? ' ' : ','); - sge_dstring_sprintf_append(&buffer, "%s", queue_pattern); - first = false; - } - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); + const lList *hard_queue_list = job_get_queue_list(old_job, JRS_SCOPE_GLOBAL, true); + for (std::vector global_hard_attr_names = {"global_q_hard", "q_hard"}; + const auto &attr_name : global_hard_attr_names) { + jsv_send_queue_list(jsv, answer_list, prefix, attr_name.c_str(), hard_queue_list); } - } - { - const lList *soft_queue_list = job_get_soft_queue_list(old_job); - if (soft_queue_list != nullptr) { - const lListElem *queue; - bool first = true; - - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s q_soft", prefix); - for_each_ep(queue, soft_queue_list) { - const char *queue_pattern = lGetString(queue, QR_name); + const lList *soft_queue_list = job_get_queue_list(old_job, JRS_SCOPE_GLOBAL, false); + for (std::vector global_soft_attr_names = {"global_q_soft", "q_soft"}; + const auto &attr_name : global_soft_attr_names) { + jsv_send_queue_list(jsv, answer_list, prefix, attr_name.c_str(), soft_queue_list); + } - sge_dstring_append_char(&buffer, first ? ' ' : ','); - sge_dstring_sprintf_append(&buffer, "%s", queue_pattern); - first = false; - } - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); + const lList *master_hard_queue_list = job_get_queue_list(old_job, JRS_SCOPE_MASTER, true); + for (std::vector master_hard_attr_names = {"master_q_hard", "masterq"}; + const auto &attr_name : master_hard_attr_names) { + jsv_send_queue_list(jsv, answer_list, prefix, attr_name.c_str(), master_hard_queue_list); } + + const lList *slave_hard_queue_list = job_get_queue_list(old_job, JRS_SCOPE_SLAVE, true); + jsv_send_queue_list(jsv, answer_list, prefix, "slave_q_hard", slave_hard_queue_list); } /* @@ -2122,9 +1785,7 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr * optional; only available if specified during submission and value is y */ { - bool reserve = lGetBool(old_job, JB_reserve) ? true : false; - - if (reserve) { + if (bool reserve = lGetBool(old_job, JB_reserve) ? true : false; reserve) { sge_dstring_clear(&buffer); sge_dstring_sprintf(&buffer, "%s R %c", prefix, reserve ? 'y' : 'n'); jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); @@ -2136,9 +1797,7 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr * optional; only available if specified during submission and value is y */ { - u_long32 restart = lGetUlong(old_job, JB_restart); - - if (restart == 1) { + if (u_long32 restart = lGetUlong(old_job, JB_restart); restart == 1) { sge_dstring_clear(&buffer); sge_dstring_sprintf(&buffer, "%s r %c", prefix, (restart == 1) ? 'y' : 'n'); jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); @@ -2152,9 +1811,7 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr * optional; only available if -shell n was specified */ { - bool no_shell = job_is_no_shell(old_job); - - if (no_shell) { + if (bool no_shell = job_is_no_shell(old_job); no_shell) { sge_dstring_clear(&buffer); sge_dstring_sprintf(&buffer, "%s shell %c", prefix, !no_shell ? 'y' : 'n'); jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); @@ -2165,39 +1822,7 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr /* -sync y|n (not available in JSV) */ - /* - * -S shell_path_list (optional) - * PARAM S [hostname:]path,... - */ - { - const lList *shell_list = lGetList(old_job, JB_shell_list); - - if (shell_list != nullptr) { - const lListElem *shell; - bool first = true; - - sge_dstring_clear(&buffer); - sge_dstring_sprintf(&buffer, "%s S", prefix); - for_each_ep(shell, shell_list) { - const char *hostname = lGetHost(shell, PN_host); - const char *path = lGetString(shell, PN_path); - - - sge_dstring_append_char(&buffer, first ? ' ' : ','); - if (hostname != nullptr) { - sge_dstring_append(&buffer, hostname); - sge_dstring_append_char(&buffer, ':'); - sge_dstring_append(&buffer, path); - } else { - sge_dstring_append(&buffer, path); - } - first = false; - } - jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); - } - } - - /* + /* * -t min[-max[:step]] (optional; only available if specified during submission * and if values differ from "1-1:1") * PARAM t_min @@ -2205,12 +1830,8 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr * PARAM t_step */ { - const lList *ja_structure_list = lGetList(old_job, JB_ja_structure); - const lListElem *ja_structure = lFirst(ja_structure_list); - - if (ja_structure != nullptr) { + if (const lListElem *ja_structure = lFirst(lGetList(old_job, JB_ja_structure)); ja_structure != nullptr) { u_long32 min, max, step; - range_get_all_ids(ja_structure, &min, &max, &step); /* @@ -2242,9 +1863,7 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr * optional; only sent to JSV if != 'n') */ { - u_long32 verify = lGetUlong(old_job, JB_verify_suitable_queues); - - if (verify > 0) { + if (u_long32 verify = lGetUlong(old_job, JB_verify_suitable_queues); verify > 0) { sge_dstring_clear(&buffer); sge_dstring_sprintf(&buffer, "%s w ", prefix); job_get_verify_attr(verify, &buffer); @@ -2262,8 +1881,6 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr */ { lList *env_list = nullptr; - const lListElem *env = nullptr; - const lListElem *display = nullptr; /* make a copy of the environment */ var_list_copy_env_vars_and_value(&env_list, lGetList(old_job, JB_env_list)); @@ -2277,21 +1894,20 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr * then we will send the DISPLAY value as if it originally came * from -display switch. */ - display = lGetElemStr(env_list, VA_variable, "DISPLAY"); - if (display != nullptr) { + if (const lListElem *display = lGetElemStr(env_list, VA_variable, "DISPLAY"); display != nullptr) { const char *value = lGetString(display, VA_value); - u_long32 progid = component_get_component_id(); - if (value != nullptr && - (strcmp(prognames[progid], "qsh") == 0 || strcmp(prognames[progid], "qrsh") == 0)) { + if (u_long32 prog_id = component_get_component_id(); + value != nullptr && (strcmp(prognames[prog_id], "qsh") == 0 || strcmp(prognames[prog_id], "qrsh") == 0)) { sge_dstring_clear(&buffer); sge_dstring_sprintf(&buffer, "PARAM display %s", value); jsv_send_command(jsv, answer_list, sge_dstring_get_string(&buffer)); } } - /* send the varaibles to the JSV but only if it was requested */ + /* send the variables to the JSV but only if it was requested */ if (lGetBool(jsv, JSV_send_env)) { + const lListElem *env = nullptr; for_each_ep(env, env_list) { const char *value = lGetString(env, VA_value); const char *name = lGetString(env, VA_variable); @@ -2339,53 +1955,47 @@ jsv_handle_started_command(lListElem *jsv, lList **answer_list, dstring *c, dstr } static bool -jsv_handle_log_command(lListElem *jsv, lList **answer_list, dstring *c, dstring *s, dstring *a) -{ - bool ret = true; - const char *command = sge_dstring_get_string(s); - const char *sub_command = sge_dstring_get_string(s); +jsv_handle_log_command(lListElem *jsv, lList **answer_list, const dstring *c, const dstring *s, const dstring *a) { + DENTER(TOP_LAYER); const char *args = sge_dstring_get_string(a); - DENTER(TOP_LAYER); if (args == nullptr) { - /* empty message will print a empty line (only newline) */ + /* empty message will print an empty line (only newline) */ args = ""; } if (strcmp(lGetString(jsv, JSV_context), JSV_CONTEXT_CLIENT) != 0) { - if (strcmp(sub_command, "INFO") == 0) { + if (const char *sub_command = sge_dstring_get_string(s); strcmp(sub_command, "INFO") == 0) { INFO("%s", args); } else if (strcmp(sub_command, "WARNING") == 0) { WARNING("%s", args); } else if (strcmp(sub_command, "ERROR") == 0) { ERROR("%s", args); } else { + const char *command = sge_dstring_get_string(s); WARNING(MSG_JSV_LOG_SS, command, sub_command); } } else { printf("%s\n", args); } - DRETURN(ret); + DRETURN(true); } static bool -jsv_handle_env_command(lListElem *jsv, lList **answer_list, dstring *c, dstring *s, dstring *a) +jsv_handle_env_command(lListElem *jsv, lList **answer_list, const dstring *c, const dstring *s, const dstring *a) { bool ret = true; dstring variable = DSTRING_INIT; dstring value = DSTRING_INIT; - const char *mod; - const char *var; - const char *val; bool skip_check = false; lList *local_answer_list = nullptr; - lListElem *new_job = (lListElem *)lGetRef(jsv, JSV_new_job); + auto *new_job = static_cast(lGetRef(jsv, JSV_new_job)); DENTER(TOP_LAYER); jsv_split_token(a, &variable, &value); - mod = sge_dstring_get_string(s); - var = sge_dstring_get_string(&variable); - val = sge_dstring_get_string(&value); + const char *mod = sge_dstring_get_string(s); + const char *var = sge_dstring_get_string(&variable); + const char *val = sge_dstring_get_string(&value); DPRINTF("got from JSV \"%s %s %s\"", mod, var, (val != nullptr) ? val : ""); @@ -2398,8 +2008,7 @@ jsv_handle_env_command(lListElem *jsv, lList **answer_list, dstring *c, dstring if (skip_check != true) { if (mod != nullptr && var != nullptr && - (((strcmp(mod, "MOD") == 0 || strcmp(mod, "ADD") == 0) && val != nullptr) || - (strcmp(mod, "DEL") == 0 && val == nullptr))) { + (((strcmp(mod, "MOD") == 0 || strcmp(mod, "ADD") == 0) && val != nullptr) || (strcmp(mod, "DEL") == 0 && val == nullptr))) { lList *env_list = lGetListRW(new_job, JB_env_list); lListElem *env_variable = nullptr; @@ -2416,19 +2025,13 @@ jsv_handle_env_command(lListElem *jsv, lList **answer_list, dstring *c, dstring lRemoveElem(env_list, &env_variable); } } else { - answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - "\"ENV %s %s %s\" is invalid\n", - (mod != nullptr) ? mod : "", - (var != nullptr) ? var : "", - (val != nullptr) ? val : ""); + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, "\"ENV %s %s %s\" is invalid\n", + (mod != nullptr) ? mod : "", (var != nullptr) ? var : "", (val != nullptr) ? val : ""); ret = false; } } else { - answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - "\"ENV %s %s %s\" is invalid\n", - (mod != nullptr) ? mod : "", - (var != nullptr) ? var : "", - (val != nullptr) ? val : ""); + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, "\"ENV %s %s %s\" is invalid\n", + (mod != nullptr) ? mod : "", (var != nullptr) ? var : "", (val != nullptr) ? val : ""); ret = false; } } @@ -2442,19 +2045,13 @@ jsv_handle_env_command(lListElem *jsv, lList **answer_list, dstring *c, dstring */ if (lGetBool(jsv, JSV_test) && !skip_check) { const char *result_string = lGetString(jsv, JSV_result); - u_long32 result_pos = lGetUlong(jsv, JSV_test_pos); - - if (strlen(result_string) > result_pos) { - char result_char = result_string[result_pos]; - bool result = (result_char == '1') ? true : false; - - if (result != ret) { - answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - "\"ENV %s %s %s\" was unexcpectedly %s\n", - (mod != nullptr) ? mod : "", - (var != nullptr) ? var : "", - (val != nullptr) ? val : "", - ret ? "accepted" : "rejected"); + + if (const u_long32 result_pos = lGetUlong(jsv, JSV_test_pos); + strlen(result_string) > result_pos) { + if (const bool result = (result_string[result_pos] == '1') ? true : false; + result != ret) { + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, "\"ENV %s %s %s\" was unexpectedly %s\n", + (mod != nullptr) ? mod : "", (var != nullptr) ? var : "", (val != nullptr) ? val : "", ret ? "accepted" : "rejected"); ret = false; } else { ret = true; @@ -2501,20 +2098,18 @@ jsv_handle_env_command(lListElem *jsv, lList **answer_list, dstring *c, dstring bool jsv_do_communication(lListElem *jsv, lList **answer_list) { + DENTER(TOP_LAYER); bool ret = true; - char input[10000]; - DENTER(TOP_LAYER); - if (ret) { - /* - * Try to read some error messages from stderr. There still has no command been send - * to JSV but the initialization code might also cause errors.... - */ - while (fscanf((FILE *)lGetRef(jsv, JSV_err), "%[^\n]\n", input) == 1) { - ERROR(MSG_JSV_LOGMSG_S, input); - answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, SGE_EVENT); - ret = false; - } + /* + * Try to read some error messages from stderr. There still has no command been send + * to JSV but the initialization code might also cause errors.... + */ + char input[10000]; + while (fscanf(static_cast(lGetRef(jsv, JSV_err)), "%[^\n]\n", input) == 1) { + ERROR(MSG_JSV_LOGMSG_S, input); + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, SGE_EVENT); + ret = false; } if (ret) { DPRINTF("JSV - START will be sent\n"); @@ -2559,7 +2154,7 @@ jsv_do_communication(lListElem *jsv, lList **answer_list) } if (ret) { DPRINTF("JSV process gets START command\n"); - while (fscanf((FILE *)lGetRef(jsv, JSV_err), "%[^\n]\n", input) == 1) { + while (fscanf(static_cast(lGetRef(jsv, JSV_err)), "%[^\n]\n", input) == 1) { ERROR(MSG_JSV_LOGMSG_S, input); } ret &= jsv_send_command(jsv, answer_list, "START"); @@ -2568,16 +2163,14 @@ jsv_do_communication(lListElem *jsv, lList **answer_list) do_retry = false; } else { DPRINTF("JSV - reject due to timeout in communication process\n"); - answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - "got no response from JSV script " SFQ, - lGetString(jsv, JSV_command)); + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, "got no response from JSV script " SFQ, lGetString(jsv, JSV_command)); lSetBool(jsv, JSV_restart, true); lSetBool(jsv, JSV_soft_shutdown, false); lSetBool(jsv, JSV_done, true); } } else { - FILE *err_stream = (FILE *)lGetRef(jsv, JSV_err); - FILE *out_stream = (FILE *)lGetRef(jsv, JSV_out); + const auto err_stream = static_cast(lGetRef(jsv, JSV_err)); + const auto out_stream = static_cast(lGetRef(jsv, JSV_out)); /* * read a line from the script or wait some time before you try again @@ -2598,22 +2191,19 @@ jsv_do_communication(lListElem *jsv, lList **answer_list) {nullptr, nullptr} }; bool handled = false; - const char *c; int i = -1; DPRINTF("JSV << \"%s\"\n", input); jsv_split_commandline(input, &command, &sub_command, &args); - c = sge_dstring_get_string(&command); - + const char *command_str = sge_dstring_get_string(&command); + while(commands[++i].command != nullptr) { - if (strcmp(c, commands[i].command) == 0) { + if (strcmp(command_str, commands[i].command) == 0) { handled = true; ret &= commands[i].func(jsv, answer_list, &command, &sub_command, &args); - if (!ret || - lGetBool(jsv, JSV_restart) || - lGetBool(jsv, JSV_accept)) { + if (!ret || lGetBool(jsv, JSV_restart) || lGetBool(jsv, JSV_accept)) { lSetBool(jsv, JSV_done, true); } break; @@ -2621,15 +2211,14 @@ jsv_do_communication(lListElem *jsv, lList **answer_list) } if (!handled) { - answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - MSG_JSV_JCOMMAND_S, c); + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, MSG_JSV_JCOMMAND_S, command_str); lSetBool(jsv, JSV_accept, false); lSetBool(jsv, JSV_restart, true); lSetBool(jsv, JSV_done, true); } /* - * set start time for ne iteration + * set start time for new iteration */ start_time = sge_get_gmt64(); sge_dstring_free(&sub_command); @@ -2641,10 +2230,9 @@ jsv_do_communication(lListElem *jsv, lList **answer_list) } /* - * try to read a line from the error stream. If there is something then - * restart the script before next check, do not communicate with script - * anymore during shutdown. The last message in the strerr stream will be - * send as answer to the calling function. + * try to read a line from the error stream. If there is something then restart the + * script before next check, do not communicate with script anymore during shutdown. + * The last message in the stderr stream will be sent as answer to the calling function. */ while (fscanf(err_stream, "%[^\n]\n", input) == 1) { ERROR(MSG_JSV_LOGMSG_S, input); @@ -2652,8 +2240,7 @@ jsv_do_communication(lListElem *jsv, lList **answer_list) ret = false; } if (!ret && !lGetBool(jsv, JSV_done)) { - answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, - "JSV stderr is - %s", input); + answer_list_add_sprintf(answer_list, STATUS_DENIED, ANSWER_QUALITY_ERROR, "JSV stderr is - %s", input); lSetBool(jsv, JSV_restart, true); lSetBool(jsv, JSV_soft_shutdown, false); lSetBool(jsv, JSV_done, true); @@ -2664,16 +2251,22 @@ jsv_do_communication(lListElem *jsv, lList **answer_list) return ret; } +/** + * Converts a CULL attribute into a switch name as used in the JSV protocol (usually a qalter switch). + * + * @param cull_attr CULL attribute + * @param job A JB_Type object + * @return Pointer to a static string with the switch name or nullptr if the attribute is not supported. + */ static const char * -jsv_cull_attr2switch_name(int cull_attr, lListElem *job) -{ +jsv_cull_attr2switch_name(const int cull_attr, const lListElem *job) { + DENTER(TOP_LAYER); const char *ret = nullptr; - DENTER(TOP_LAYER); if (cull_attr == JB_execution_time) { ret = "a"; } else if (cull_attr == JB_context) { - ret = "ac"; /* although it might also be a ds or sc request we return ac here */ + ret = "ac"; // although it might also be a ds or sc request we return ac here } else if (cull_attr == JB_ar) { ret = "ar"; } else if (cull_attr == JB_account) { @@ -2705,7 +2298,7 @@ jsv_cull_attr2switch_name(int cull_attr, lListElem *job) } else if (cull_attr == JB_jobshare) { ret = "js"; } else if (cull_attr == JB_request_set_list) { - ret = "request_set"; + ret = nullptr; } else if (cull_attr == JB_mail_options) { ret = "m"; } else if (cull_attr == JB_notify) { @@ -2713,32 +2306,24 @@ jsv_cull_attr2switch_name(int cull_attr, lListElem *job) } else if (cull_attr == JB_mail_list) { ret = "M"; } else if (cull_attr == JB_job_name) { - /* - * This is a special case for JB_job_name parameter. - * A) null - * qalter ... => qalter with job id - * B) - * qalter -N => qalter with job id using -N option - * to change name - * C) :: - * qalter ... => qalter with job name instead - * of job id - * D) :: - * qalter -N => qalter with job name instead of - * job id using -N option to change name - */ + // This is a special case for JB_job_name parameter. + // A) null + // qalter ... => qalter with job id + // B) + // qalter -N => qalter with job id using -N option to change name + // C) :: + // qalter ... => qalter with job name instead of job id + // D) :: + // qalter -N => qalter with job name instead of + // job id using -N option to change name #define JOB_NAME_DEL ':' - const char *job_name = lGetString(job, JB_job_name); - if (job_name != nullptr) { + if (const char *job_name = lGetString(job, JB_job_name); job_name != nullptr) { if (job_name[0] == JOB_NAME_DEL) { - const char *help_str = strchr(&(job_name[1]), JOB_NAME_DEL); - if (help_str != nullptr && help_str[1] != '\0') { - /* This is case D) */ - ret = "N"; + if (const char *help_str = strchr(&(job_name[1]), JOB_NAME_DEL); help_str != nullptr && help_str[1] != '\0') { + ret = "N"; // case D } } else { - /* This is case B) */ - ret = "N"; + ret = "N"; // case B } } } else if (cull_attr == JB_stdout_path_list) { @@ -2769,65 +2354,85 @@ jsv_cull_attr2switch_name(int cull_attr, lListElem *job) DRETURN(ret); } +/** + * Check if a modification request is rejected by the JSV script. + * + * @param answer_list The answer list to append the error message to. + * @param job The job to check. + * @return true if the modification request is rejected, false otherwise. + */ bool -jsv_is_modify_rejected(lList **answer_list, lListElem *job) -{ +jsv_is_modify_rejected(lList **answer_list, const lListElem *job) { + DENTER(TOP_LAYER); bool ret = false; - DENTER(TOP_LAYER); if (job != nullptr) { const char *jsv_allowed_mod = mconf_get_jsv_allowed_mod(); const char *jsv_url = mconf_get_jsv_url(); if (jsv_url && strcasecmp(jsv_url, "none") != 0) { - /* - * Check now if there are allowed modifications. - */ + // Check now if there are allowed modifications. if (jsv_allowed_mod && strcmp(jsv_allowed_mod, "none") != 0) { - const lDescr *descr = lGetElemDescr(job); - const lDescr *pointer = nullptr; lList *allowed_switches = nullptr; lList *got_switches = nullptr; - const lListElem *allowed = nullptr; - /* - * Transform the cull fields into a list of corresponding - * qalter switch names. - */ + // Transform CULL fields into a list of corresponding qalter switch names + // or switch combinations as accepted in JSV scripts. There are some exceptions that are handled + // in the following code. + const lDescr *descr = lGetElemDescr(job); str_list_parse_from_string(&allowed_switches, jsv_allowed_mod, ","); - for (pointer = descr; pointer->nm != NoName; pointer++) { - const char *swch = jsv_cull_attr2switch_name(pointer->nm, job); - - if (swch != nullptr) { - if (strcmp(swch, "request_set") == 0) { - lAddElemStr(&got_switches, ST_name, "l_hard", ST_Type); - lAddElemStr(&got_switches, ST_name, "l_soft", ST_Type); - lAddElemStr(&got_switches, ST_name, "q_hard", ST_Type); - lAddElemStr(&got_switches, ST_name, "q_soft", ST_Type); - lAddElemStr(&got_switches, ST_name, "masterq", ST_Type); - } else { - lAddElemStr(&got_switches, ST_name, swch, ST_Type); - - } + for (const lDescr *pointer = descr; pointer->nm != NoName; pointer++) { + if (const char *switch_name = jsv_cull_attr2switch_name(pointer->nm, job); switch_name != nullptr) { + lAddElemStr(&got_switches, ST_name, switch_name, ST_Type); } } - /* - * Even if not specified on commandline. The information of the - * -w switch is always passed to qalter. We must allow it even if it - * was not specified. - */ - allowed = lGetElemStr(allowed_switches, ST_name, "w"); + // resource list specific switches + const lList *list = job_get_resource_list(job, JRS_SCOPE_GLOBAL, true); + if (list != nullptr) { + lAddElemStr(&got_switches, ST_name, "global_l_hard", ST_Type); + } + list = job_get_resource_list(job, JRS_SCOPE_GLOBAL, false); + if (list != nullptr) { + lAddElemStr(&got_switches, ST_name, "global_l_soft", ST_Type); + } + list = job_get_resource_list(job, JRS_SCOPE_MASTER, true); + if (list != nullptr) { + lAddElemStr(&got_switches, ST_name, "master_l_hard", ST_Type); + } + list = job_get_resource_list(job, JRS_SCOPE_SLAVE, true); + if (list != nullptr) { + lAddElemStr(&got_switches, ST_name, "slave_l_hard", ST_Type); + } + + // queue list specific switches + list = job_get_queue_list(job, JRS_SCOPE_GLOBAL, true); + if (list != nullptr) { + lAddElemStr(&got_switches, ST_name, "global_q_hard", ST_Type); + } + list = job_get_queue_list(job, JRS_SCOPE_GLOBAL, false); + if (list != nullptr) { + lAddElemStr(&got_switches, ST_name, "global_q_soft", ST_Type); + } + list = job_get_queue_list(job, JRS_SCOPE_MASTER, true); + if (list != nullptr) { + lAddElemStr(&got_switches, ST_name, "master_q_hard", ST_Type); + } + list = job_get_queue_list(job, JRS_SCOPE_SLAVE, true); + if (list != nullptr) { + lAddElemStr(&got_switches, ST_name, "slave_q_hard", ST_Type); + } + + // Even if not specified on commandline. The information of the -w switch is always passed + // to qalter. We must allow it even if it was not specified. + const lListElem *allowed = lGetElemStr(allowed_switches, ST_name, "w"); if (allowed == nullptr) { lAddElemStr(&allowed_switches, ST_name, "w", ST_Type); } - /* - * Allow -t switch automatically if -h is used. The corresponding - * information of -t in the CULL data structure is used to - * send the information of -h. - */ + // Allow -t switch automatically if -h is used. The corresponding information of -t in the CULL data structure + // is used to send the information of -h. allowed = lGetElemStr(allowed_switches, ST_name, "h"); if (allowed != nullptr) { allowed = lGetElemStr(allowed_switches, ST_name, "t"); @@ -2837,10 +2442,7 @@ jsv_is_modify_rejected(lList **answer_list, lListElem *job) } } - /* - * Remove the allowed switches from the list of switches which were - * applied to the job we got. - */ + // Remove the allowed switches from the list of switches which were applied to the job we got. for_each_ep(allowed, allowed_switches) { const char *name = lGetString(allowed, ST_name); const void *iterator = nullptr; @@ -2854,9 +2456,7 @@ jsv_is_modify_rejected(lList **answer_list, lListElem *job) } } - /* - * If there are no remaining switches then the request will not be rejected. - */ + // If there are no remaining switches then the request will not be rejected. if (lGetNumberOfElem(got_switches) == 0) { ret = false; } else { @@ -2885,9 +2485,7 @@ jsv_is_modify_rejected(lList **answer_list, lListElem *job) lFreeList(&got_switches); } } else { - /* - * JSV is active but no modification allowed - */ + // JSV is active but no modification allowed ERROR(SFNMAX, MSG_JSV_ALLOWED); answer_list_add(answer_list, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR); ret = true; diff --git a/source/libs/sgeobj/sge_jsv_script.h b/source/libs/sgeobj/sge_jsv_script.h index c1fd5afd6..6b207e30d 100644 --- a/source/libs/sgeobj/sge_jsv_script.h +++ b/source/libs/sgeobj/sge_jsv_script.h @@ -39,4 +39,4 @@ bool jsv_do_communication(lListElem *jsv, lList **answer_list); bool -jsv_is_modify_rejected(lList **answer_list, lListElem *job); +jsv_is_modify_rejected(lList **answer_list, const lListElem *job);