chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Prep v225: Applying various fixes and changes to src/libelogind/sd-bus that got lost...
[elogind.git]
/
src
/
basic
/
terminal-util.c
diff --git
a/src/basic/terminal-util.c
b/src/basic/terminal-util.c
index 103643614bd9042ad5c8ea22929e29c7c7db5362..73e5c2e571b681233dfc5135bf5616fd7903d280 100644
(file)
--- a/
src/basic/terminal-util.c
+++ b/
src/basic/terminal-util.c
@@
-44,7
+44,7
@@
static volatile unsigned cached_lines = 0;
int chvt(int vt) {
_cleanup_close_ int fd;
int chvt(int vt) {
_cleanup_close_ int fd;
- fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC);
+ fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC
|O_NONBLOCK
);
if (fd < 0)
return -errno;
if (fd < 0)
return -errno;
@@
-126,6
+126,8
@@
int read_one_char(FILE *f, char *ret, usec_t t, bool *need_nl) {
return 0;
}
return 0;
}
+/// UNNEEDED by elogind
+#if 0
int ask_char(char *ret, const char *replies, const char *text, ...) {
int r;
int ask_char(char *ret, const char *replies, const char *text, ...) {
int r;
@@
-174,8
+176,6
@@
int ask_char(char *ret, const char *replies, const char *text, ...) {
}
}
}
}
-/// UNNEEDED by elogind
-#if 0
int ask_string(char **ret, const char *text, ...) {
assert(ret);
assert(text);
int ask_string(char **ret, const char *text, ...) {
assert(ret);
assert(text);
@@
-233,14
+233,14
@@
int reset_terminal_fd(int fd, bool switch_to_text) {
* interfere with that. */
/* Disable exclusive mode, just in case */
* interfere with that. */
/* Disable exclusive mode, just in case */
- ioctl(fd, TIOCNXCL);
+
(void)
ioctl(fd, TIOCNXCL);
/* Switch to text mode */
if (switch_to_text)
/* Switch to text mode */
if (switch_to_text)
- ioctl(fd, KDSETMODE, KD_TEXT);
+
(void)
ioctl(fd, KDSETMODE, KD_TEXT);
/* Enable console unicode mode */
/* Enable console unicode mode */
- ioctl(fd, KDSKBMODE, K_UNICODE);
+
(void)
ioctl(fd, KDSKBMODE, K_UNICODE);
if (tcgetattr(fd, &termios) < 0) {
r = -errno;
if (tcgetattr(fd, &termios) < 0) {
r = -errno;
@@
-279,7
+279,7
@@
int reset_terminal_fd(int fd, bool switch_to_text) {
finish:
/* Just in case, flush all crap out */
finish:
/* Just in case, flush all crap out */
- tcflush(fd, TCIOFLUSH);
+
(void)
tcflush(fd, TCIOFLUSH);
return r;
}
return r;
}
@@
-287,7
+287,11
@@
finish:
int reset_terminal(const char *name) {
_cleanup_close_ int fd = -1;
int reset_terminal(const char *name) {
_cleanup_close_ int fd = -1;
- fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC);
+ /* We open the terminal with O_NONBLOCK here, to ensure we
+ * don't block on carrier if this is a terminal with carrier
+ * configured. */
+
+ fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
if (fd < 0)
return fd;
if (fd < 0)
return fd;
@@
-307,7
+311,8
@@
int open_terminal(const char *name, int mode) {
* https://bugs.launchpad.net/ubuntu/+source/linux/+bug/554172/comments/245
*/
* https://bugs.launchpad.net/ubuntu/+source/linux/+bug/554172/comments/245
*/
- assert(!(mode & O_CREAT));
+ if (mode & O_CREAT)
+ return -EINVAL;
for (;;) {
fd = open(name, mode, 0);
for (;;) {
fd = open(name, mode, 0);
@@
-416,9
+421,8
@@
int acquire_terminal(
if (r < 0 && r == -EPERM && ignore_tiocstty_eperm)
r = 0;
if (r < 0 && r == -EPERM && ignore_tiocstty_eperm)
r = 0;
- if (r < 0 && (force || fail || r != -EPERM))
{
+ if (r < 0 && (force || fail || r != -EPERM))
goto fail;
goto fail;
- }
if (r >= 0)
break;
if (r >= 0)
break;
@@
-492,6
+496,8
@@
fail:
return r;
}
return r;
}
+/// UNNEEDED by elogind
+#if 0
int release_terminal(void) {
static const struct sigaction sa_new = {
.sa_handler = SIG_IGN,
int release_terminal(void) {
static const struct sigaction sa_new = {
.sa_handler = SIG_IGN,
@@
-502,7
+508,7
@@
int release_terminal(void) {
struct sigaction sa_old;
int r = 0;
struct sigaction sa_old;
int r = 0;
- fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_
NDELAY|O_CLOEXEC
);
+ fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_
CLOEXEC|O_NONBLOCK
);
if (fd < 0)
return -errno;
if (fd < 0)
return -errno;
@@
-517,6
+523,7
@@
int release_terminal(void) {
return r;
}
return r;
}
+#endif // 0
int terminal_vhangup_fd(int fd) {
assert(fd >= 0);
int terminal_vhangup_fd(int fd) {
assert(fd >= 0);
@@
-530,7
+537,7
@@
int terminal_vhangup_fd(int fd) {
int terminal_vhangup(const char *name) {
_cleanup_close_ int fd;
int terminal_vhangup(const char *name) {
_cleanup_close_ int fd;
- fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC);
+ fd = open_terminal(name, O_RDWR|O_NOCTTY|O_CLOEXEC
|O_NONBLOCK
);
if (fd < 0)
return fd;
if (fd < 0)
return fd;
@@
-577,7
+584,7
@@
int vt_disallocate(const char *name) {
return -EINVAL;
/* Try to deallocate */
return -EINVAL;
/* Try to deallocate */
- fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC);
+ fd = open_terminal("/dev/tty0", O_RDWR|O_NOCTTY|O_CLOEXEC
|O_NONBLOCK
);
if (fd < 0)
return fd;
if (fd < 0)
return fd;
@@
-615,18
+622,20
@@
void warn_melody(void) {
/* Yeah, this is synchronous. Kinda sucks. But well... */
/* Yeah, this is synchronous. Kinda sucks. But well... */
- ioctl(fd, KIOCSOUND, (int)(1193180/440));
+
(void)
ioctl(fd, KIOCSOUND, (int)(1193180/440));
usleep(125*USEC_PER_MSEC);
usleep(125*USEC_PER_MSEC);
- ioctl(fd, KIOCSOUND, (int)(1193180/220));
+
(void)
ioctl(fd, KIOCSOUND, (int)(1193180/220));
usleep(125*USEC_PER_MSEC);
usleep(125*USEC_PER_MSEC);
- ioctl(fd, KIOCSOUND, (int)(1193180/220));
+
(void)
ioctl(fd, KIOCSOUND, (int)(1193180/220));
usleep(125*USEC_PER_MSEC);
usleep(125*USEC_PER_MSEC);
- ioctl(fd, KIOCSOUND, 0);
+
(void)
ioctl(fd, KIOCSOUND, 0);
}
}
+/// UNNEEDED by elogind
+#if 0
int make_console_stdio(void) {
int fd, r;
int make_console_stdio(void) {
int fd, r;
@@
-642,6
+651,7
@@
int make_console_stdio(void) {
return 0;
}
return 0;
}
+#endif // 0
int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) {
static const char status_indent[] = " "; /* "[" STATUS "] " */
int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) {
static const char status_indent[] = " "; /* "[" STATUS "] " */
@@
-810,11
+820,14
@@
bool tty_is_vc_resolve(const char *tty) {
return tty_is_vc(tty);
}
return tty_is_vc(tty);
}
+/// UNNEEDED by elogind
+#if 0
const char *default_term_for_tty(const char *tty) {
assert(tty);
return tty_is_vc_resolve(tty) ? "TERM=linux" : "TERM=vt220";
}
const char *default_term_for_tty(const char *tty) {
assert(tty);
return tty_is_vc_resolve(tty) ? "TERM=linux" : "TERM=vt220";
}
+#endif // 0
int fd_columns(int fd) {
struct winsize ws = {};
int fd_columns(int fd) {
struct winsize ws = {};
@@
-969,6
+982,8
@@
int getttyname_malloc(int fd, char **ret) {
return 0;
}
return 0;
}
+/// UNNEEDED by elogind
+#if 0
int getttyname_harder(int fd, char **r) {
int k;
char *s = NULL;
int getttyname_harder(int fd, char **r) {
int k;
char *s = NULL;
@@
-985,6
+1000,7
@@
int getttyname_harder(int fd, char **r) {
*r = s;
return 0;
}
*r = s;
return 0;
}
+#endif // 0
int get_ctty_devnr(pid_t pid, dev_t *d) {
int r;
int get_ctty_devnr(pid_t pid, dev_t *d) {
int r;