Trying to reduce the ability for a fork bomb to fault the kernel
[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 /*
21 tSpiderVariable *Script_System_IO_Open(tSpiderScript *, int, tSpiderVariable *);
22 */
23
24 // === GLOBALS ===
25 /*
26 tSpiderFunction gaScriptNS_IO_Fcns[] = {
27         {"Open", Script_System_IO_Open}
28 };
29 tSpiderNamespace        gaScriptNS_System[] = {
30         {
31                 "IO",
32                 0, NULL,
33                 ARRAY_SIZE(gaScriptNS_IO_Fcns), gaScriptNS_IO_Fcns,
34                 0, NULL
35         }
36 };
37
38 tSpiderNamespace        gaScriptNamespaces[] = {
39         {
40                 "System",
41                 ARRAY_SIZE(gaScriptNS_System), gaScriptNS_System,
42                 0, NULL,
43                 0, NULL
44         }
45 };
46
47 tSpiderVariant  gScriptVariant = {
48         "init", 0,
49         ARRAY_SIZE(gaScriptNamespaces), gaScriptNamespaces
50 };
51 */
52
53 // === CODE ===
54 /**
55  * \fn int main(int argc, char *argv[])
56  * \brief Entrypoint
57  */
58 int main(int argc, char *argv[])
59 {
60          int    tid;
61          int    i;
62         char    termpath[sizeof(DEFAULT_TERMINAL)] = DEFAULT_TERMINAL;
63         char    *child_argv[2] = {DEFAULT_SHELL, 0};
64         
65         // - Parse init script
66         
67         // - Start virtual terminals
68         for( i = 0; i < NUM_TERMS; i++ )
69         {               
70                 tid = clone(CLONE_VM, 0);
71                 if(tid == 0)
72                 {
73                         termpath[sizeof(DEFAULT_TERMINAL)-2] = '0' + i;
74                         
75                         open(termpath, OPENFLAG_READ);  // Stdin
76                         open(termpath, OPENFLAG_WRITE); // Stdout
77                         open(termpath, OPENFLAG_WRITE); // Stderr
78                         execve(DEFAULT_SHELL, child_argv, NULL);
79                         for(;;) sleep();
80                 }
81         }
82         
83         // TODO: Implement message watching
84         for(;;) sleep();
85         
86         return 42;
87 }
88
89 /**
90  * \brief Reads and parses the boot configuration script
91  * \param Filename      File to parse and execute
92  */
93 void ExecuteScript(const char *Filename)
94 {
95         /*
96         tSpiderScript   *script;
97         script = SpiderScript_ParseFile(&gScriptVariant, Filename);
98         SpiderScript_ExecuteMethod(script, "");
99         SpiderScript_Free(script);
100         */
101 }
102
103 /**
104  * \brief Open a file
105  */
106 /*
107 tSpiderVariable *Script_System_IO_Open(tSpiderScript *Script, int NArgs, tSpiderVariable *Args)
108 {
109         return NULL;
110 }
111 */

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