Restore tty plugin after tty refactor

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2021-04-15 09:02:28 +02:00
1 parent 4f40b65f0c
commit eaeddc36c2
2 files changed
+26 -12

No files matched your search

+16 -12
View File
@@ -32,13 +32,14 @@
#include "finit.h" #include "finit.h"
#include "helpers.h" #include "helpers.h"
#include "plugin.h" #include "plugin.h"
#include "service.h"
#include "tty.h" #include "tty.h"
static void watcher(void *arg, int fd, int events); static void tty_watcher(void *arg, int fd, int events);
static plugin_t plugin = { static plugin_t plugin = {
.io = { .io = {
.cb = watcher, .cb = tty_watcher,
.flags = PLUGIN_IO_READ, .flags = PLUGIN_IO_READ,
}, },
}; };
@@ -55,22 +56,25 @@ static void setup(void)
static void do_tty(char *tty, size_t len, int creat) static void do_tty(char *tty, size_t len, int creat)
{ {
#if 0
char name[len + 6]; char name[len + 6];
svc_t *entry; svc_t *svc;
snprintf(name, sizeof(name), "/dev/%s", tty); snprintf(name, sizeof(name), "/dev/%s", tty);
entry = svc_find_by_tty(name); svc = svc_find_by_tty(name);
if (entry && tty_enabled(entry)) { if (svc) {
if (creat) if (svc_is_blocked(svc) && creat) {
tty_start(entry); _d("%s: blocked, re-enabling", svc_ident(svc, NULL, 0));
else if (entry->pid) svc_start(svc);
tty_stop(entry); } else if (svc->pid) {
_d("%s: missing ...", svc_ident(svc, NULL, 0));
svc_missing(svc);
}
service_step_all(SVC_TYPE_TTY);
} }
#endif
} }
static void watcher(void *arg, int fd, int events) static void tty_watcher(void *arg, int fd, int events)
{ {
static char ev_buf[8 *(sizeof(struct inotify_event) + NAME_MAX + 1) + 1]; static char ev_buf[8 *(sizeof(struct inotify_event) + NAME_MAX + 1) + 1];
struct inotify_event *ev; struct inotify_event *ev;
+10
View File
@@ -412,6 +412,16 @@ static int service_start(svc_t *svc)
return 1; return 1;
} }
if (svc_is_tty(svc)) {
char *dev = tty_canonicalize(svc->dev);
if (!dev || !tty_exists(dev)) {
_d("TTY %s missing or invalid, halting service.", svc->dev);
svc_missing(svc);
return 1;
}
}
if (svc_is_sysv(svc)) if (svc_is_sysv(svc))
logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s start' ...", svc->cmd); logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s start' ...", svc->cmd);