diff options
author | Renato Botelho <renato@netgate.com> | 2018-05-18 14:53:44 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2018-05-18 14:53:44 -0300 |
commit | 64f021cd075bbcb3042539dcebc63e7d335ec2c0 (patch) | |
tree | 1a64375406a7b5976f98eaf4cf19f00cf2931dd1 /lib/libc/gen/getttyent.c | |
parent | 8f29f1de284afe0ec8987780d5404a3e1a31712a (diff) | |
parent | eb64daea863b1fe3320e10c6c72cbfe7e9ce967b (diff) | |
download | FreeBSD-src-64f021cd075bbcb3042539dcebc63e7d335ec2c0.zip FreeBSD-src-64f021cd075bbcb3042539dcebc63e7d335ec2c0.tar.gz |
Merge remote-tracking branch 'origin/stable/11' into devel-11
Diffstat (limited to 'lib/libc/gen/getttyent.c')
-rw-r--r-- | lib/libc/gen/getttyent.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/lib/libc/gen/getttyent.c b/lib/libc/gen/getttyent.c index 266f631..e0b2698 100644 --- a/lib/libc/gen/getttyent.c +++ b/lib/libc/gen/getttyent.c @@ -34,6 +34,7 @@ static char sccsid[] = "@(#)getttyent.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD$"); #include <sys/types.h> +#include <sys/stat.h> #include <sys/sysctl.h> #include <ctype.h> @@ -72,11 +73,14 @@ auto_tty_status(const char *ty_name) { size_t len; char *buf, *cons, *nextcons; + int rv; + + rv = TTY_IFCONSOLE; /* Check if this is an enabled kernel console line */ buf = NULL; if (sysctlbyname("kern.console", NULL, &len, NULL, 0) == -1) - return (0); /* Errors mean don't enable */ + return (rv); /* Errors mean don't enable */ buf = malloc(len); if (sysctlbyname("kern.console", buf, &len, NULL, 0) == -1) goto done; @@ -87,14 +91,32 @@ auto_tty_status(const char *ty_name) nextcons = buf; while ((cons = strsep(&nextcons, ",")) != NULL && strlen(cons) != 0) { if (strcmp(cons, ty_name) == 0) { - free(buf); - return (TTY_ON); + rv |= TTY_ON; + break; } } done: free(buf); - return (0); + return (rv); +} + +static int +auto_exists_status(const char *ty_name) +{ + struct stat sb; + char *dev; + int rv; + + rv = TTY_IFEXISTS; + if (*ty_name == '/') + asprintf(&dev, "%s", ty_name); + else + asprintf(&dev, "/dev/%s", ty_name); + if (dev != NULL && stat(dev, &sb) == 0) + rv |= TTY_ON; + free(dev); + return (rv); } struct ttyent * @@ -161,6 +183,8 @@ getttyent(void) tty.ty_status |= TTY_ON; else if (scmp(_TTYS_ONIFCONSOLE)) tty.ty_status |= auto_tty_status(tty.ty_name); + else if (scmp(_TTYS_ONIFEXISTS)) + tty.ty_status |= auto_exists_status(tty.ty_name); else if (scmp(_TTYS_SECURE)) tty.ty_status |= TTY_SECURE; else if (scmp(_TTYS_INSECURE)) |