mirror of
https://github.com/troglobit/finit.git
synced 2026-10-27 12:20:54 +00:00
Move fork() of console to run_getty() and remove startx conf option
New function helpers.c:run_getty() refactored from main(). Used to start a default console getty. Removed startx finit.conf option, superseded by service statement, see examples/finit.conf for a working use case. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
dfa0fe6428
commit
75eb5cc043
6 files changed
+70
-73
No files matched your search
@@ -122,11 +122,6 @@ void parse_finit_conf(char *file)
|
|||||||
network = build_cmd(NULL, x, CMD_SIZE);
|
network = build_cmd(NULL, x, CMD_SIZE);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (MATCH_CMD(line, "startx ", x)) {
|
|
||||||
if (startx) free(startx);
|
|
||||||
startx = build_cmd(NULL, x, CMD_SIZE);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (MATCH_CMD(line, "service ", x)) {
|
if (MATCH_CMD(line, "service ", x)) {
|
||||||
if (svc_register(x))
|
if (svc_register(x))
|
||||||
_e("Failed, too many services to monitor.\n");
|
_e("Failed, too many services to monitor.\n");
|
||||||
|
|||||||
+1
-1
@@ -10,4 +10,4 @@ network service networking start
|
|||||||
service /sbin/klogd -n -- Kernel logging server
|
service /sbin/klogd -n -- Kernel logging server
|
||||||
service /sbin/syslogd -n -- Syslog server
|
service /sbin/syslogd -n -- Syslog server
|
||||||
service /usr/sbin/sshd -D -- OpenSSH server
|
service /usr/sbin/sshd -D -- OpenSSH server
|
||||||
startx startx
|
service /usr/bin/startx -- X Window System
|
||||||
@@ -38,7 +38,6 @@ int debug = 0;
|
|||||||
int verbose = 1;
|
int verbose = 1;
|
||||||
char *sdown = NULL;
|
char *sdown = NULL;
|
||||||
char *network = NULL;
|
char *network = NULL;
|
||||||
char *startx = NULL;
|
|
||||||
char *username = NULL;
|
char *username = NULL;
|
||||||
char *hostname = NULL;
|
char *hostname = NULL;
|
||||||
|
|
||||||
@@ -165,81 +164,25 @@ int main(int UNUSED(args), char *argv[])
|
|||||||
_d("Starting all static services from %s", FINIT_CONF);
|
_d("Starting all static services from %s", FINIT_CONF);
|
||||||
svc_start_all();
|
svc_start_all();
|
||||||
|
|
||||||
/* Run startup scripts in /etc/finit.d/, if any. */
|
/*
|
||||||
|
* Run startup scripts in /etc/finit.d/, if any.
|
||||||
|
*/
|
||||||
|
_d("Running startup scripts in /etc/finit.d/ ...");
|
||||||
run_parts(FINIT_RCSD);
|
run_parts(FINIT_RCSD);
|
||||||
|
|
||||||
if (!fork()) {
|
|
||||||
/* child process */
|
|
||||||
int i;
|
|
||||||
char c;
|
|
||||||
sigset_t nmask;
|
|
||||||
struct sigaction sa;
|
|
||||||
|
|
||||||
vhangup();
|
|
||||||
|
|
||||||
close(2);
|
|
||||||
close(1);
|
|
||||||
close(0);
|
|
||||||
|
|
||||||
if (open(CONSOLE, O_RDWR) != 0)
|
|
||||||
exit(1);
|
|
||||||
|
|
||||||
sigemptyset(&sa.sa_mask);
|
|
||||||
sa.sa_handler = SIG_DFL;
|
|
||||||
|
|
||||||
sigemptyset(&nmask);
|
|
||||||
sigaddset(&nmask, SIGCHLD);
|
|
||||||
sigprocmask(SIG_UNBLOCK, &nmask, NULL);
|
|
||||||
|
|
||||||
for (i = 1; i < NSIG; i++)
|
|
||||||
sigaction(i, &sa, NULL);
|
|
||||||
|
|
||||||
dup2(0, STDIN_FILENO);
|
|
||||||
dup2(0, STDOUT_FILENO);
|
|
||||||
dup2(0, STDERR_FILENO);
|
|
||||||
|
|
||||||
set_procname(argv, "console");
|
|
||||||
|
|
||||||
/* ConsoleKit needs this */
|
|
||||||
setenv("DISPLAY", ":0", 1);
|
|
||||||
|
|
||||||
while (!fexist(SYNC_SHUTDOWN)) {
|
|
||||||
char line[LINE_SIZE];
|
|
||||||
|
|
||||||
if (fexist(SYNC_STOPPED)) {
|
|
||||||
sleep(1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startx && !debug) {
|
|
||||||
echo("Starting X ...");
|
|
||||||
snprintf(line, sizeof(line), "su -c '%s' -l %s", startx, username);
|
|
||||||
system(line);
|
|
||||||
} else {
|
|
||||||
static const char msg[] = "\nPlease press Enter to activate this console. ";
|
|
||||||
|
|
||||||
i = write(STDERR_FILENO, msg, sizeof(msg) - 1);
|
|
||||||
while (read(STDIN_FILENO, &c, 1) == 1 && c != '\n')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (fexist(SYNC_STOPPED))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
run(GETTY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hooks that should run at the very end
|
* Hooks that should run at the very end
|
||||||
*/
|
*/
|
||||||
run_hooks(HOOK_SYSTEM_UP);
|
run_hooks(HOOK_SYSTEM_UP);
|
||||||
|
|
||||||
|
/* Start GETTY on console */
|
||||||
|
_d("Starting getty on console ...");
|
||||||
|
run_getty(GETTY, argv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enter main loop to monior /dev/initctl and services
|
* Enter main loop to monior /dev/initctl and services
|
||||||
*/
|
*/
|
||||||
|
_d("Entering main loop ...");
|
||||||
ev_run(loop, 0);
|
ev_run(loop, 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ extern int debug;
|
|||||||
extern int verbose;
|
extern int verbose;
|
||||||
extern char *sdown;
|
extern char *sdown;
|
||||||
extern char *network;
|
extern char *network;
|
||||||
extern char *startx;
|
|
||||||
extern char *hostname;
|
extern char *hostname;
|
||||||
extern char *username;
|
extern char *username;
|
||||||
|
|
||||||
|
|||||||
@@ -343,6 +343,65 @@ int run_interactive(char *cmd, char *fmt, ...)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid_t run_getty(char *cmd, char *argv[])
|
||||||
|
{
|
||||||
|
pid_t pid = fork();
|
||||||
|
|
||||||
|
if (!pid) {
|
||||||
|
int i;
|
||||||
|
char c;
|
||||||
|
sigset_t nmask;
|
||||||
|
struct sigaction sa;
|
||||||
|
|
||||||
|
vhangup();
|
||||||
|
|
||||||
|
close(2);
|
||||||
|
close(1);
|
||||||
|
close(0);
|
||||||
|
|
||||||
|
if (open(CONSOLE, O_RDWR) != 0)
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sa.sa_handler = SIG_DFL;
|
||||||
|
|
||||||
|
sigemptyset(&nmask);
|
||||||
|
sigaddset(&nmask, SIGCHLD);
|
||||||
|
sigprocmask(SIG_UNBLOCK, &nmask, NULL);
|
||||||
|
|
||||||
|
for (i = 1; i < NSIG; i++)
|
||||||
|
sigaction(i, &sa, NULL);
|
||||||
|
|
||||||
|
dup2(0, STDIN_FILENO);
|
||||||
|
dup2(0, STDOUT_FILENO);
|
||||||
|
dup2(0, STDERR_FILENO);
|
||||||
|
|
||||||
|
set_procname(argv, "console");
|
||||||
|
|
||||||
|
while (!fexist(SYNC_SHUTDOWN)) {
|
||||||
|
static const char msg[] = "\nPlease press Enter to activate this console. ";
|
||||||
|
|
||||||
|
if (fexist(SYNC_STOPPED)) {
|
||||||
|
sleep(1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = write(STDERR_FILENO, msg, sizeof(msg) - 1);
|
||||||
|
while (read(STDIN_FILENO, &c, 1) == 1 && c != '\n')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (fexist(SYNC_STOPPED))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
run(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
|
||||||
static int cmp(const void *s1, const void *s2)
|
static int cmp(const void *s1, const void *s2)
|
||||||
{
|
{
|
||||||
return strcmp(*(char **)s1, *(char **)s2);
|
return strcmp(*(char **)s1, *(char **)s2);
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ void set_hostname (char *hostname);
|
|||||||
|
|
||||||
int run (char *cmd);
|
int run (char *cmd);
|
||||||
int run_interactive (char *cmd, char *fmt, ...);
|
int run_interactive (char *cmd, char *fmt, ...);
|
||||||
|
pid_t run_getty (char *cmd, char *argv[]);
|
||||||
int run_parts (char *dir, ...);
|
int run_parts (char *dir, ...);
|
||||||
|
|
||||||
#endif /* FINIT_HELPERS_H_ */
|
#endif /* FINIT_HELPERS_H_ */
|
||||||
|
|||||||
Reference in new issue
Block a user