X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=util.c;h=f9eae6bba1e8818b7d56c8174664f33626975c7c;hb=601f6a1e820462b1df6ff632d112bef241d556b1;hp=52ca5e25631a9e56f8fd5e27df7c63d777b6d50a;hpb=8b6c71206d32b11683e5e7cebc9acb467ba01b38;p=elogind.git diff --git a/util.c b/util.c index 52ca5e256..f9eae6bba 100644 --- a/util.c +++ b/util.c @@ -34,6 +34,9 @@ #include #include #include +#include +#include +#include #include "macro.h" #include "util.h" @@ -1276,6 +1279,49 @@ char *format_timestamp(char *buf, size_t l, usec_t t) { return buf; } +bool fstype_is_network(const char *fstype) { + static const char * const table[] = { + "cifs", + "smbfs", + "ncpfs", + "nfs", + "nfs4" + }; + + unsigned i; + + for (i = 0; i < ELEMENTSOF(table); i++) + if (streq(table[i], fstype)) + return true; + + return false; +} + +int chvt(int vt) { + int fd, r = 0; + + if ((fd = open("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC)) < 0) + return -errno; + + if (vt < 0) { + int tiocl[2] = { + TIOCL_GETKMSGREDIRECT, + 0 + }; + + if (ioctl(fd, TIOCLINUX, tiocl) < 0) + return -errno; + + vt = tiocl[0] <= 0 ? 1 : tiocl[0]; + } + + if (ioctl(fd, VT_ACTIVATE, vt) < 0) + r = -errno; + + close_nointr(r); + return r; +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime",