toaruos/userspace/init.c

59 lines
1.1 KiB
C
Raw Normal View History

2012-01-30 22:10:53 +04:00
/* vim: tabstop=4 shiftwidth=4 noexpandtab
*
* Initial Startup
*/
#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>
DEFN_SYSCALL1(sethostname, 31, char *);
#define DEFAULT_HOSTNAME "toaru-test"
2012-02-13 02:45:23 +04:00
#define FORK_FOR_TERMINAL 1
2012-01-30 22:10:53 +04:00
/* 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);
fclose(_host_file);
}
}
void start_terminal() {
#if FORK_FOR_TERMINAL
int pid = fork();
if (!pid) {
#endif
char * tokens[] = {
2012-02-17 00:31:40 +04:00
"/bin/compositor",
2012-01-30 22:10:53 +04:00
NULL
};
int i = execve(tokens[0], tokens, NULL);
exit(0);
2012-02-13 02:45:23 +04:00
#if FORK_FOR_TERMINAL
} else {
syscall_wait(pid);
2012-01-30 22:10:53 +04:00
}
#endif
}
void main(int argc, char * argv[]) {
2012-02-13 02:45:23 +04:00
fprintf(stderr, "[init] Hello world.\n");
2012-01-30 22:10:53 +04:00
/* Hostname */
set_hostname();
/* Terminal */
start_terminal();
}