summaryrefslogtreecommitdiff
path: root/lume-legacy/src/user/init.cc
blob: 376e697dbd92859fb009cf9f2474f2e8205838ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (C) 2026 Richard QIn
 */
#include "ulib/stdio.h"
#include "ulib/stdlib.h"
#include "ulib/string.h"
#include "user/user.h"
#include "drivers/uart_color.h"

int main()
{
    char *argv[] = {(char *)"sh", 0};

    printf(ANSI_BLUE "\n[Init] Starting Lume OS Shell..." ANSI_RESET);
    printf("\n");

    while (1)
    {
        // printf("fork start\n");
        int pid = fork();
        // printf("fork suceess, pid=%i\n", pid);
        
        if (pid < 0)
        {
            printf("[Init] fork failed!\n");
            exit(1);
        }

        if (pid == 0)
        {
            
            char sh_path[] = "/sh";
            exec(sh_path, argv);

            printf("[Init] exec sh failed\n");
            return 0;
            exit(1);
        }
        else
        {
            // break;
            int status;
            int wpid;
            while (1)
            {
                wpid = wait((uint64)&status);

                if (wpid == pid)
                {
                    printf("Shell Exit");
                    break;
                }
                if (wpid < 0)
                {
                    printf("[Init] wait error or no child\n");

                    break;
                }
            }
        }
    }
    return 0;
}