示例#1
0
static void pctl_util_init_phandle_null() {
    int lv_status;

    gv_pctl_phandle_null_inited = true;
    lv_status = XPROCESSHANDLE_NULLIT_(&gv_pctl_phandle_null);
    CHK_FEIGNORE(lv_status);
}
示例#2
0
//
// plugin - send msg to ms-ic
//
static void sb_pi_ic_send(MS_Mon_Node_Info_Entry_Type *pp_node,
                          MS_Mon_Process_Info_Type    *pp_proc,
                          Sqstate_Pi_Info_Type        *pp_info,
                          char                        *pp_title,
                          bool                         pv_title,
                          const char                  *pp_lib,
                          const char                  *pp_call,
                          char                        *pp_rsp,
                          int                          pv_rsplen,
                          int                         *pp_rsplen) {
    char             la_ctrl[200];
    char            *lp_data;
    char            *lp_p;
    char             la_rsp[MAX_RSP];
    short           *lp_ctrl;
    short           *lp_results;
    char            *lp_rsp;
    int              lv_clen;
    int              lv_disable;
    int              lv_dlen;
    int              lv_fserr;
    int              lv_inx;
    int              lv_len;
    int              lv_msgid;
    int              lv_oid;
    bool             lv_open;
    MS_Result_Type   lv_results;
    int              lv_rsplen;

    pp_node = pp_node; // touch
    if (pp_rsplen != NULL)
        *pp_rsplen = 0;

    lv_open = (strcmp(pp_proc->process_name, gp_pname) != 0);
    gp_pname = pp_proc->process_name;

    if (strcmp(pp_call, "ic_unload") == 0)
        sprintf(la_ctrl, "unload" ":" ":" "all");
    else
        sprintf(la_ctrl, "call" ":" "%s" ":" "%s", pp_lib, pp_call);
    lv_clen = static_cast<int>(strlen(la_ctrl)) + 1;
    lv_dlen = 0;
    for (lv_inx = 0; lv_inx < pp_info->ic_argc; lv_inx++)
        lv_dlen += static_cast<int>(strlen(pp_info->ic_argv[lv_inx])) + 1;
    if (lv_dlen > 0) {
        lp_data = new char[lv_dlen];
        lp_p = lp_data;
        for (lv_inx = 0; lv_inx < pp_info->ic_argc; lv_inx++) {
            lv_len = sprintf(lp_p, "%s", pp_info->ic_argv[lv_inx]);
            lp_p += lv_len + 1;
        }
    } else
        lp_data = NULL;
    if (lv_open) {
        if (gv_verbosev)
            sb_pi_verb_printf("opening %s...\n", gp_pname);
        if (gv_opened) {
            gv_opened = false;
            lv_fserr = msg_mon_close_process(&gv_phandle);
            CHK_FEIGNORE(lv_fserr);
        }
        lv_disable = msg_test_assert_disable();
        if (pp_info->self)
            lv_fserr = msg_mon_open_process_self_ic(&gv_phandle, &lv_oid);
        else
            lv_fserr = msg_mon_open_process_ic(gp_pname, &gv_phandle, &lv_oid);
        msg_test_assert_enable(lv_disable);
        sb_pi_verb_ok(lv_fserr, "open");
    } else
        lv_fserr = XZFIL_ERR_OK;
    if (lv_fserr != XZFIL_ERR_OK) {
        sb_pi_verb_printf("ERROR: could not open %s, fserr=%d\n",
                          gp_pname,
                          lv_fserr);
    } else {
        lp_ctrl = reinterpret_cast<short *>(la_ctrl);
        gv_opened = true;
        if (gv_verbose)
            sb_pi_verb_printf("linking %s, ctrl=%s...\n", gp_pname, la_ctrl);
        lv_disable = msg_test_assert_disable();
        if (pp_rsp == NULL) {
            lp_rsp = la_rsp;
            lv_rsplen = MAX_RSP;
        } else {
            lp_rsp = pp_rsp;
            lv_rsplen = pv_rsplen;
        }
        lv_fserr = BMSG_LINK_(&gv_phandle,                 // phandle
                              &lv_msgid,                   // msgid
                              lp_ctrl,                     // reqctrl
                              lv_clen,                     // reqctrlsize
                              NULL,                        // replyctrl
                              0,                           // replyctrlmax
                              lp_data,                     // reqdata
                              lv_dlen,                     // reqdatasize
                              lp_rsp,                      // replydata
                              lv_rsplen,                   // replydatamax
                              0,                           // linkertag
                              0,                           // pri
                              0,                           // xmitclass
                              BMSG_LINK_MSINTERCEPTOR);    // linkopts
        msg_test_assert_enable(lv_disable);
        sb_pi_verb_ok(lv_fserr, "link");
        if (lv_fserr != XZFIL_ERR_OK) {
            sb_pi_printf("ERROR: error in link to %s, fserr=%d\n",
                           gp_pname, lv_fserr);
        } else {
            if (gv_verbosev)
                sb_pi_verb_printf("breaking %s...\n", gp_pname);
            lp_results = reinterpret_cast<short *>(&lv_results);
            lv_disable = msg_test_assert_disable();
            lv_fserr = BMSG_BREAK_(lv_msgid, lp_results, &gv_phandle);
            msg_test_assert_enable(lv_disable);
            sb_pi_verb_ok(lv_fserr, "break");
            if (lv_fserr == XZFIL_ERR_OK) {
                if (pp_rsp == NULL)
                    sb_pi_ic_call_print_rsp(pp_title,
                                            pv_title,
                                            la_rsp,
                                            lv_results.rr_datasize);
                else if (pp_rsplen != NULL)
                    *pp_rsplen = lv_results.rr_datasize;
            } else {
                sb_pi_printf("ERROR: error in break to %s, fserr=%d\n",
                               gp_pname, lv_fserr);
            }
        }
    }
}
示例#3
0
SB_Export short XPROCESS_GETPAIRINFO_(SB_Phandle_Type *pp_phandle,
                                      char            *pp_pair,
                                      short            pv_maxlen,
                                      short           *pp_pair_length,
                                      SB_Phandle_Type *pp_primary_phandle,
                                      SB_Phandle_Type *pp_backup_phandle,
                                      int             *pp_search,
                                      SB_Phandle_Type *pp_ancestor_phandle,
                                      char            *pp_node,
                                      short            pv_node_len,
                                      short            pv_options,
                                      char            *pp_ancestor_desc,
                                      short            pv_ancestor_desc_maxlen,
                                      short           *pp_ancestor_desc_len,
                                      short           *pp_error_detail) {
    const char               *WHERE = "XPROCESS_GETPAIRINFO_";
    char                      la_name[MS_MON_MAX_PROCESS_NAME];
    char                     *lp_name;
    short                    *lp_phandles;
    int                       lv_fserr;
    short                     lv_param;
    SB_Phandle_Type           lv_phandle;
    bool                      lv_phandle_null;
    MS_Mon_Process_Info_Type  lv_pi;
    bool                      lv_pi_get;
    bool                      lv_pi_ok;
    short                     lv_ret;
    int                       lv_status;
    SB_API_CTR               (lv_zctr, XPROCESS_GETPAIRINFO_);

    lv_pi_get = true;
    lv_pi_ok = false;
    lp_phandles = reinterpret_cast<short *>(pp_phandle);
    if ((pp_phandle == NULL) || (lp_phandles[0] == -1))
        lv_phandle_null = true;
    else
        lv_phandle_null = false;
    if (gv_ms_trace_params) {
        char la_phandlet[MSG_UTIL_PHANDLE_LEN];
        msg_util_format_phandle(la_phandlet, pp_phandle);
        trace_where_printf(WHERE, "ENTER phandle=%s, pair=%p, maxlen=%d, pair-length=%p, p-phandle=%p, b-phandle=%p\n",
                           la_phandlet,
                           pfp(pp_pair),
                           pv_maxlen,
                           pfp(pp_pair_length),
                           pfp(pp_primary_phandle),
                           pfp(pp_backup_phandle));
        trace_where_printf(WHERE, "search=%p(%d), a-phandle=%p, node=%p, nodelen=%d, options=%d, a-desc=%p, a-desc-maxlen=%d, a-desc-len=%p, err-detail=%p\n",
                           pfp(pp_search),
                           (pp_search != NULL) ? *pp_search : -1,
                           pfp(pp_ancestor_phandle),
                           pfp(pp_node),
                           pv_node_len,
                           pv_options,
                           pfp(pp_ancestor_desc),
                           pv_ancestor_desc_maxlen,
                           pfp(pp_ancestor_desc_len),
                           pfp(pp_error_detail));
    }
    if (!gv_ms_calls_ok) {
        lv_ret = XPROC_INVSTATE;
        return ms_err_rtn_msg(WHERE, "msg_init() not called or shutdown",
                              lv_ret);
    }
    lv_ret = XPROC_OK;
    lv_fserr = XZFIL_ERR_OK;
    if (pp_error_detail != NULL)
        *pp_error_detail = 0;

    // check 'legacy' parameters and reject
    if ((pp_search != NULL) && (*pp_search != -1)) {
        lv_ret = XPROC_PRM_UNSUP;
        lv_param = PGPI_PARAM_SEARCH;
        if (pp_error_detail != NULL)
            *pp_error_detail = lv_param;
        return ms_err_rtn_msg(WHERE, "search (non -1) parameter unsupported", lv_ret);
    }
    if (pp_ancestor_phandle != NULL) {
        lv_ret = XPROC_PRM_UNSUP;
        lv_param = PGPI_PARAM_ANCESTOR_PHANDLE;
        if (pp_error_detail != NULL)
            *pp_error_detail = lv_param;
        return ms_err_rtn_msg(WHERE, "ancestor-phandle parameter unsupported", lv_ret);
    }
    if ((pp_node != NULL) && pv_node_len) {
        lv_ret = XPROC_PRM_UNSUP;
        lv_param = PGPI_PARAM_NODE;
        if (pp_error_detail != NULL)
            *pp_error_detail = lv_param;
        return ms_err_rtn_msg(WHERE, "node/len parameter unsupported", lv_ret);
    }
    if (pv_options) {
        lv_ret = XPROC_PRM_UNSUP;
        lv_param = PGPI_PARAM_OPTIONS;
        if (pp_error_detail != NULL)
            *pp_error_detail = lv_param;
        return ms_err_rtn_msg(WHERE, "options (non-zero) parameter unsupported", lv_ret);
    }
    if ((pp_ancestor_desc != NULL) && pv_ancestor_desc_maxlen) {
        lv_ret = XPROC_PRM_UNSUP;
        lv_param = PGPI_PARAM_ANCESTOR_DESC;
        if (pp_error_detail != NULL)
            *pp_error_detail = lv_param;
        return ms_err_rtn_msg(WHERE, "ancestor-desc/maxlen parameter unsupported", lv_ret);
    }

    if (lv_phandle_null) {
        // null phandle, check pair param
        if (pp_pair_length == NULL) { // in
            // use pair name to create phandle
            if (pp_pair == NULL) {
                lv_ret = XPROC_BNDS;
                lv_param = PGPI_PARAM_PAIR;
                if (pp_error_detail != NULL)
                    *pp_error_detail = lv_param;
                return ms_err_rtn_msg(WHERE, "invalid pair", lv_ret);
            }
            if (gv_ms_trace_params)
                trace_where_printf(WHERE, "pair=%s\n", pp_pair);
            lp_name = la_name;
            memcpy(la_name, pp_pair, sbmin(pv_maxlen, static_cast<int>(sizeof(la_name))));
            if (pv_maxlen < static_cast<int>(sizeof(la_name)))
                la_name[pv_maxlen] = '\0';
            else
                la_name[MS_MON_MAX_PROCESS_NAME-1] = '\0';
            lv_pi_get = false;
            lv_fserr = msg_mon_get_process_info_detail(la_name, &lv_pi);
            if (lv_fserr == XZFIL_ERR_OK) {
                ms_util_fill_phandle_name(&lv_phandle,
                                          la_name,
                                          lv_pi.nid,
                                          lv_pi.pid
#ifdef SQ_PHANDLE_VERIFIER
                                         ,lv_pi.verifier
#endif
                                         );
                lv_pi_ok = true;
            } else if (lv_fserr == XZFIL_ERR_NOTFOUND)
                lv_ret = XPROC_NONEXTANT;
            else
                lv_ret = XPROC_NODEDOWN;
        } else { // out
            // use our phandle and return pair
            lv_fserr = XPROCESSHANDLE_GETMINE_(&lv_phandle);
            lp_name = ms_od_map_phandle_to_name(&lv_phandle);
            if ((pp_pair != NULL) && (lv_fserr == XZFIL_ERR_OK)) {
                *pp_pair_length = static_cast<short>(strlen(lp_name));
                memcpy(pp_pair, lp_name, *pp_pair_length);
                if (gv_ms_trace_params)
                    trace_where_printf(WHERE, "pair=%s\n", lp_name);
            }
            if (lv_fserr != XZFIL_ERR_OK)
                lv_ret = XPROC_INVSTATE;
        }
    } else {
        lp_name = ms_od_map_phandle_to_name(pp_phandle);
        lv_pi_get = false;
        lv_fserr = msg_mon_get_process_info_detail(lp_name, &lv_pi);
        if (lv_fserr == XZFIL_ERR_OK) {
            lv_pi_ok = true;
            ms_util_fill_phandle_name(&lv_phandle,
                                      lp_name,
                                      lv_pi.nid,
                                      lv_pi.pid
#ifdef SQ_PHANDLE_VERIFIER
                                     ,lv_pi.verifier
#endif
                                     );
            if (pp_pair_length != NULL) { // out
                *pp_pair_length = static_cast<short>(strlen(lp_name));
                memcpy(pp_pair, lp_name, *pp_pair_length);
                if (gv_ms_trace_params)
                    trace_where_printf(WHERE, "pair=%s\n", lp_name);
            }
        } else if (lv_fserr == XZFIL_ERR_NOTFOUND)
            lv_ret = XPROC_NONEXTANT;
        else
            lv_ret = XPROC_NODEDOWN;
    }

    // at this point, name pair should be setup
    if (lv_fserr == XZFIL_ERR_OK) {
        if (lv_pi_get)
            lv_fserr = msg_mon_get_process_info_detail(lp_name, &lv_pi);
        if (lv_fserr == XZFIL_ERR_OK) {
            lv_pi_ok = true;
            if (pp_primary_phandle != NULL) {
                ms_util_fill_phandle_name(pp_primary_phandle,
                                          lp_name,
                                          !lv_pi.backup ? lv_pi.nid : lv_pi.parent_nid,
                                          !lv_pi.backup ? lv_pi.pid : lv_pi.parent_pid
#ifdef SQ_PHANDLE_VERIFIER
                                         ,!lv_pi.backup ? lv_pi.verifier : lv_pi.parent_verifier
#endif
                                         );
                if (gv_ms_trace_params) {
                    char la_phandlet[MSG_UTIL_PHANDLE_LEN];
                    msg_util_format_phandle(la_phandlet, pp_primary_phandle);
                    trace_where_printf(WHERE, "p-phandle=%s\n", la_phandlet);
                }
            }
            if (pp_backup_phandle != NULL) {
                if (strcmp(lv_pi.parent_name, lv_pi.process_name) == 0)
                    ms_util_fill_phandle_name(pp_backup_phandle,
                                              lp_name,
                                              !lv_pi.backup ? lv_pi.parent_nid : lv_pi.nid,
                                              !lv_pi.backup ? lv_pi.parent_pid : lv_pi.pid
#ifdef SQ_PHANDLE_VERIFIER
                                             ,!lv_pi.backup ? lv_pi.parent_verifier : lv_pi.verifier
#endif
                                             );
                else {
                    lv_status = XPROCESSHANDLE_NULLIT_(pp_backup_phandle);
                    CHK_FEIGNORE(lv_status);
                }
                if (gv_ms_trace_params) {
                    char la_phandlet[MSG_UTIL_PHANDLE_LEN];
                    msg_util_format_phandle(la_phandlet, pp_backup_phandle);
                    trace_where_printf(WHERE, "b-phandle=%s\n", la_phandlet);
                }
            }
        } else if (lv_fserr == XZFIL_ERR_NOTFOUND)
            lv_ret = XPROC_NONEXTANT;
        else
            lv_ret = XPROC_NODEDOWN;
    }

    if (lv_pi_ok) {
        if (strcmp(lv_pi.parent_name, lv_pi.process_name) == 0) {
            // process-pair
            if (!lv_pi.backup) {
                if ((lv_pi.nid == gv_ms_su_nid) &&
                    (lv_pi.pid == gv_ms_su_pid))
                    lv_ret = XPROC_PRIMARY;
                else if ((lv_pi.parent_nid == gv_ms_su_nid) &&
                         (lv_pi.parent_pid == gv_ms_su_pid))
                    lv_ret = XPROC_BACKUP;
                else
                    lv_ret = XPROC_OK; // not the calling process
            } else {
                if ((lv_pi.nid == gv_ms_su_nid) &&
                    (lv_pi.pid == gv_ms_su_pid))
                    lv_ret = XPROC_BACKUP;
                else if ((lv_pi.parent_nid == gv_ms_su_nid) &&
                         (lv_pi.parent_pid == gv_ms_su_pid))
                    lv_ret = XPROC_PRIMARY;
                else
                    lv_ret = XPROC_OK; // not the calling process
            }
        } else
            lv_ret = XPROC_SINGLE;
    }

    return ms_err_rtn_msg_noassert(WHERE, "EXIT", lv_ret);
}
示例#4
0
//
// plugin - send message to interceptor
//
SB_Export bool sqstatepi_send_ic_ok(const char                  *pp_module,
                                    const char                  *pp_call,
                                    MS_Mon_Node_Info_Entry_Type *pp_node,
                                    MS_Mon_Process_Info_Type    *pp_proc,
                                    Sqstate_Pi_Info_Type        *pp_info,
                                    const char                  *pp_lib,
                                    char                        *pp_rsp,
                                    int                          pv_rsp_len,
                                    int                         *pp_rsp_len) {
    char             la_ctrl[200];
    char            *lp_data;
    char            *lp_p;
    short           *lp_results;
    int              lv_clen;
    int              lv_dlen;
    int              lv_fserr;
    int              lv_inx;
    int              lv_len;
    int              lv_msgid;
    int              lv_oid;
    int              lv_ok;
    bool             lv_open;
    MS_Result_Type   lv_results;

    pp_node = pp_node; // touch
    lv_ok = false;
    *pp_rsp_len = 0;

    lv_open = (strcmp(pp_proc->process_name, gp_sqstatepi_pname) != 0);
    gp_sqstatepi_pname = pp_proc->process_name;

    sqstatepi_set_ctrl(la_ctrl, pp_info, pp_lib, pp_module, pp_call);
    lv_clen = static_cast<int>(strlen(la_ctrl)) + 1;
    lv_dlen = 0;
    for (lv_inx = 0; lv_inx < pp_info->ic_argc; lv_inx++)
        lv_dlen += static_cast<int>(strlen(pp_info->ic_argv[lv_inx])) + 1;
    if (lv_dlen > 0) {
        lp_data = new char[lv_dlen];
        lp_p = lp_data;
        for (lv_inx = 0; lv_inx < pp_info->ic_argc; lv_inx++) {
            lv_len = sprintf(lp_p, "%s", pp_info->ic_argv[lv_inx]);
            lp_p += lv_len + 1;
        }
    } else
        lp_data = NULL;
    if (lv_open) {
        if (pp_info->verbosev)
            sqstatepi_printf("opening %s...\n", gp_sqstatepi_pname);
        if (gv_sqstatepi_opened) {
            gv_sqstatepi_opened = false;
            lv_fserr = msg_mon_close_process(&gv_sqstatepi_phandle);
            CHK_FEIGNORE(lv_fserr);
        }
        if (pp_info->self)
            lv_fserr = msg_mon_open_process_self_ic(&gv_sqstatepi_phandle,
                                                    &lv_oid);
        else
            lv_fserr = msg_mon_open_process_ic(gp_sqstatepi_pname,
                                               &gv_sqstatepi_phandle,
                                               &lv_oid);
        sqstatepi_verbose_ok(pp_info, lv_fserr, "open");
    } else
        lv_fserr = XZFIL_ERR_OK;
    if (lv_fserr != XZFIL_ERR_OK) {
        sqstatepi_printf("ERROR: could not open %s, fserr=%d\n",
                         gp_sqstatepi_pname, lv_fserr);
    } else {
        gv_sqstatepi_opened = true;
        if (pp_info->verbose)
            sqstatepi_printf("linking %s, ctrl=%s...\n",
                             gp_sqstatepi_pname, la_ctrl);
        lv_fserr = BMSG_LINK_(&gv_sqstatepi_phandle,    // phandle
                              &lv_msgid,                // msgid
                              (short *) la_ctrl,        // reqctrl
                              lv_clen,                  // reqctrlsize
                              NULL,                     // replyctrl
                              0,                        // replyctrlmax
                              lp_data,                  // reqdata
                              lv_dlen,                  // reqdatasize
                              pp_rsp,                   // replydata
                              pv_rsp_len,               // replydatamax
                              0,                        // linkertag
                              0,                        // pri
                              0,                        // xmitclass
                              BMSG_LINK_MSINTERCEPTOR); // linkopts
        sqstatepi_verbose_ok(pp_info, lv_fserr, "link");
        if (lv_fserr != XZFIL_ERR_OK) {
            sqstatepi_printf("ERROR: error in link to %s, fserr=%d\n",
                             gp_sqstatepi_pname, lv_fserr);
        } else {
            if (pp_info->verbosev)
                sqstatepi_printf("breaking %s...\n", gp_sqstatepi_pname);
            lp_results = (short *) &lv_results;
            lv_fserr = BMSG_BREAK_(lv_msgid, lp_results, &gv_sqstatepi_phandle);
            sqstatepi_verbose_ok(pp_info, lv_fserr, "break");
            if (lv_fserr == XZFIL_ERR_OK) {
                *pp_rsp_len = lv_results.rr_datasize;
                lv_ok = true;
            } else {
                sqstatepi_printf("ERROR: error in break to %s, fserr=%d\n",
                                 gp_sqstatepi_pname, lv_fserr);
            }
        }
    }

    if (lp_data != NULL)
        delete [] lp_data;

    return lv_ok;
}