toaruos/userspace/init.c
Kevin Lange 07955c83c6 Fix dozens of build warnings and other oddities.
* Finally bring syscall.h up to speed and include all syscalls in the
  syscall module of the C library.
* Remove the third-party obfuscated C demos (we have nyancat, good
  enough)
* Fix userspace apps to build without complaining about undeclared
  strtok_r by disable __STRICT_ANSI__
* Fix .eh_frame by including the proper stuff with libgcc.
2012-09-04 20:27:49 -07:00

99 lines
1.7 KiB
C

/* vim: tabstop=4 shiftwidth=4 noexpandtab
*
* init
*
* Provides the standard boot routines and
* calls the user session (compositor / terminal)
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#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);
if (buf[strlen(buf)-1] == '\n') {
buf[strlen(buf)-1] = '\0';
}
syscall_sethostname(buf);
fclose(_host_file);
}
}
void start_terminal(char * arg) {
int pid = fork();
if (!pid) {
char * tokens[] = {
"/bin/terminal",
"-F",
arg,
NULL
};
int i = execve(tokens[0], tokens, NULL);
exit(0);
} else {
syscall_wait(pid);
}
}
void start_vga_terminal(char * arg) {
int pid = fork();
if (!pid) {
char * tokens[] = {
"/bin/terminal",
"-Vl",
arg,
NULL
};
int i = execve(tokens[0], tokens, NULL);
exit(0);
} else {
syscall_wait(pid);
}
}
void start_compositor() {
int pid = fork();
if (!pid) {
char * tokens[] = {
"/bin/compositor",
NULL
};
int i = execve(tokens[0], tokens, NULL);
exit(0);
} else {
syscall_wait(pid);
}
}
int main(int argc, char * argv[]) {
/* Hostname */
set_hostname();
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;
}
}
start_compositor();
}