75 lines
1.7 KiB
C
75 lines
1.7 KiB
C
/* Calcite, src/user-apps/init/init.c
|
|
* Copyright 2025-2026 Benji Dial
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
* for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <kernel-public/process.h>
|
|
#include <calcite/file-streams.h>
|
|
#include <kernel-public/files.h>
|
|
#include <kernel-public/ipc.h>
|
|
#include <calcite/syscalls.h>
|
|
|
|
#define MAX_LINE_LENGTH 1023
|
|
|
|
void main() {
|
|
|
|
struct file_stream *rc;
|
|
if (open_file_stream("root://calcite/init.rc", &rc) != FAR_SUCCESS)
|
|
return;
|
|
|
|
int at_file_end = 0;
|
|
|
|
while (!at_file_end) {
|
|
|
|
char line[MAX_LINE_LENGTH + 1];
|
|
int line_length = 0;
|
|
|
|
while (1) {
|
|
|
|
char ch = read_file_stream_byte(rc);
|
|
|
|
if (ch == -1) {
|
|
at_file_end = 1;
|
|
break;
|
|
}
|
|
if (ch == '\n')
|
|
break;
|
|
if (line_length == MAX_LINE_LENGTH) {
|
|
while (1) {
|
|
ch = read_file_stream_byte(rc);
|
|
if (ch == -1 || ch == '\n')
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
|
|
line[line_length++] = ch;
|
|
|
|
}
|
|
|
|
if (line_length == 0 || line[0] == '#')
|
|
continue;
|
|
|
|
line[line_length] = 0;
|
|
|
|
struct process_start_info psi;
|
|
psi.forwared_envvar_count = 0;
|
|
psi.set_envvar_count = 0;
|
|
|
|
start_elf(line, &psi);
|
|
|
|
}
|
|
|
|
}
|