Put X11 and EGL into the kernel leaving ES 2.0 only in driver
[cilux] / src / platform / linux / cilux.c
1
2 /* -------------------------------------------------------------------------- */
3
4 #include <kernelplat.h>
5 #include <container.h>
6 #include <version.h>
7
8 /* -------------------------------------------------------------------------- */
9
10 static void cilux_terminate(void);
11 static void re_exec_as_other();
12
13 /* -------------------------------------------------------------------------- */
14
15 int main(int argc, char* argv[])
16 {
17     c_init(cilux_version, cilux_ciux, cilux_terminate);
18
19     re_exec_as_other();
20     c_run(0);
21
22     return 0;
23 }
24
25 /* -------------------------------------------------------------------------- */
26
27 void re_exec_as_other()
28 {
29     char* other="other";
30     uid_t uid=0;
31     gid_t gid=0;
32     if(getuid()==0){
33         struct passwd* pw=getpwnam(other);
34         if(!pw){ printf("fail: getpwnam(\"%s\");\n", other); exit(1); }
35         uid=pw->pw_uid;
36         gid=pw->pw_gid;
37     }
38
39     pid_t pid=fork();
40     switch(pid){
41         case 0:
42             break;
43         case -1:
44             printf("Failed to fork\n");
45             exit(1);
46         default:
47             printf("pid %d\n", pid);
48             exit(0);
49     }
50     setsid();
51
52     if(getuid()==0){
53         if(setgroups(0,0)== -1){
54             printf("fail: setgroups(0,0)\n");
55             exit(1);
56         }
57         if(setgid(gid)== -1){
58             printf("fail: setgid(%d)\n", gid);
59             exit(1);
60         }
61         if(initgroups(other, gid)== -1){
62             printf("fail: initgroups(\"%s\",%d)\n", other, gid);
63             exit(1);
64         }
65         if(setuid(uid)== -1){
66             printf("fail: setuid(%d)\n", uid);
67             exit(1);
68         }
69     }
70 }
71
72 void cilux_terminate(void)
73 {
74     c_running(0);
75     exit(0);
76 }
77
78 /* -------------------------------------------------------------------------- */
79
80