2012-01-30 22:10:53 +04:00
|
|
|
/* vim: tabstop=4 shiftwidth=4 noexpandtab
|
|
|
|
*
|
2012-07-07 08:08:28 +04:00
|
|
|
* init
|
|
|
|
*
|
|
|
|
* Provides the standard boot routines and
|
|
|
|
* calls the user session (compositor / terminal)
|
2012-01-30 22:10:53 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2012-01-30 22:13:11 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
2012-01-30 22:10:53 +04:00
|
|
|
#include <syscall.h>
|
|
|
|
|
|
|
|
#define DEFAULT_HOSTNAME "toaru-test"
|
|
|
|
|
|
|
|
/* Set the hostname to whatever is in /etc/hostname */
|
|
|
|
void set_hostname() {
|
|
|
|
FILE * _host_file = fopen("/etc/hostname", "r");
|
|
|
|
if (!_host_file) {
|
|
|
|
/* No /etc/hostname, use the default */
|
|
|
|
syscall_sethostname(DEFAULT_HOSTNAME);
|
|
|
|
} else {
|
|
|
|
char buf[256];
|
|
|
|
fgets(buf, 255, _host_file);
|
2012-01-30 22:13:11 +04:00
|
|
|
if (buf[strlen(buf)-1] == '\n') {
|
|
|
|
buf[strlen(buf)-1] = '\0';
|
|
|
|
}
|
2012-01-30 22:10:53 +04:00
|
|
|
syscall_sethostname(buf);
|
2012-10-08 11:17:50 +04:00
|
|
|
setenv("HOST", buf, 1);
|
2012-01-30 22:10:53 +04:00
|
|
|
fclose(_host_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-02 13:24:25 +04:00
|
|
|
void start_terminal(char * arg) {
|
2012-01-30 22:10:53 +04:00
|
|
|
int pid = fork();
|
|
|
|
if (!pid) {
|
2012-03-24 02:44:37 +04:00
|
|
|
char * tokens[] = {
|
2013-06-28 11:42:40 +04:00
|
|
|
"/bin/compositor",
|
2012-03-24 02:44:37 +04:00
|
|
|
"/bin/terminal",
|
2013-03-28 11:12:48 +04:00
|
|
|
"-Fl",
|
2012-09-02 13:24:25 +04:00
|
|
|
arg,
|
2012-03-24 02:44:37 +04:00
|
|
|
NULL
|
|
|
|
};
|
2012-10-08 11:17:50 +04:00
|
|
|
int i = execvp(tokens[0], tokens);
|
2012-03-28 06:47:25 +04:00
|
|
|
exit(0);
|
|
|
|
} else {
|
|
|
|
syscall_wait(pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-18 11:06:32 +04:00
|
|
|
void start_terminal_no_freetype(char * arg) {
|
|
|
|
int pid = fork();
|
|
|
|
if (!pid) {
|
|
|
|
char * tokens[] = {
|
2013-06-28 11:42:40 +04:00
|
|
|
"/bin/compositor",
|
2012-09-18 11:06:32 +04:00
|
|
|
"/bin/terminal",
|
2013-03-28 11:12:48 +04:00
|
|
|
"-Fklb",
|
2012-09-18 11:06:32 +04:00
|
|
|
arg,
|
|
|
|
NULL
|
|
|
|
};
|
2012-10-08 11:17:50 +04:00
|
|
|
int i = execv(tokens[0], tokens);
|
2012-09-18 11:06:32 +04:00
|
|
|
exit(0);
|
|
|
|
} else {
|
|
|
|
syscall_wait(pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-02 13:24:25 +04:00
|
|
|
void start_vga_terminal(char * arg) {
|
2012-04-11 08:35:12 +04:00
|
|
|
int pid = fork();
|
|
|
|
if (!pid) {
|
|
|
|
char * tokens[] = {
|
2013-06-29 06:02:11 +04:00
|
|
|
"/bin/vga-warning",
|
2012-09-02 13:24:25 +04:00
|
|
|
arg,
|
2012-04-11 08:35:12 +04:00
|
|
|
NULL
|
|
|
|
};
|
2012-10-08 11:17:50 +04:00
|
|
|
int i = execvp(tokens[0], tokens);
|
2012-04-11 08:35:12 +04:00
|
|
|
exit(0);
|
|
|
|
} else {
|
|
|
|
syscall_wait(pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-28 06:47:25 +04:00
|
|
|
void start_compositor() {
|
|
|
|
int pid = fork();
|
|
|
|
if (!pid) {
|
2012-11-18 00:59:18 +04:00
|
|
|
char * _tokens[] = {
|
2012-11-18 00:57:00 +04:00
|
|
|
"/bin/compositor",
|
2012-03-24 02:44:37 +04:00
|
|
|
NULL
|
|
|
|
};
|
2012-11-18 00:59:18 +04:00
|
|
|
execvp(_tokens[0], _tokens);
|
|
|
|
|
2012-03-24 02:44:37 +04:00
|
|
|
exit(0);
|
2012-02-13 02:45:23 +04:00
|
|
|
} else {
|
|
|
|
syscall_wait(pid);
|
2012-01-30 22:10:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-28 06:47:25 +04:00
|
|
|
|
2012-09-02 13:24:25 +04:00
|
|
|
int main(int argc, char * argv[]) {
|
2012-01-30 22:10:53 +04:00
|
|
|
/* Hostname */
|
|
|
|
set_hostname();
|
2012-09-02 13:24:25 +04:00
|
|
|
if (argc > 1) {
|
|
|
|
char * args = NULL;
|
|
|
|
if (argc > 2) {
|
|
|
|
args = argv[2];
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[1],"--single")) {
|
|
|
|
start_terminal(args);
|
|
|
|
return 0;
|
|
|
|
} else if (!strcmp(argv[1], "--vga")) {
|
|
|
|
start_vga_terminal(args);
|
|
|
|
return 0;
|
2012-09-18 11:06:32 +04:00
|
|
|
} else if (!strcmp(argv[1], "--special")) {
|
|
|
|
start_terminal_no_freetype(args);
|
|
|
|
return 0;
|
2012-09-02 13:24:25 +04:00
|
|
|
}
|
2012-03-28 06:47:25 +04:00
|
|
|
}
|
2012-09-02 13:24:25 +04:00
|
|
|
start_compositor();
|
2012-01-30 22:10:53 +04:00
|
|
|
}
|