コード例 #1
0
/*
 *===========================================================================
 *                    ipcom_clearenv
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 *
 */
IP_PUBLIC int
ipcom_clearenv(void)
{
#if IPCOM_USE_ENV == IPCOM_ENV_IPCOM
    Ip_err      retval;
    Ipcom_proc *proc;

    proc = ipcom_proc_self();
    ip_assert(proc != IP_NULL);

    retval = ipcom_once(&proc->env_once, ipcom_env_init, proc);
    if (retval != IPCOM_SUCCESS)
    {
        IP_PANIC();
        return -1;
    }

    ipcom_proc_clearenv(proc);
    return 0;

#elif IPCOM_USE_ENV == IPCOM_ENV_NATIVE && (defined(IP_PORT_OSE) || defined(IP_PORT_OSE5))
    /*!! Are all environment variables cleaned up by OS automatically? */
    return 0;

#elif defined(IPCOM_USE_SYSVAR) && IPCOM_VR_MAX == 1
    /*! Hmmmm */
    return -1;

#else
    return -1;

#endif /* #if IPCOM_USE_ENV == IPCOM_ENV_IPCOM */
}
コード例 #2
0
/*
 *===========================================================================
 *                    ipcom_proc_copyenv
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 *
 */
IP_GLOBAL void
ipcom_proc_copyenv(Ipcom_proc *proc_c)
{
    Ipcom_proc         *proc_p;
    Ip_err              retval;

    proc_p = ipcom_proc_self();
    ip_assert(proc_p != IP_NULL);
    ip_assert(proc_c != IP_NULL);

    if (proc_p->env_tree == IP_NULL)
        /* Parent process has no environment variables */
        return;

    /* Create child environment semaphore and tree */
    retval = ipcom_once(&proc_c->env_once, ipcom_env_init, proc_c);
    if (retval != IPCOM_SUCCESS)
    {
        IP_PANIC();
        return;
    }

    ipcom_mutex_lock(proc_p->env_mutex);

    ipcom_hash_for_each(proc_p->env_tree,
                        (Ipcom_hash_foreach_cb_func) ipcom_env_clone,
                        proc_c->env_tree);

    ipcom_mutex_unlock(proc_p->env_mutex);
}
コード例 #3
0
/*
 *===========================================================================
 *                    ipcom_getenv
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 *
 */
IP_PUBLIC char *
ipcom_getenv(const char *name)
{
#if IPCOM_USE_ENV == IPCOM_ENV_IPCOM
    Ip_err           retval;
    Ipcom_proc      *proc;
    Ipcom_env_entry *env;
    char            *value = IP_NULL;

    proc = ipcom_proc_self();
    ip_assert(proc != IP_NULL);

    retval = ipcom_once(&proc->env_once, ipcom_env_init, proc);
    if (retval != IPCOM_SUCCESS)
    {
        IP_PANIC();
        return IP_NULL;
    }

    ipcom_mutex_lock(proc->env_mutex);

    env = ipcom_hash_get(proc->env_tree, name);
    if (env != IP_NULL)
        value = (char *)env->value;

    ipcom_mutex_unlock(proc->env_mutex);

    return value;

#elif IPCOM_USE_ENV == IPCOM_ENV_NATIVE && (defined(IP_PORT_OSE) || defined(IP_PORT_OSE5))
    char *env;
    static char buf[256];

    env = get_env(current_process(), name);
    if (env != IP_NULL)
    {
        ipcom_strncpy(buf, env, sizeof(buf));
        free_buf((union SIGNAL **)&env);
        return (char *)buf;
    }
    return IP_NULL;

#elif IPCOM_USE_ENV == IPCOM_ENV_NATIVE
    return getenv(name);

#elif defined(IPCOM_USE_SYSVAR) && IPCOM_VR_MAX == 1
    static char buf[256];
    Ip_size_t  buf_size = sizeof(buf);

    return ipcom_sysvar_get(name, buf, &buf_size);

#else
    return IP_NULL;

#endif /* #if IPCOM_USE_ENV == IPCOM_ENV_IPCOM */
}
コード例 #4
0
/*
 *===========================================================================
 *                    ipcom_shellalias_setup
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 *
 */
IP_STATIC Ip_err
ipcom_shellalias_setup()
{
    Ip_err                          err;
    static Ipcom_once_t             once = IPCOM_ONCE_INIT;

    err = ipcom_once(&once, ipcom_shellalias_init, IP_NULL);
    if (err != IPCOM_SUCCESS)
        return err;

    return IPCOM_SUCCESS;
}
コード例 #5
0
/*
 *===========================================================================
 *                    ipcom_unsetenv
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 *
 */
IP_PUBLIC int
ipcom_unsetenv(const char *name)
{
#if IPCOM_USE_ENV == IPCOM_ENV_IPCOM
    Ip_err           retval;
    Ipcom_proc      *proc;
    Ipcom_env_entry *env;

    proc = ipcom_proc_self();
    ip_assert(proc != IP_NULL);

    retval = ipcom_once(&proc->env_once, ipcom_env_init, proc);
    if (retval != IPCOM_SUCCESS)
    {
        IP_PANIC();
        return -1;
    }

    ipcom_mutex_lock(proc->env_mutex);

    env = ipcom_hash_get(proc->env_tree, name);
    if (env != IP_NULL)
        ipcom_env_delete(env, proc->env_tree);

    ipcom_mutex_unlock(proc->env_mutex);

    return 0;

#elif IPCOM_USE_ENV == IPCOM_ENV_NATIVE && (defined(IP_PORT_OSE) || defined(IP_PORT_OSE5))
    set_env(current_process(), name, NULL);
    return 0;

#elif IPCOM_USE_ENV == IPCOM_ENV_NATIVE && defined(IP_PORT_VXWORKS)
    {
        char buf[256];
        int  ret;
        ipcom_snprintf(buf, sizeof(buf), "%s=", name);
        ret = (int)putenv(buf);
        return ret == 0 ? 0 : -1;
    }

#elif IPCOM_USE_ENV == IPCOM_ENV_NATIVE
    return unsetenv(name);

#elif defined(IPCOM_USE_SYSVAR) && IPCOM_VR_MAX == 1
    (void)ipcom_sysvar_unset(name);
    return 0;

#else
    return 0;

#endif /* #if IPCOM_USE_ENV == IPCOM_ENV_IPCOM */
}
コード例 #6
0
ファイル: ipcom_shellcmd.c プロジェクト: rgmabs19357/Huawei-
/*
 *===========================================================================
 *                    ipcom_shell_add_cmd
 *===========================================================================
 * Description:     Add a command to the list of available ipcom_shell commands
 * Parameters:      name : command's name
 *                  usage : usage string
 *                  description : description of command
 *                  hook : function to that executes the command
 *                  priority : na
 *                  stack_size : the stack to be used by the process that
 *                               executes the hook.
 *
 * Returns:         IPCOM_SUCCESS : ok
 *                  IPCOM_ERR_DUPLICATE : command already exists
 *                  IPCOM_ERR_NO_MEMORY : out of memory
 *
 *
 */
IP_PUBLIC Ip_err
ipcom_shell_add_cmd(const char *name, const char *usage,
                    const char *description, Ipcom_shell_cmd_type hook,
                    Ip_s32 priority, Ip_s32 stack_size)
{
    Ipcom_shell_cmd *cmd;
    static Ipcom_once_t  once = IPCOM_ONCE_INIT;
    Ip_err  err;

    err = ipcom_once(&once, ipcom_shellcmd_init, IP_NULL);
    if (err != IPCOM_SUCCESS)
        return err;

    /* First check if present */
    cmd = ipcom_shell_find_cmd(name);
    if (cmd != IP_NULL)
        return IPCOM_ERR_DUPLICATE;      /*!!allow duplicates for overlay. */

    /* Add a new entry to the list */
    cmd = (Ipcom_shell_cmd *)ipcom_malloc(sizeof(Ipcom_shell_cmd));
    if (cmd == IP_NULL)
        return IPCOM_ERR_NO_MEMORY;

    ipcom_memset(cmd, 0, sizeof(Ipcom_shell_cmd));

    ipcom_strncpy(cmd->name, name, sizeof(cmd->name)-1);
    ipcom_strncpy(cmd->usage, usage, sizeof(cmd->usage)-1);
    ipcom_strncpy(cmd->description, description, sizeof(cmd->description)-1);

    cmd->hook = hook;
    if (priority == 0 || priority == IPCOM_SHELL_PRIO_SAME)
       cmd->priority = ipcom_proc_getprio(ipcom_getpid());
    else
       cmd->priority = priority;
    cmd->stack_size = stack_size;

    ipcom_list_insert_last(&ipcom_shell_cmd_head, &cmd->cmd_list);

#if defined(WRS_IPNET) && defined(IP_PORT_VXWORKS) && (IP_PORT_VXWORKS >= 65)
    (void)ipcom_vxshell_add_cmd(name,
                                usage,
                                description,
                                hook,
                                priority,
                                stack_size);
#endif

    return IPCOM_SUCCESS;
}
コード例 #7
0
ファイル: ipcom_sysvar.c プロジェクト: rgmabs19357/Huawei-
/*
 *===========================================================================
 *                    ipcom_sysvar_unset
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 */
IP_PUBLIC Ip_err
ipcom_sysvar_unset(const char *name)
{
    Ipcom_sysvar_entry *sysvar;
    Ip_err              retval;
    Ip_size_t           namelen;
    Ipcom_sysvar_tree   *tree;

    retval = ipcom_once(&ipcom_sysvar_once, ipcom_sysvar_init, IP_NULL);
    if (retval != IPCOM_SUCCESS)
        return retval;

    namelen = ipcom_strlen(name);
    if (name[namelen-1] == '*')
        return ipcom_sysvar_for_each(name, ipcom_sysvar_unset_cb, IP_NULL);

    IPCOM_CODE_LOCK();

    tree = ipcom_sysvar_tree_get(-1);
    if (tree == IP_NULL)
    {
        retval = IPCOM_ERR_NO_MEMORY;
        goto leave;
    }

    retval = IPCOM_ERR_NOT_FOUND;
    sysvar = ipcom_hash_get(tree->sysvars, name);
    if (sysvar)
    {
        if(IP_BIT_ISSET(sysvar->flags, IPCOM_SYSVAR_FLAG_READONLY))
            retval = IPCOM_ERR_READONLY;
        else
        {
            ipcom_sysvar_release(tree, sysvar);
            retval = IPCOM_SUCCESS;
        }
    }

 leave:
    ipcom_sysvar_tree_done(tree);
    IPCOM_CODE_UNLOCK();
    return retval;
}
コード例 #8
0
ファイル: ipcom_sysvar.c プロジェクト: rgmabs19357/Huawei-
IP_STATIC Ip_err
ipcom_sysvar_setvr(const char *name, const char *value, int flags, int vr)
{
    Ip_err retval;
    Ipcom_sysvar_tree   *tree;


    if (value == IP_NULL)
        return IPCOM_SUCCESS;  /* simply ignore it silently */

#ifdef IP_PORT_OSE5
    if (IP_BIT_ISFALSE(flags, IPCOM_SYSVAR_FLAG_OVERWRITE))
    {
        Ip_size_t test_size = 1;
        char test[1];

        if (ipcom_sysvar_get_ose5(name, test, &test_size) || test_size > 1)
            return IPCOM_ERR_DUPLICATE;
    }
#endif /* IP_PORT_OSE5 */


    retval = ipcom_once(&ipcom_sysvar_once, ipcom_sysvar_init, IP_NULL);
    if (retval != IPCOM_SUCCESS)
    {
        IP_PANIC();
        return retval;
    }

    IPCOM_CODE_LOCK();

    tree = ipcom_sysvar_tree_get(vr);
    if (tree == IP_NULL)
        retval = IPCOM_ERR_NO_MEMORY;
    else
        retval =  ipcom_sysvar_set_tree(name, value, flags, tree);
    ipcom_sysvar_tree_done(tree);

    IPCOM_CODE_UNLOCK();

    return retval;
}
コード例 #9
0
ファイル: ipppp_example.c プロジェクト: rgmabs19357/Huawei-
/*
 *===========================================================================
 *                       ipppp_work_schedule
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 *
 */
IP_STATIC int
ipppp_work_schedule(struct Ipppp_action_work *work)
{
    if (ipcom_once(&ipppp_work_once,
                   ipppp_work_init,
                   IP_NULL)
        != IPCOM_SUCCESS)
    {
        IP_PANIC();
        return -1;
    }


    ipcom_mutex_lock(ipppp_work_lock);
    ipcom_list_insert_last(&ipppp_work_queue, &work->list);
    ipcom_mutex_unlock(ipppp_work_lock);

    ipcom_sem_post(ipppp_work_sem);
    return 0;
}
コード例 #10
0
ファイル: ipcom_sysvar.c プロジェクト: rgmabs19357/Huawei-
/*
 *===========================================================================
 *                    ipcom_sysvar_for_each
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 */
IP_PUBLIC Ip_err
ipcom_sysvar_for_each(const char            *name,
                      Ipcom_sysvar_for_each cb_func,
                      void                  *cookie)
{
    Ipcom_sysvar_entry *sysvar;
    Ipcom_sysvar_tree  *tree;
    Ip_size_t           namelen = 0;
    Ip_err              retval;
    Ipcom_pqueue       *pq;

    retval = ipcom_once(&ipcom_sysvar_once, ipcom_sysvar_init, IP_NULL);
    if (retval != IPCOM_SUCCESS)
        return retval;

    if (name)
    {
        namelen = ipcom_strlen(name);
        if (name[namelen-1] == '*')
            namelen--; /* ignore trailing wildcard sign */
    }

    pq = ipcom_pqueue_new((Ipcom_pqueue_cmp_func)ipcom_sysvar_pqueue_cmp,
                          ipcom_pqueue_nop_store_index);
    if (pq == IP_NULL)
        return IPCOM_ERR_NO_MEMORY;

    IPCOM_CODE_LOCK();

    tree = ipcom_sysvar_tree_get(-1);
    if (tree == IP_NULL)
    {
        ipcom_pqueue_delete(pq);
        IPCOM_CODE_UNLOCK();
        return IPCOM_ERR_NO_MEMORY;
    }

    /* Add all sysvars to the priority queue so they can be extracted
       sorted in lexicographical order */
    ipcom_hash_for_each(tree->sysvars,
                        (Ipcom_hash_foreach_cb_func)ipcom_sysvar_pqueue_insert_cb,
                        pq);

    while (IP_NULL != (sysvar = ipcom_pqueue_remove_next(pq)))
    {
        if (name == IP_NULL
            || ipcom_strncmp(sysvar->name, name, namelen) == 0)
        {
            IPCOM_CODE_UNLOCK();
            (void)cb_func(sysvar->name, sysvar->value, sysvar->flags, cookie);
            IPCOM_CODE_LOCK();
        }
        ipcom_sysvar_release(tree, sysvar);
    }

    ipcom_pqueue_delete(pq);
    ipcom_sysvar_tree_done(tree);

    IPCOM_CODE_UNLOCK();

#ifdef IP_PORT_OSE5_DISABLED
    return ipcom_sysvar_for_each_ose5(name, cb_func, cookie);
#else
    return IPCOM_SUCCESS;
#endif
}
コード例 #11
0
ファイル: ipcom_sysvar.c プロジェクト: rgmabs19357/Huawei-
/*
 *===========================================================================
 *                    ipcom_sysvar_getvr
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 */
IP_GLOBAL char *
ipcom_sysvar_getvr(const char *name, char *value, Ip_size_t *value_size, Ip_bool usr, int vr)
{
    Ipcom_sysvar_entry  *sysvar;
    Ip_size_t           value_length;
    char                *ret_value = IP_NULL;
    Ip_err              retval;
    Ipcom_sysvar_tree   *tree;

    if (name == IP_NULL)
        return IP_NULL;

    retval = ipcom_once(&ipcom_sysvar_once, ipcom_sysvar_init, IP_NULL);
    if (retval != IPCOM_SUCCESS)
    {
        IP_PANIC();
        return IP_NULL;
    }

    IPCOM_CODE_LOCK();

    tree = ipcom_sysvar_tree_get(vr);
    if (tree == IP_NULL)
        goto leave;

    sysvar = ipcom_hash_get(tree->sysvars, name);
    if (sysvar)
    {
        if (value == IP_NULL)
        {
#ifdef IP_PORT_OSE5
            if (usr)
                ret_value = ipcom_strdup_usr(sysvar->value);
            else
#else
                (void)usr;
#endif
                ret_value = ipcom_strdup(sysvar->value);
        }
        else
        {
            value_length = ipcom_strlen(sysvar->value) + 1;
            if (value_length > *value_size)
            {
                ret_value = IP_NULL;
                *value_size = value_length;
            }
            else
            {
                ret_value = value;
                ipcom_memcpy(ret_value, sysvar->value, value_length);
                *value_size = value_length - 1;
            }
        }
    }
#ifdef IP_PORT_OSE5
    else
    {
        ret_value = ipcom_sysvar_get_ose5(name, value, value_size);
    }
#endif /* IP_PORT_OSE5 */

 leave:
    ipcom_sysvar_tree_done(tree);
    IPCOM_CODE_UNLOCK();
    return ret_value;
}
コード例 #12
0
/*
 *===========================================================================
 *                    ipcom_setenv
 *===========================================================================
 * Description:
 * Parameters:
 * Returns:
 *
 */
IP_PUBLIC int
ipcom_setenv(const char *name, const char *value, int rewrite)
{
#if IPCOM_USE_ENV == IPCOM_ENV_IPCOM
    Ip_err           retval;
    Ipcom_proc      *proc;
    Ipcom_env_entry *env;

    proc = ipcom_proc_self();
    ip_assert(proc != IP_NULL);

    retval = ipcom_once(&proc->env_once, ipcom_env_init, proc);
    if (retval != IPCOM_SUCCESS)
    {
        IP_PANIC();
        return -1;
    }

    ipcom_mutex_lock(proc->env_mutex);

    /* Check for duplicate. */
    env = ipcom_hash_get(proc->env_tree, name);
    if (env != IP_NULL)
    {
        if (rewrite == 0)
            goto leave;
        ipcom_env_delete(env, proc->env_tree);
    }

    /* Create environment variable. */
    env = ipcom_env_create(name, value);
    if (env == IP_NULL)
    {
        ipcom_mutex_unlock(proc->env_mutex);
        return -1;
    }
    (void)ipcom_hash_add(proc->env_tree, env);

 leave:
    ipcom_mutex_unlock(proc->env_mutex);
    return 0;

#elif IPCOM_USE_ENV == IPCOM_ENV_NATIVE && (defined(IP_PORT_OSE) || defined(IP_PORT_OSE5))
    (void)rewrite;

    set_env(current_process(), name, value);
    return 0;

#elif IPCOM_USE_ENV == IPCOM_ENV_NATIVE && defined(IP_PORT_VXWORKS)
    char buf[256];
    int  ret;

    (void)rewrite;

    ipcom_snprintf(buf, sizeof(buf), "%s=%s", name, value);
    ret = (int)putenv(buf);
    return ret == 0 ? 0 : -1;

#elif IPCOM_USE_ENV == IPCOM_ENV_NATIVE
    return setenv(name, value, rewrite);

#elif defined(IPCOM_USE_SYSVAR) && IPCOM_VR_MAX == 1
    (void)ipcom_sysvar_set(name, value, rewrite ? IPCOM_SYSVAR_FLAG_OVERWRITE : 0);
    return 0;

#else
    (void)name;
    (void)value;
    (void)rewrite;
    return -1;

#endif /* #if IPCOM_USE_ENV == IPCOM_ENV_IPCOM */
}