mirror of
https://github.com/troglobit/finit.git
synced 2026-11-19 19:40:50 +00:00
Refactor run_getty() and run_getty2() into one
By moving the built-in getty to a stand-alone bundled getty we can now refactor the old run_getty() functions into a single one. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
a319e32438
commit
5404aa6037
5 files changed
+11
-43
No files matched your search
+1
-29
@@ -345,35 +345,7 @@ static int activate_console(int noclear, int nowait)
|
|||||||
* since /bin/login usually only disables ECHO until a password line has
|
* since /bin/login usually only disables ECHO until a password line has
|
||||||
* been entered. Upon starting the user's $SHELL the ISIG flag is reset
|
* been entered. Upon starting the user's $SHELL the ISIG flag is reset
|
||||||
*/
|
*/
|
||||||
pid_t run_getty(char *tty, char *baud, char *term, int noclear, int nowait, struct rlimit rlimit[])
|
pid_t run_getty(char *tty, char *cmd, char *args[], int noclear, int nowait, struct rlimit rlimit[])
|
||||||
{
|
|
||||||
speed_t speed;
|
|
||||||
int rc = 1;
|
|
||||||
|
|
||||||
speed = stty_parse_speed(baud);
|
|
||||||
prepare_tty(tty, speed, "tty", rlimit);
|
|
||||||
if (activate_console(noclear, nowait)) {
|
|
||||||
char spd[15];
|
|
||||||
char *args[5] = {
|
|
||||||
"getty",
|
|
||||||
tty,
|
|
||||||
spd,
|
|
||||||
term,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
snprintf(spd, sizeof(spd), "%d", speed);
|
|
||||||
logit(LOG_ERR, "Starting built-in getty on %s, speed %u", tty, speed);
|
|
||||||
rc = execv("/libexec/finit/getty", args);
|
|
||||||
}
|
|
||||||
logit(LOG_ERR, "Failed starting built-in getty on %s, speed %u", tty, speed);
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Start external getty as defined by user in .conf file
|
|
||||||
*/
|
|
||||||
pid_t run_getty2(char *tty, char *cmd, char *args[], int noclear, int nowait, struct rlimit rlimit[])
|
|
||||||
{
|
{
|
||||||
int rc = 1;
|
int rc = 1;
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
|
|
||||||
#define _PATH_LOGIT FINIT_LIBPATH_ "/logit"
|
#define _PATH_LOGIT FINIT_LIBPATH_ "/logit"
|
||||||
#define _PATH_SULOGIN FINIT_LIBPATH_ "/sulogin"
|
#define _PATH_SULOGIN FINIT_LIBPATH_ "/sulogin"
|
||||||
|
#define _PATH_GETTY FINIT_LIBPATH_ "/getty"
|
||||||
|
|
||||||
#define CMD_SIZE 256
|
#define CMD_SIZE 256
|
||||||
#define LINE_SIZE 1024
|
#define LINE_SIZE 1024
|
||||||
|
|||||||
+1
-2
@@ -92,8 +92,7 @@ int complete (char *cmd, int pid);
|
|||||||
int run (char *cmd);
|
int run (char *cmd);
|
||||||
int run_interactive (char *cmd, char *fmt, ...);
|
int run_interactive (char *cmd, char *fmt, ...);
|
||||||
int exec_runtask (char *cmd, char *args[]);
|
int exec_runtask (char *cmd, char *args[]);
|
||||||
pid_t run_getty (char *tty, char *baud, char *term, int noclear, int nowait, struct rlimit rlimit[]);
|
pid_t run_getty (char *tty, char *cmd, char *args[], int noclear, int nowait, struct rlimit rlimit[]);
|
||||||
pid_t run_getty2 (char *tty, char *cmd, char *args[], int noclear, int nowait, struct rlimit rlimit[]);
|
|
||||||
pid_t run_sh (char *tty, int noclear, int nowait, struct rlimit rlimit[]);
|
pid_t run_sh (char *tty, int noclear, int nowait, struct rlimit rlimit[]);
|
||||||
int run_parts (char *dir, char *cmd);
|
int run_parts (char *dir, char *cmd);
|
||||||
|
|
||||||
|
|||||||
+2
-7
@@ -1220,12 +1220,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
if (tty_parse_args(cmd, &tty))
|
if (tty_parse_args(cmd, &tty))
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
if (tty.cmd)
|
len += strlen(tty.cmd) + tty.num + 1;
|
||||||
len += strlen(tty.cmd);
|
|
||||||
else
|
|
||||||
len += 3;
|
|
||||||
|
|
||||||
len += tty.num + 1;
|
|
||||||
for (i = 0; i < tty.num; i++)
|
for (i = 0; i < tty.num; i++)
|
||||||
len += strlen(tty.args[i]) + 1;
|
len += strlen(tty.args[i]) + 1;
|
||||||
|
|
||||||
@@ -1233,7 +1228,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
if (!line)
|
if (!line)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
snprintf(line, len, "%s", tty.cmd ?: "tty");
|
snprintf(line, len, "%s", tty.cmd);
|
||||||
for (i = 0; i < tty.num; i++) {
|
for (i = 0; i < tty.num; i++) {
|
||||||
strlcat(line, " ", len);
|
strlcat(line, " ", len);
|
||||||
strlcat(line, tty.args[i], len);
|
strlcat(line, tty.args[i], len);
|
||||||
|
|||||||
@@ -221,6 +221,10 @@ int tty_parse_args(char *cmd, struct tty *tty)
|
|||||||
_d("Registering %s getty on TTY %s at %s baud with term %s", tty->cmd ? "external" : "built-in",
|
_d("Registering %s getty on TTY %s at %s baud with term %s", tty->cmd ? "external" : "built-in",
|
||||||
tty->dev, tty->baud ?: "0", tty->term ?: "N/A");
|
tty->dev, tty->baud ?: "0", tty->term ?: "N/A");
|
||||||
|
|
||||||
|
/* Built-in getty now comes as standalone program */
|
||||||
|
if (!tty->cmd)
|
||||||
|
tty->cmd = _PATH_GETTY;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,10 +289,7 @@ int tty_exec(svc_t *svc)
|
|||||||
return run_sh(dev, svc->noclear, svc->nowait, svc->rlimit);
|
return run_sh(dev, svc->noclear, svc->nowait, svc->rlimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
_d("%s: Starting %sgetty ...", dev, !svc->cmd ? "built-in " : "");
|
_d("%s: Starting %s ...", dev, svc->cmd);
|
||||||
if (!strcmp(svc->cmd, "tty"))
|
|
||||||
return run_getty(dev, svc->baud, svc->term, svc->noclear, svc->nowait, svc->rlimit);
|
|
||||||
|
|
||||||
for (i = 1, j = 0; i < MAX_NUM_SVC_ARGS; i++) {
|
for (i = 1, j = 0; i < MAX_NUM_SVC_ARGS; i++) {
|
||||||
if (!svc->args[i][0])
|
if (!svc->args[i][0])
|
||||||
break;
|
break;
|
||||||
@@ -297,7 +298,7 @@ int tty_exec(svc_t *svc)
|
|||||||
}
|
}
|
||||||
args[j++] = NULL;
|
args[j++] = NULL;
|
||||||
|
|
||||||
return run_getty2(dev, svc->cmd, args, svc->noclear, svc->nowait, svc->rlimit);
|
return run_getty(dev, svc->cmd, args, svc->noclear, svc->nowait, svc->rlimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user