MCPcopy Index your code
hub / github.com/RT-Thread/rt-thread / lwp_startup

Function lwp_startup

components/lwp/lwp_runtime.c:49–110  ·  view source on GitHub ↗

* Startup process 1 and do the essential works */

Source from the content-addressed store, hash-verified

47 * Startup process 1 and do the essential works
48 */
49static int lwp_startup(void)
50{
51 int error;
52
53 const char *init_path;
54 char *argv[] = {0, "&"};
55 char *envp[] = {LWP_CONSOLE_PATH, 0};
56
57#ifdef LWP_DEBUG_INIT
58 int command;
59 int countdown = LATENCY_TIMES;
60 while (countdown)
61 {
62 command = lwp_startup_debug_request();
63 if (command)
64 {
65 return 0;
66 }
67 rt_kprintf("Press any key to stop init process startup ... %d\n", countdown);
68 countdown -= 1;
69 rt_thread_mdelay(LATENCY_IN_MSEC);
70 }
71 rt_kprintf("Starting init ...\n");
72#endif /* LWP_DEBUG_INIT */
73
74 for (size_t i = 0; i < sizeof(init_search_path)/sizeof(init_search_path[0]); i++)
75 {
76 struct stat s;
77 init_path = init_search_path[i];
78 error = stat(init_path, &s);
79 if (error == 0)
80 {
81 argv[0] = (void *)init_path;
82 error = lwp_execve((void *)init_path, 0, sizeof(argv)/sizeof(argv[0]), argv, envp);
83 if (error < 0)
84 {
85 LOG_W("%s: failed to setup runtime environment\b"
86 "\tlwp_execve() failed with code %d", __func__, error);
87 }
88 else if (error != 1)
89 {
90 LOG_W("%s: pid 1 is already allocated", __func__);
91 error = -EBUSY;
92 }
93 else
94 {
95 rt_lwp_t p = lwp_from_pid_locked(1);
96 p->sig_protected = 1;
97
98 error = 0;
99 }
100 break;
101 }
102 }
103
104 if (error)
105 {
106 LOG_D("%s: failed to setup runtime environment\b"

Callers

nothing calls this directly

Calls 6

rt_kprintfFunction · 0.85
rt_thread_mdelayFunction · 0.85
lwp_execveFunction · 0.85
lwp_from_pid_lockedFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected