Exemple #1
0
/*
 *===========================================================================
 *                    ipcom_sysvar_tree_get
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 */
IP_STATIC Ipcom_sysvar_tree *
ipcom_sysvar_tree_get(int vr)
{
#if IPCOM_VR_MAX > 1
    if (vr == -1)
        vr = ipcom_proc_vr_get();

    if (vr >= IPCOM_VR_MAX)
        return IP_NULL;
#else
    vr = 0;
#endif

    if (ipcom_sysvar.tree[vr].sysvars)
        ipcom_sysvar.tree[vr].referenced++;
    else
    {
        ipcom_sysvar.tree[vr].sysvars
            = ipcom_hash_new((Ipcom_hash_obj_func) ipcom_sysvar_hash_obj,
                             (Ipcom_hash_key_func) ipcom_sysvar_hash_key,
                             (Ipcom_hash_cmp_func) ipcom_sysvar_hash_cmp);

        if (ipcom_sysvar.tree[vr].sysvars == IP_NULL)
            return IP_NULL;

        ipcom_sysvar.tree[vr].vr = vr;
        ipcom_sysvar.tree[vr].referenced = 1;
        ipcom_sysvar_tree_initialize(&ipcom_sysvar.tree[vr]);
    }

    return &ipcom_sysvar.tree[vr];
}
Exemple #2
0
/*
 *===========================================================================
 *                    ipcom_cmd_ipd
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 */
IP_PUBLIC int
ipcom_cmd_ipd(int argc, char **argv)
{
    Ipcom_getopt   opt;
    int            i, c, msgtype;
    Ip_err         err = IPCOM_SUCCESS;
#if IPCOM_VR_MAX > 1
    int            vr = ipcom_proc_vr_get();
    int            vr_new = vr;
#endif

    if (argc < 2)
    {
usage:
        ipcom_fprintf(ip_stderr,
                      "Interpeak daemon (IPD) command, version 1.2"IP_LF
                      "usage:  "IP_LF
                      "   ipd [-V <vr>] list"IP_LF
                      "   ipd [-V <vr>] start <service>"IP_LF
                      "   ipd [-V <vr>] kill <service>"IP_LF
                      "   ipd [-V <vr>] reconfigure <service>"IP_LF
                      "   ipd [-V <vr>] <#> <service>"IP_LF
                      IP_LF);
        return 0;
    }

    ipcom_getopt_clear_r(&opt);
    while ((c = ipcom_getopt_r(argc, argv, "V:", &opt)) != -1)
    {
        switch(c)
        {
        case 'V':
#if IPCOM_VR_MAX > 1
            vr_new = ipcom_atoi(opt.optarg);
#endif
            break;
        default:
            ipcom_printf("ipd: unknown option %c"IP_LF, (char)c);
            return -1;
        }
    }

    if (opt.optind >= argc)
    {
        ipcom_printf("ipd: missing <command> argument"IP_LF);
        goto usage;
    }


    if(ipcom_strcmp(argv[opt.optind], "list") == 0)
    {
#if IPCOM_VR_MAX > 1
        if (vr != vr_new)
            ipcom_proc_vr_set(vr_new);
#endif
        ipcom_printf("Services:"IP_LF);
        for (i = 0; ipcom_ipd_products[i].name != IP_NULL; i++)
        {
            if ((argc - (opt.optind + 1)) > 0)
            {
                int p;
                for (p = opt.optind + 1; p < argc; p++)
                {
                    if (ipcom_strcasecmp(ipcom_ipd_products[i].name, argv[p]) == 0)
                        goto print_service;
                }
                continue;
            }

print_service:
            if (IP_BIT_ISSET(ipcom_ipd_products[i].flags, IPCOM_IPD_FLAG_IPD_START))
            {
#ifdef IP_PORT_OSE5
                if (ipcom_ipd_products[i].start == IP_NULL
                    && ipcom_ipd_isinstalled_ose5(ipcom_ipd_products[i].name) != IPCOM_SUCCESS)
                    continue;
#endif
                err = ipcom_ipd_send(ipcom_ipd_products[i].name, IPCOM_IPD_MSGTYPE_PING);
                ipcom_printf("%-20s %-s"IP_LF,
                             ipcom_ipd_products[i].name,
                             err == IPCOM_SUCCESS ? "started" : "killed");
            }
            else if (ipcom_ipd_products[i].start)
                ipcom_printf("%-20s %-s"IP_LF,
                             ipcom_ipd_products[i].name, "started");

        }
        ipcom_printf(IP_LF);
#if IPCOM_VR_MAX > 1
        if (vr != vr_new)
            ipcom_proc_vr_set(vr);
#endif
        return 0;
    }

    if ((argc - opt.optind) < 2)
    {
        ipcom_printf("ipd: missing <service> argument"IP_LF);
        return -1;
    }

    for (i = 0; ipcom_cmd_ipd_messages[i].name; i++)
        if (ipcom_strcmp(argv[opt.optind], ipcom_cmd_ipd_messages[i].name) == 0)
        {
            msgtype = ipcom_cmd_ipd_messages[i].msgtype;
            goto sendmsg;
        }

    if (*argv[opt.optind] == '-' && ipcom_isdigit(argv[opt.optind][1]))
    {
        /* "UNIX" signal support (using negative numbers) */
        msgtype = -ipcom_atoi(argv[opt.optind] + 1);
        goto sendmsg;
    }

    if (ipcom_isdigit(argv[opt.optind][0]))
    {
        /* positive numbers */
        msgtype = ipcom_atoi(argv[1]);
        goto sendmsg;
    }

    /* unknown command. */
    ipcom_printf ("ipd: unknown command '%s'"IP_LF, argv[opt.optind]);
    return -1;

    /* send msg */
 sendmsg:
#if IPCOM_VR_MAX > 1
    if (vr != vr_new)
        ipcom_proc_vr_set(vr_new);
#endif


    if ((argc - opt.optind) < 3)
        err = ipcom_ipd_send(argv[opt.optind+1], msgtype);
    else
    {
        Ipcom_ipd_msg   *msg;
        int             sz  = ipcom_strlen(argv[opt.optind + 2]) + 1;

        msg = ipcom_calloc(1, sz + sizeof(*msg));
        if (msg != IP_NULL)
        {
            msg->msgtype = msgtype;
            ipcom_memcpy(msg + 1, argv[opt.optind + 2], sz);
            err = ipcom_ipd_sendmsg(argv[opt.optind+1], msg, sz + sizeof(*msg));
            ipcom_free(msg);
        }
    }

    if(err == IPCOM_SUCCESS)
        ipcom_printf("ipd: %s %s ok"IP_LF, argv[opt.optind], argv[opt.optind+1]);
    else
        ipcom_printf("ipd: %s %s failed: %s"IP_LF, argv[opt.optind], argv[opt.optind+1], ipcom_err_string(err));

#if IPCOM_VR_MAX > 1
    if (vr != vr_new)
        ipcom_proc_vr_set(vr);
#endif
    return 0;
}
/*
 *===========================================================================
 *                    ipcom_shell_print_prompt
 *===========================================================================
 * Description:     Print shell prompt.
 * Parameters:
 * Returns:         0 = success, <0 = error code.
 *
 */
IP_STATIC int
ipcom_shell_print_prompt(char *prompt_template, char *prompt_addr, int *promptlen, Ip_pid_t ppid, Ip_u32 seqno)
{
    int    baselen;
    int    ret = 0;
    int    buflen = 0;
    char  *buf;
#if IPCOM_USE_FILE != IPCOM_FILE_NONE
    char  *cwd;
    char  *base;
    char   cwdbuf[128];
#endif

    buf = ipcom_malloc(IPCOM_STDIO_BUFSIZE);
    if (buf == IP_NULL)
        return -1;

    for (; *prompt_template != '\0'; ++prompt_template)
    {
        ip_assert(buflen < (int)IPCOM_STDIO_BUFSIZE - 1);
        if (*prompt_template != '\\')
        {
            /* 'Normal' character */
            buf[buflen++] = *prompt_template;
        }
        else
        {
            /* New special character*/
            switch (*++prompt_template)
            {
            case 'w':
            /* Print current working directory */
            case 'W':
#if IPCOM_USE_FILE != IPCOM_FILE_NONE
                /* Print basename of the current workning directory */
                cwd = ipcom_getcwd(cwdbuf, sizeof(cwdbuf));
                if (cwd == IP_NULL)
                {
                    IPCOM_LOG0(DEBUG, "ipcom_shell_print_prompt :: ipcom_getcwd() failed");
                    break;
                }
                if (*prompt_template == 'w')
                    base = cwd;
                else
                {
                    base = ipcom_strrchr(cwd, '/');
                    if (base != IP_NULL && base != cwd)
                        base++;
                    else
                    {
                        base = ipcom_strrchr(cwd, '\\');
                        if (base == IP_NULL)
                            base = cwd;
                        else
                            base++;
                    }
                }
                baselen = ipcom_strlen(base);
                ipcom_memcpy(buf + buflen, base, baselen);
                buflen += baselen;
#endif
                break;

            case 'p':
                /* Print the shell process name */
            {
                char procname[40];
                ipcom_sprintf(procname, "ipcom_shell_%lx_%lx", (Ip_u32)ppid, seqno);
                baselen = ipcom_strlen(procname);
                ipcom_memcpy(buf + buflen, procname, baselen);
                buflen += baselen;
            }
            break;

            case 'P':
                /* Print the shell process pid */
            {
                char pid[14];
                ipcom_sprintf(pid, "0x%lx", ipcom_getpid());
                baselen = ipcom_strlen(pid);
                ipcom_memcpy(buf + buflen, pid, baselen);
                buflen += baselen;
            }
            break;

            case 'i':
                /* Print the IP address */
                if (*prompt_addr)
                {
                    baselen = ipcom_strlen(prompt_addr);
                    ipcom_memcpy(buf + buflen, prompt_addr, baselen);
                    buflen += baselen;
                }
                break;

#if IPCOM_USE_ENV != IPCOM_ENV_NONE
            case 'V':
            {
                char vrbuf[16];
                baselen = ipcom_sprintf(vrbuf, "%d", ipcom_proc_vr_get());
                ipcom_memcpy(buf + buflen, vrbuf, baselen);
                buflen += baselen;
            }
            break;
#endif

            default:
                /* Unknown code. */
                IPCOM_LOG1(DEBUG, "ipcom_shell_print_prompt :: unknown code: %c", *prompt_template);
                buf[buflen++] = '\\';
                buf[buflen++] = '\\';
                buf[buflen++] = *prompt_template;
                break;
            }
        }
    }

    if (buflen > 0)
    {
        buf[buflen] = '\0';
        if (promptlen != IP_NULL)
            *promptlen = ipcom_strlen(buf);
        ipcom_printf(buf);
    }
    ipcom_free(buf);
    if (ret < 0)
        IPCOM_LOG0(WARNING, "ipcom_shell_print_prompt :: ipcom_printf() failed");
    return ret;
}