Fixed behavior of VTerm when driver is set at runtime
[tpg/acess2.git] / Usermode / Applications / init_src / main.c
1 /*
2  * Acess2 System Init Task
3  */
4 #include <acess/sys.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <spiderscript.h>
8 //#include "common.h"
9
10 // === CONSTANTS ===
11 #define NULL    ((void*)0)
12 #define NUM_TERMS       4
13 #define DEFAULT_TERMINAL        "/Devices/VTerm/0"
14 #define DEFAULT_SHELL   "/Acess/SBin/login"
15 #define DEFAULT_SCRIPT  "/Acess/Conf/BootConf.isc"
16
17 #define ARRAY_SIZE(x)   ((sizeof(x))/(sizeof((x)[0])))
18
19 // === PROTOTYPES ===
20 tSpiderVariable *Script_System_IO_Open(tSpiderScript *, int, tSpiderVariable *);
21
22 // === GLOBALS ===
23 tSpiderFunction gaScriptNS_IO_Fcns[] = {
24         {"Open", Script_System_IO_Open}
25 };
26 tSpiderNamespace        gaScriptNS_System[] = {
27         {
28                 "IO",
29                 0, NULL,
30                 ARRAY_SIZE(gaScriptNS_IO_Fcns), gaScriptNS_IO_Fcns,
31                 0, NULL
32         }
33 };
34
35 tSpiderNamespace        gaScriptNamespaces[] = {
36         {
37                 "System",
38                 ARRAY_SIZE(gaScriptNS_System), gaScriptNS_System,
39                 0, NULL,
40                 0, NULL
41         }
42 };
43
44 tSpiderVariant  gScriptVariant = {
45         "init", 0,
46         ARRAY_SIZE(gaScriptNamespaces), gaScriptNamespaces
47 };
48
49 // === CODE ===
50 /**
51  * \fn int main(int argc, char *argv[])
52  * \brief Entrypoint
53  */
54 int main(int argc, char *argv[])
55 {
56          int    tid;
57          int    i;
58         char    termpath[sizeof(DEFAULT_TERMINAL)] = DEFAULT_TERMINAL;
59         char    *child_argv[2] = {DEFAULT_SHELL, 0};
60         
61         // - Parse init script
62         
63         // - Start virtual terminals
64         for( i = 0; i < NUM_TERMS; i++ )
65         {               
66                 tid = clone(CLONE_VM, 0);
67                 if(tid == 0)
68                 {
69                         termpath[sizeof(DEFAULT_TERMINAL)-2] = '0' + i;
70                         
71                         open(termpath, OPENFLAG_READ);  // Stdin
72                         open(termpath, OPENFLAG_WRITE); // Stdout
73                         open(termpath, OPENFLAG_WRITE); // Stderr
74                         execve(DEFAULT_SHELL, child_argv, NULL);
75                         for(;;) sleep();
76                 }
77         }
78         
79         // TODO: Implement message watching
80         for(;;) sleep();
81         
82         return 42;
83 }
84
85 /**
86  * \brief Reads and parses the boot configuration script
87  * \param Filename      File to parse and execute
88  */
89 void ExecuteScript(const char *Filename)
90 {
91         tSpiderScript   *script;
92         script = SpiderScript_ParseFile(&gScriptVariant, Filename);
93         SpiderScript_ExecuteMethod(script, "");
94         SpiderScript_Free(script);
95 }
96
97 /**
98  * \brief Open a file
99  */
100 tSpiderVariable *Script_System_IO_Open(tSpiderScript *Script, int NArgs, tSpiderVariable *Args)
101 {
102         return NULL;
103 }

UCC git Repository :: git.ucc.asn.au