int mavlink_main(int argc, char *argv[]) { if (argc < 2) { warnx("missing command"); usage(); } if (!strcmp(argv[1], "start")) { /* this is not an error */ if (thread_running) errx(0, "mavlink already running\n"); thread_should_exit = false; mavlink_task = task_spawn("mavlink", SCHED_DEFAULT, SCHED_PRIORITY_DEFAULT, 6000, mavlink_thread_main, (const char**)argv); exit(0); } if (!strcmp(argv[1], "stop")) { thread_should_exit = true; while (thread_running) { usleep(200000); } warnx("terminated."); exit(0); } if (!strcmp(argv[1], "status")) { if (thread_running) { errx(0, "running"); } else { errx(1, "not running"); } } warnx("unrecognized command"); usage(); /* not getting here */ return 0; }
/** * The sd log deamon app only briefly exists to start * the background job. The stack size assigned in the * Makefile does only apply to this management task. * * The actual stack size should be set in the call * to task_spawn(). */ int sdlog_main(int argc, char *argv[]) { if (argc < 1) usage("missing command"); if (!strcmp(argv[1], "start")) { if (thread_running) { printf("sdlog already running\n"); /* this is not an error */ exit(0); } thread_should_exit = false; deamon_task = task_spawn("sdlog", SCHED_DEFAULT, SCHED_PRIORITY_DEFAULT - 30, 4096, sdlog_thread_main, (const char **)argv); exit(0); } if (!strcmp(argv[1], "stop")) { if (!thread_running) { printf("\tsdlog is not started\n"); } thread_should_exit = true; exit(0); } if (!strcmp(argv[1], "status")) { if (thread_running) { print_sdlog_status(); } else { printf("\tsdlog not started\n"); } exit(0); } usage("unrecognized command"); exit(1); }
/** * @fn :tc_libc_spawn_posix_spawnattr_dump * @brief :Show the current attributes * @scenario :It dumps the spawn attributes whose address is passed * @API's covered :posix_spawnattr_init,posix_spawnattr_setschedparam, posix_spawnattr_setflags,posix_spawnattr_setschedpolicy, posix_spawnattr_dump * @Preconditions :posix_spawnattr_init, posix_spawnattr_setschedparam, posix_spawnattr_setflags,posix_spawnattr_setschedpolicy * @Postconditions :none * @Return :void */ static void tc_libc_spawn_posix_spawnattr_dump(void) { int ret_chk = ERROR; pid_t pid; posix_spawnattr_t st_attr; ret_chk = posix_spawnattr_init(&st_attr); TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK); ret_chk = posix_spawnattr_setschedpolicy(&st_attr, SCHED_RR); TC_ASSERT_EQ("posix_spawnattr_setschedpolicy", ret_chk, OK); ret_chk = task_spawn(&pid, "spawn_dump", function_name_spawn, NULL, &st_attr, (char *const *)NULL, (char *const *)NULL); sleep(SEC_4); TC_ASSERT_EQ("task_spawn", ret_chk, OK); posix_spawnattr_dump(&st_attr); TC_SUCCESS_RESULT(); }
/** * The deamon app only briefly exists to start * the background job. The stack size assigned in the * Makefile does only apply to this management task. * * The actual stack size should be set in the call * to task_spawn(). */ int flow_position_control_main(int argc, char *argv[]) { if (argc < 1) usage("missing command"); if (!strcmp(argv[1], "start")) { if (thread_running) { printf("flow position control already running\n"); /* this is not an error */ exit(0); } thread_should_exit = false; deamon_task = task_spawn("flow_position_control", SCHED_DEFAULT, SCHED_PRIORITY_MAX - 6, 4096, flow_position_control_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); exit(0); } if (!strcmp(argv[1], "stop")) { thread_should_exit = true; exit(0); } if (!strcmp(argv[1], "status")) { if (thread_running) printf("\tflow position control app is running\n"); else printf("\tflow position control app not started\n"); exit(0); } usage("unrecognized command"); exit(1); }
/** * The attitude_estimator_ekf app only briefly exists to start * the background job. The stack size assigned in the * Makefile does only apply to this management task. * * The actual stack size should be set in the call * to task_create(). */ int attitude_estimator_ekf_main(int argc, char *argv[]) { if (argc < 1) usage("missing command"); if (!strcmp(argv[1], "start")) { if (thread_running) { printf("attitude_estimator_ekf already running\n"); /* this is not an error */ exit(0); } thread_should_exit = false; attitude_estimator_ekf_task = task_spawn("attitude_estimator_ekf", SCHED_DEFAULT, SCHED_PRIORITY_MAX - 5, 12400, attitude_estimator_ekf_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); exit(0); } if (!strcmp(argv[1], "stop")) { thread_should_exit = true; exit(0); } if (!strcmp(argv[1], "status")) { if (thread_running) { printf("\tattitude_estimator_ekf app is running\n"); } else { printf("\tattitude_estimator_ekf app not started\n"); } exit(0); } usage("unrecognized command"); exit(1); }
/** * The deamon app only briefly exists to start * the background job. The stack size assigned in the * Makefile does only apply to this management task. * * The actual stack size should be set in the call * to task_create(). */ int ardrone_interface_main(int argc, char *argv[]) { if (argc < 1) usage("missing command"); if (!strcmp(argv[1], "start")) { if (thread_running) { printf("ardrone_interface already running\n"); /* this is not an error */ exit(0); } thread_should_exit = false; ardrone_interface_task = task_spawn("ardrone_interface", SCHED_DEFAULT, SCHED_PRIORITY_MAX - 15, 2048, ardrone_interface_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); exit(0); } if (!strcmp(argv[1], "stop")) { thread_should_exit = true; exit(0); } if (!strcmp(argv[1], "status")) { if (thread_running) { printf("\tardrone_interface is running\n"); } else { printf("\tardrone_interface not started\n"); } exit(0); } usage("unrecognized command"); exit(1); }
/** * The deamon app only briefly exists to start * the background job. The stack size assigned in the * Makefile does only apply to this management task. * * The actual stack size should be set in the call * to task_create(). */ int px4_deamon_app_main(int argc, char *argv[]) { if (argc < 1) usage("missing command"); if (!strcmp(argv[1], "start")) { if (thread_running) { printf("deamon already running\n"); /* this is not an error */ exit(0); } thread_should_exit = false; deamon_task = task_spawn("deamon", SCHED_DEFAULT, SCHED_PRIORITY_DEFAULT, 4096, px4_deamon_thread_main, (argv) ? (const char **)&argv[2] : (const char **)NULL); exit(0); } if (!strcmp(argv[1], "stop")) { thread_should_exit = true; exit(0); } if (!strcmp(argv[1], "status")) { if (thread_running) { printf("\tdeamon app is running\n"); } else { printf("\tdeamon app not started\n"); } exit(0); } usage("unrecognized command"); exit(1); }
/** * @fn :tc_libc_spawn_task_spawnattr_SetGetstacksize * @brief :sets and gets the stack size attribute of the thread attributes object referred to by st_attr * @scenario :The stack size attribute determines the minimum size (in bytes) that will be allocated for * threads created using the thread attributes object st_attr. * @API's covered :posix_spawnattr_init, task_spawnattr_setstacksize,task_spawnattr_getstacksize * @Preconditions :posix_spawnattr_init * @Postconditions :none * @Return :void */ static void tc_libc_spawn_task_spawnattr_setgetstacksize(void) { int ret_chk = ERROR; pid_t pid; posix_spawnattr_t st_attr; size_t stacksize; ret_chk = posix_spawnattr_init(&st_attr); TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK); ret_chk = task_spawnattr_setstacksize(&st_attr, SPAWN_STACKSIZE); TC_ASSERT_EQ("task_spawnattr_setstacksize", ret_chk, OK); ret_chk = task_spawn(&pid, "spawn_stacksize", function_name_spawn, NULL, &st_attr, (char *const *)NULL, (char *const *)NULL); sleep(SEC_4); TC_ASSERT_EQ("task_spawn", ret_chk, OK); ret_chk = task_spawnattr_getstacksize(&st_attr, &stacksize); TC_ASSERT_EQ("task_spawnattr_getstacksize", ret_chk, OK); TC_ASSERT_EQ("task_spawnattr_getstacksize", stacksize, SPAWN_STACKSIZE); TC_SUCCESS_RESULT(); }
static void tc_libc_spawn_posix_spawnattr_setgetflags(void) { int ret_chk = ERROR; pid_t pid; posix_spawnattr_t st_attr; short int flags; ret_chk = posix_spawnattr_init(&st_attr); TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK); ret_chk = posix_spawnattr_setflags(&st_attr, POSIX_SPAWN_SETSCHEDPARAM); TC_ASSERT_EQ("posix_spawnattr_setflags", ret_chk, OK); ret_chk = task_spawn(&pid, "spawn_flag", function_name_spawn, NULL, &st_attr, (char *const *)NULL, (char *const *)NULL); sleep(SEC_3); TC_ASSERT_EQ("task_spawn", ret_chk, OK); ret_chk = posix_spawnattr_getflags(&st_attr, &flags); TC_ASSERT_EQ("posix_spawnattr_getflags", ret_chk, OK); TC_ASSERT_EQ("posix_spawnattr_getflags", flags, POSIX_SPAWN_SETSCHEDPARAM); TC_SUCCESS_RESULT(); }
/* start one px4 driver */ bool AP_BoardConfig::px4_start_driver(main_fn_t main_function, const char *name, const char *arguments) { char *s = strdup(arguments); char *args[10]; uint8_t nargs = 0; char *saveptr = nullptr; // parse into separate arguments for (char *tok=strtok_r(s, " ", &saveptr); tok; tok=strtok_r(nullptr, " ", &saveptr)) { args[nargs++] = tok; if (nargs == ARRAY_SIZE(args)-1) { break; } } args[nargs++] = nullptr; printf("Starting driver %s %s\n", name, arguments); pid_t pid; if (task_spawn(&pid, name, main_function, nullptr, nullptr, args, nullptr) != 0) { free(s); printf("Failed to spawn %s\n", name); return false; } // wait for task to exit and gather status int status = -1; if (waitpid(pid, &status, 0) != pid) { printf("waitpid failed for %s\n", name); free(s); return false; } free(s); return (status >> 8) == 0; }
/** * @fn : tc_libc_spawn_posix_spawnattr_SetGetsigmask * @brief : sets and gets the spawn-sigmask attribute in an initialized attributes object referenced by st_attr * @scenario : The spawn-sigmask attribute represents the signal mask in effect in the new process image of a spawn operation * @API's covered : posix_spawnattr_init, posix_spawnattr_setsigmask, posix_spawnattr_getsigmask * @Preconditions : posix_spawnattr_init * @Postconditions : none * @Return : void */ static void tc_libc_spawn_posix_spawnattr_setgetsigmask(void) { posix_spawnattr_t st_attr; int ret_chk = ERROR; sigset_t setMask = MIN_SIGNO; sigset_t getMask; pid_t pid; ret_chk = posix_spawnattr_init(&st_attr); TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK); ret_chk = posix_spawnattr_setsigmask(&st_attr, &setMask); TC_ASSERT_EQ("posix_spawnattr_setsigmask", ret_chk, OK); ret_chk = task_spawn(&pid, "spawn_sigmask", function_name_spawn, NULL, &st_attr, (char *const *)NULL, (char *const *)NULL); sleep(SEC_4); TC_ASSERT_EQ("task_spawn", ret_chk, OK); ret_chk = posix_spawnattr_getsigmask(&st_attr, &getMask); TC_ASSERT_EQ("posix_spawnattr_getsigmask", ret_chk, OK); TC_ASSERT_EQ("posix_spawnattr_getsigmask", setMask, getMask); TC_SUCCESS_RESULT(); }
int exec_builtin(FAR const char *appname, FAR char * const *argv, FAR const char *redirfile, int oflags) { FAR const struct builtin_s *builtin; posix_spawnattr_t attr; posix_spawn_file_actions_t file_actions; struct sched_param param; pid_t pid; int index; int ret; /* Verify that an application with this name exists */ index = builtin_isavail(appname); if (index < 0) { ret = ENOENT; goto errout_with_errno; } /* Get information about the builtin */ builtin = builtin_for_index(index); if (builtin == NULL) { ret = ENOENT; goto errout_with_errno; } /* Initialize attributes for task_spawn(). */ ret = posix_spawnattr_init(&attr); if (ret != 0) { goto errout_with_errno; } ret = posix_spawn_file_actions_init(&file_actions); if (ret != 0) { goto errout_with_attrs; } /* Set the correct task size and priority */ param.sched_priority = builtin->priority; ret = posix_spawnattr_setschedparam(&attr, ¶m); if (ret != 0) { goto errout_with_actions; } ret = task_spawnattr_setstacksize(&attr, builtin->stacksize); if (ret != 0) { goto errout_with_actions; } /* If robin robin scheduling is enabled, then set the scheduling policy * of the new task to SCHED_RR before it has a chance to run. */ #if CONFIG_RR_INTERVAL > 0 ret = posix_spawnattr_setschedpolicy(&attr, SCHED_RR); if (ret != 0) { goto errout_with_actions; } ret = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER); if (ret != 0) { goto errout_with_actions; } #else ret = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSCHEDPARAM); if (ret != 0) { goto errout_with_actions; } #endif /* Is output being redirected? */ if (redirfile) { /* Set up to close open redirfile and set to stdout (1) */ ret = posix_spawn_file_actions_addopen(&file_actions, 1, redirfile, O_WRONLY, 0644); if (ret != 0) { sdbg("ERROR: posix_spawn_file_actions_addopen failed: %d\n", ret); goto errout_with_actions; } } /* Start the built-in */ ret = task_spawn(&pid, builtin->name, builtin->main, &file_actions, &attr, (argv) ? &argv[1] : (FAR char * const *)NULL, (FAR char * const *)NULL); if (ret != 0) { sdbg("ERROR: task_spawn failed: %d\n", ret); goto errout_with_actions; } /* Free attibutes and file actions. Ignoring return values in the case * of an error. */ /* Return the task ID of the new task if the task was sucessfully * started. Otherwise, ret will be ERROR (and the errno value will * be set appropriately). */ (void)posix_spawn_file_actions_destroy(&file_actions); (void)posix_spawnattr_destroy(&attr); return pid; errout_with_actions: (void)posix_spawn_file_actions_destroy(&file_actions); errout_with_attrs: (void)posix_spawnattr_destroy(&attr); errout_with_errno: set_errno(ret); return ERROR; }