summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
Diffstat (limited to 'sbin')
-rw-r--r--sbin/init/init.c50
-rw-r--r--sbin/ipfw/ipfw2.c6
2 files changed, 39 insertions, 17 deletions
diff --git a/sbin/init/init.c b/sbin/init/init.c
index f4206c4..12cf9a7 100644
--- a/sbin/init/init.c
+++ b/sbin/init/init.c
@@ -154,6 +154,8 @@ typedef struct init_session {
int se_flags; /* status of session */
#define SE_SHUTDOWN 0x1 /* session won't be restarted */
#define SE_PRESENT 0x2 /* session is in /etc/ttys */
+#define SE_IFEXISTS 0x4 /* session defined as "onifexists" */
+#define SE_IFCONSOLE 0x8 /* session defined as "onifconsole" */
int se_nspace; /* spacing count */
char *se_device; /* filename of port */
char *se_getty; /* what to run on that port */
@@ -1260,7 +1262,6 @@ static session_t *
new_session(session_t *sprev, struct ttyent *typ)
{
session_t *sp;
- int fd;
if ((typ->ty_status & TTY_ON) == 0 ||
typ->ty_name == 0 ||
@@ -1271,21 +1272,15 @@ new_session(session_t *sprev, struct ttyent *typ)
sp->se_flags |= SE_PRESENT;
+ if ((typ->ty_status & TTY_IFEXISTS) != 0)
+ sp->se_flags |= SE_IFEXISTS;
+
+ if ((typ->ty_status & TTY_IFCONSOLE) != 0)
+ sp->se_flags |= SE_IFCONSOLE;
+
if (asprintf(&sp->se_device, "%s%s", _PATH_DEV, typ->ty_name) < 0)
err(1, "asprintf");
- /*
- * Attempt to open the device, if we get "device not configured"
- * then don't add the device to the session list.
- */
- if ((fd = open(sp->se_device, O_RDONLY | O_NONBLOCK, 0)) < 0) {
- if (errno == ENXIO) {
- free_session(sp);
- return (0);
- }
- } else
- close(fd);
-
if (setupargv(sp, typ) == 0) {
free_session(sp);
return (0);
@@ -1505,6 +1500,30 @@ start_getty(session_t *sp)
}
/*
+ * Return 1 if the session is defined as "onifexists"
+ * or "onifconsole" and the device node does not exist.
+ */
+static int
+session_has_no_tty(session_t *sp)
+{
+ int fd;
+
+ if ((sp->se_flags & SE_IFEXISTS) == 0 &&
+ (sp->se_flags & SE_IFCONSOLE) == 0)
+ return (0);
+
+ fd = open(sp->se_device, O_RDONLY | O_NONBLOCK, 0);
+ if (fd < 0) {
+ if (errno == ENOENT)
+ return (1);
+ return (0);
+ }
+
+ close(fd);
+ return (0);
+}
+
+/*
* Collect exit status for a child.
* If an exiting login, start a new login running.
*/
@@ -1522,7 +1541,8 @@ collect_child(pid_t pid)
del_session(sp);
sp->se_process = 0;
- if (sp->se_flags & SE_SHUTDOWN) {
+ if (sp->se_flags & SE_SHUTDOWN ||
+ session_has_no_tty(sp)) {
if ((sprev = sp->se_prev) != NULL)
sprev->se_next = sp->se_next;
else
@@ -1608,6 +1628,8 @@ multi_user(void)
for (sp = sessions; sp; sp = sp->se_next) {
if (sp->se_process)
continue;
+ if (session_has_no_tty(sp))
+ continue;
if ((pid = start_getty(sp)) == -1) {
/* serious trouble */
requested_transition = clean_ttys;
diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c
index 4f4a925..0c51845 100644
--- a/sbin/ipfw/ipfw2.c
+++ b/sbin/ipfw/ipfw2.c
@@ -1724,7 +1724,7 @@ print_instruction(struct buf_pr *bp, const struct format_opts *fo,
static ipfw_insn *
print_opcode(struct buf_pr *bp, struct format_opts *fo,
- struct show_state *state, uint8_t opcode)
+ struct show_state *state, int opcode)
{
ipfw_insn *cmd;
int l;
@@ -1732,7 +1732,7 @@ print_opcode(struct buf_pr *bp, struct format_opts *fo,
for (l = state->rule->act_ofs, cmd = state->rule->cmd;
l > 0; l -= F_LEN(cmd), cmd += F_LEN(cmd)) {
/* We use zero opcode to print the rest of options */
- if (opcode != 0 && cmd->opcode != opcode)
+ if (opcode >= 0 && cmd->opcode != opcode)
continue;
/*
* Skip O_NOP, when we printing the rest
@@ -2208,7 +2208,7 @@ show_static_rule(struct cmdline_opts *co, struct format_opts *fo,
O_IP_DSTPORT, HAVE_DSTIP);
/* Print the rest of options */
- while (print_opcode(bp, fo, &state, 0))
+ while (print_opcode(bp, fo, &state, -1))
;
end:
/* Print comment at the end */
OpenPOWER on IntegriCloud