Exemplo n.º 1
0
int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
                FAR char **argv)
{
    int ret = OK;

    sched_lock();

    /* Try to find command within pre-built application list. */

    ret = exec_namedapp(cmd, (FAR const char **)argv);
    if (ret >= 0)
    {
#ifdef CONFIG_SCHED_WAITPID
        if (vtbl->np.np_bg == false)
        {
            int rc = 0;

            waitpid(ret, &rc, 0);

            /* We can't return the exact status (nsh has nowhere to put it)
             * so just pass back zero/nonzero in a fashion that doesn't look
             * like an error.
             */

            ret = (rc == 0) ? OK : 1;

            /* TODO:  Set the environment variable '?' to a string corresponding
             * to WEXITSTATUS(rc) so that $? will expand to the exit status of
             * the most recently executed task.
             */
        }
        else
#endif
        {
            struct sched_param param;
            sched_getparam(0, &param);
            nsh_output(vtbl, "%s [%d:%d]\n", cmd, ret, param.sched_priority);

            /* Backgrounded commands always 'succeed' as long as we can start
             * them.
             */

            ret = OK;
        }
    }


    sched_unlock();

    if (ret < 0)
    {
        return -errno;
    }

    return ret;
}
Exemplo n.º 2
0
int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
                FAR char *argv[])
{
#ifndef CONFIG_APPS_BINDIR
   FAR const char * name;
#endif
   int ret = OK;

   /* Try to find command within pre-built application list. */

   ret = exec_namedapp(cmd, argv);
   if (ret < 0)
     {
       int err = -errno;
#ifndef CONFIG_APPS_BINDIR
       int i;
       
       /* On failure, list the set of available built-in commands */

       nsh_output(vtbl, "Builtin Apps: ");
       for (i = 0; (name = namedapp_getname(i)) != NULL; i++)
         {
           nsh_output(vtbl, "%s ", name);
         }
       nsh_output(vtbl, "\nand type 'help' for more NSH commands.\n\n");

       /* If the failing command was '?', then do not report an error */
       
       if (strcmp(cmd, "?") != 0)
         {
           return err;
         }

       return OK;
#else
       return err;
#endif
     }

#ifdef CONFIG_SCHED_WAITPID
   if (vtbl->np.np_bg == false)
     {
       waitpid(ret, NULL, 0);
     }
   else
#endif
     {
       struct sched_param param;
       sched_getparam(0, &param);
       nsh_output(vtbl, "%s [%d:%d]\n", cmd, ret, param.sched_priority);
     }

   return OK;
}