You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/04/19 14:07:18 UTC
[incubator-nuttx-apps] 04/09: system/taskset: Call system to launch
application instead of nsh_system
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 7b4d34e3526fc1232ffbf5c1b48392c5ffcbd9be
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Apr 17 02:35:20 2020 +0800
system/taskset: Call system to launch application instead of nsh_system
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
system/system/system.c | 2 +-
system/taskset/Kconfig | 2 +-
system/taskset/taskset.c | 33 +++++++++++----------------------
3 files changed, 13 insertions(+), 24 deletions(-)
diff --git a/system/system/system.c b/system/system/system.c
index 2573269..76749c2 100644
--- a/system/system/system.c
+++ b/system/system/system.c
@@ -148,7 +148,7 @@ int system(FAR const char *cmd)
errcode = posix_spawn(&pid, CONFIG_SYSTEM_SYSTEM_SHPATH, NULL, &attr,
argv, (FAR char * const *)NULL);
#else
- errcode = task_spawn(&pid, "popen", nsh_system, NULL, &attr,
+ errcode = task_spawn(&pid, "system", nsh_system, NULL, &attr,
argv, (FAR char * const *)NULL);
#endif
diff --git a/system/taskset/Kconfig b/system/taskset/Kconfig
index a9e5d21..0be8361 100644
--- a/system/taskset/Kconfig
+++ b/system/taskset/Kconfig
@@ -6,7 +6,7 @@
config SYSTEM_TASKSET
tristate "Taskset Command"
default n
- depends on SMP && NSH_LIBRARY && SCHED_WAITPID
+ depends on SMP && SYSTEM_SYSTEM
---help---
Enable support for the taskset command.
diff --git a/system/taskset/taskset.c b/system/taskset/taskset.c
index 4decd97..b2efb2b 100644
--- a/system/taskset/taskset.c
+++ b/system/taskset/taskset.c
@@ -49,8 +49,6 @@
#include <errno.h>
#include <string.h>
-#include "nshlib/nshlib.h"
-
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -59,11 +57,10 @@
* Name: show_usage
****************************************************************************/
-static void show_usage(FAR const char *progname, int exitcode) noreturn_function;
static void show_usage(FAR const char *progname, int exitcode)
{
- printf("%s mask command ... \n", progname);
- printf("%s -p [mask] pid \n", progname);
+ printf("%s mask command ...\n", progname);
+ printf("%s -p [mask] pid\n", progname);
exit(exitcode);
}
@@ -85,7 +82,7 @@ static bool get_cpuset(const char *arg, cpu_set_t *cpu_set)
}
else
{
- fprintf(stderr, "invalid cpuset %s \n", arg);
+ fprintf(stderr, "invalid cpuset %s\n", arg);
}
return ret;
@@ -97,7 +94,6 @@ static bool get_cpuset(const char *arg, cpu_set_t *cpu_set)
int main(int argc, FAR char *argv[])
{
- FAR char *nshargv[2];
char command[CONFIG_NSH_LINELEN];
int exitcode;
int option;
@@ -143,7 +139,8 @@ int main(int argc, FAR char *argv[])
if (-1 == rc)
{
- fprintf(stderr, "Err in sched_setaffinity() errno=%d \n", errno);
+ fprintf(stderr,
+ "Err in sched_setaffinity() errno=%d\n", errno);
goto errout;
}
}
@@ -152,11 +149,11 @@ int main(int argc, FAR char *argv[])
if (-1 == rc)
{
- fprintf(stderr, "Err in sched_getaffinity() errno=%d \n", errno);
+ fprintf(stderr, "Err in sched_getaffinity() errno=%d\n", errno);
goto errout;
}
- printf("pid %d's current affinity mask: %x \n", pid, cpuset);
+ printf("pid %d's current affinity mask: %x\n", pid, cpuset);
}
else
{
@@ -167,8 +164,9 @@ int main(int argc, FAR char *argv[])
goto errout;
}
- /* Construct actual command with args */
- /* NOTE: total length does not exceed CONFIG_NSH_LINELEN */
+ /* Construct actual command with args
+ * NOTE: total length does not exceed CONFIG_NSH_LINELEN
+ */
for (i = 0; i < argc - 2; i++)
{
@@ -176,17 +174,8 @@ int main(int argc, FAR char *argv[])
strcat(command, " ");
}
- nshargv[0] = command;
- nshargv[1] = NULL;
-
sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpuset);
- usleep(10 * 1000);
-
- pid = task_create("system", CONFIG_SYSTEM_TASKSET_PRIORITY,
- CONFIG_SYSTEM_TASKSET_STACKSIZE, nsh_system,
- (FAR char * const *)nshargv);
-
- waitpid(pid, &rc, 0);
+ system(command);
}
}