mirror of
https://github.com/systemd/systemd.git
synced 2025-03-28 02:50:16 +03:00
shared: add terminal-util.[ch]
This commit is contained in:
parent
3df3e884ae
commit
288a74cce5
1
.gitignore
vendored
1
.gitignore
vendored
@ -256,6 +256,7 @@
|
||||
/test-tables
|
||||
/test-term-page
|
||||
/test-term-parser
|
||||
/test-terminal-util
|
||||
/test-time
|
||||
/test-tmpfiles
|
||||
/test-udev
|
||||
|
@ -903,6 +903,8 @@ libsystemd_shared_la_SOURCES = \
|
||||
src/shared/process-util.h \
|
||||
src/shared/random-util.c \
|
||||
src/shared/random-util.h \
|
||||
src/shared/terminal-util.c \
|
||||
src/shared/terminal-util.h \
|
||||
src/shared/uid-range.c \
|
||||
src/shared/uid-range.h \
|
||||
src/shared/nss-util.h \
|
||||
@ -1394,6 +1396,7 @@ tests += \
|
||||
test-ellipsize \
|
||||
test-util \
|
||||
test-process-util \
|
||||
test-terminal-util \
|
||||
test-path-lookup \
|
||||
test-ring \
|
||||
test-barrier \
|
||||
@ -1675,6 +1678,12 @@ test_process_util_SOURCES = \
|
||||
test_process_util_LDADD = \
|
||||
libsystemd-shared.la
|
||||
|
||||
test_terminal_util_SOURCES = \
|
||||
src/test/test-terminal-util.c
|
||||
|
||||
test_terminal_util_LDADD = \
|
||||
libsystemd-shared.la
|
||||
|
||||
test_path_lookup_SOURCES = \
|
||||
src/test/test-path-lookup.c
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "hashmap.h"
|
||||
#include "pager.h"
|
||||
#include "analyze-verify.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
#define SCALE_X (0.1 / 1000.0) /* pixels per us */
|
||||
#define SCALE_Y (20.0)
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <getopt.h>
|
||||
|
||||
#include "path-util.h"
|
||||
#include "terminal-util.h"
|
||||
#include "util.h"
|
||||
#include "hashmap.h"
|
||||
#include "cgroup-util.h"
|
||||
|
@ -78,6 +78,7 @@
|
||||
#include "cap-list.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
#ifdef HAVE_APPARMOR
|
||||
#include "apparmor-util.h"
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "bus-error.h"
|
||||
#include "special.h"
|
||||
#include "failure-action.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static void log_and_status(Manager *m, const char *message) {
|
||||
log_warning("%s", message);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "async.h"
|
||||
#include "virt.h"
|
||||
#include "dbus.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
Job* job_new_raw(Unit *unit) {
|
||||
Job *j;
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "set.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
#define TIMEOUT_USEC (10 * USEC_PER_SEC)
|
||||
|
||||
|
@ -74,6 +74,7 @@
|
||||
#include "kmod-setup.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static enum {
|
||||
ACTION_RUN,
|
||||
|
@ -72,6 +72,7 @@
|
||||
#include "bus-kernel.h"
|
||||
#include "time-util.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
/* Initial delay and the interval for printing status messages about running jobs */
|
||||
#define JOBS_IN_PROGRESS_WAIT_USEC (5*USEC_PER_SEC)
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "def.h"
|
||||
#include "switch-root.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
#define FINALIZE_ATTEMPTS 50
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "bus-common-errors.h"
|
||||
#include "bus-error.h"
|
||||
#include "transaction.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependencies);
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "build.h"
|
||||
#include "strv.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static const char prefixes[] =
|
||||
"/etc\0"
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "random-util.h"
|
||||
#include "locale-util.h"
|
||||
#include "ask-password-api.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static char *arg_root = NULL;
|
||||
static char *arg_locale = NULL; /* $LANG */
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "fileio.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static const char *arg_dest = "/tmp";
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "compress.h"
|
||||
#include "sigbus.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static enum {
|
||||
ACTION_NONE,
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "journal-verify.h"
|
||||
#include "lookup3.h"
|
||||
#include "compress.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static void draw_progress(uint64_t p, usec_t *last_usec) {
|
||||
unsigned n, i, j, k;
|
||||
|
@ -60,6 +60,7 @@
|
||||
#include "mkdir.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-error.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
#define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE)
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "journald-console.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static bool prefix_timestamp(void) {
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "rm-rf.h"
|
||||
#include "journal-file.h"
|
||||
#include "journal-verify.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
#define N_ENTRIES 6000
|
||||
#define RANDOM_RANGE 77
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "macro.h"
|
||||
#include "cap-list.h"
|
||||
#include "formats-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
#include "bus-message.h"
|
||||
#include "bus-internal.h"
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "bus-signature.h"
|
||||
#include "bus-type.h"
|
||||
#include "busctl-introspect.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static bool arg_no_pager = false;
|
||||
static bool arg_legend = true;
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "spawn-polkit-agent.h"
|
||||
#include "verbs.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static char **arg_property = NULL;
|
||||
static bool arg_all = false;
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "logind-action.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
int manager_handle_action(
|
||||
Manager *m,
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "bus-error.h"
|
||||
#include "udev-util.h"
|
||||
#include "logind.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
int manager_add_device(Manager *m, const char *sysfs, bool master, Device **_device) {
|
||||
Device *d;
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "logind.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const char *name, sd_bus_error *error, Session **ret) {
|
||||
_cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "util.h"
|
||||
#include "mkdir.h"
|
||||
#include "formats-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
Seat *seat_new(Manager *m, const char *id) {
|
||||
Seat *s;
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "bus-error.h"
|
||||
#include "logind-session.h"
|
||||
#include "formats-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
#define RELEASE_USEC (20*USEC_PER_SEC)
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "fileio.h"
|
||||
#include "bus-error.h"
|
||||
#include "formats-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static int parse_argv(
|
||||
pam_handle_t *handle,
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "sysfs-show.h"
|
||||
#include "path-util.h"
|
||||
#include "udev-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static int show_sysfs_one(
|
||||
struct udev *udev,
|
||||
|
@ -53,6 +53,7 @@
|
||||
#include "verbs.h"
|
||||
#include "import-util.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static char **arg_property = NULL;
|
||||
static bool arg_all = false;
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "socket-util.h"
|
||||
#include "ether-addr-util.h"
|
||||
#include "verbs.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static bool arg_no_pager = false;
|
||||
static bool arg_legend = true;
|
||||
|
@ -94,6 +94,7 @@
|
||||
#include "local-addresses.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
#ifdef HAVE_SECCOMP
|
||||
#include "seccomp-util.h"
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "mkdir.h"
|
||||
#include "strv.h"
|
||||
#include "random-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
#include "ask-password-api.h"
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "path-util.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "cgroup-show.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static int compare(const void *a, const void *b) {
|
||||
const pid_t *p = a, *q = b;
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "socket-util.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
#define SNDBUF_SIZE (8*1024*1024)
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "journal-internal.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
/* up to three lines (each up to 100 characters),
|
||||
or 300 characters, whichever is less */
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "util.h"
|
||||
#include "process-util.h"
|
||||
#include "macro.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static pid_t pager_pid = 0;
|
||||
|
||||
|
1072
src/shared/terminal-util.c
Normal file
1072
src/shared/terminal-util.c
Normal file
File diff suppressed because it is too large
Load Diff
109
src/shared/terminal-util.h
Normal file
109
src/shared/terminal-util.h
Normal file
@ -0,0 +1,109 @@
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
|
||||
systemd is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
systemd is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "macro.h"
|
||||
#include "time-util.h"
|
||||
|
||||
#define ANSI_HIGHLIGHT_ON "\x1B[1;39m"
|
||||
#define ANSI_RED_ON "\x1B[31m"
|
||||
#define ANSI_HIGHLIGHT_RED_ON "\x1B[1;31m"
|
||||
#define ANSI_GREEN_ON "\x1B[32m"
|
||||
#define ANSI_HIGHLIGHT_GREEN_ON "\x1B[1;32m"
|
||||
#define ANSI_HIGHLIGHT_YELLOW_ON "\x1B[1;33m"
|
||||
#define ANSI_HIGHLIGHT_BLUE_ON "\x1B[1;34m"
|
||||
#define ANSI_HIGHLIGHT_OFF "\x1B[0m"
|
||||
#define ANSI_ERASE_TO_END_OF_LINE "\x1B[K"
|
||||
|
||||
int reset_terminal_fd(int fd, bool switch_to_text);
|
||||
int reset_terminal(const char *name);
|
||||
|
||||
int open_terminal(const char *name, int mode);
|
||||
int acquire_terminal(const char *name, bool fail, bool force, bool ignore_tiocstty_eperm, usec_t timeout);
|
||||
int release_terminal(void);
|
||||
|
||||
int terminal_vhangup_fd(int fd);
|
||||
int terminal_vhangup(const char *name);
|
||||
|
||||
int chvt(int vt);
|
||||
|
||||
int read_one_char(FILE *f, char *ret, usec_t timeout, bool *need_nl);
|
||||
int ask_char(char *ret, const char *replies, const char *text, ...) _printf_(3, 4);
|
||||
int ask_string(char **ret, const char *text, ...) _printf_(2, 3);
|
||||
|
||||
int vt_disallocate(const char *name);
|
||||
|
||||
char *resolve_dev_console(char **active);
|
||||
bool tty_is_vc(const char *tty);
|
||||
bool tty_is_vc_resolve(const char *tty);
|
||||
bool tty_is_console(const char *tty) _pure_;
|
||||
int vtnr_from_tty(const char *tty);
|
||||
const char *default_term_for_tty(const char *tty);
|
||||
|
||||
void warn_melody(void);
|
||||
|
||||
int make_stdio(int fd);
|
||||
int make_null_stdio(void);
|
||||
int make_console_stdio(void);
|
||||
|
||||
int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) _printf_(4,0);
|
||||
int status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) _printf_(4,5);
|
||||
|
||||
int fd_columns(int fd);
|
||||
unsigned columns(void);
|
||||
int fd_lines(int fd);
|
||||
unsigned lines(void);
|
||||
void columns_lines_cache_reset(int _unused_ signum);
|
||||
|
||||
bool on_tty(void);
|
||||
|
||||
static inline const char *ansi_highlight(void) {
|
||||
return on_tty() ? ANSI_HIGHLIGHT_ON : "";
|
||||
}
|
||||
|
||||
static inline const char *ansi_highlight_red(void) {
|
||||
return on_tty() ? ANSI_HIGHLIGHT_RED_ON : "";
|
||||
}
|
||||
|
||||
static inline const char *ansi_highlight_green(void) {
|
||||
return on_tty() ? ANSI_HIGHLIGHT_GREEN_ON : "";
|
||||
}
|
||||
|
||||
static inline const char *ansi_highlight_yellow(void) {
|
||||
return on_tty() ? ANSI_HIGHLIGHT_YELLOW_ON : "";
|
||||
}
|
||||
|
||||
static inline const char *ansi_highlight_blue(void) {
|
||||
return on_tty() ? ANSI_HIGHLIGHT_BLUE_ON : "";
|
||||
}
|
||||
|
||||
static inline const char *ansi_highlight_off(void) {
|
||||
return on_tty() ? ANSI_HIGHLIGHT_OFF : "";
|
||||
}
|
||||
|
||||
int get_ctty_devnr(pid_t pid, dev_t *d);
|
||||
int get_ctty(pid_t, dev_t *_devnr, char **r);
|
||||
|
||||
int getttyname_malloc(int fd, char **r);
|
||||
int getttyname_harder(int fd, char **r);
|
1038
src/shared/util.c
1038
src/shared/util.c
File diff suppressed because it is too large
Load Diff
@ -63,16 +63,6 @@
|
||||
|
||||
#define FORMAT_BYTES_MAX 8
|
||||
|
||||
#define ANSI_HIGHLIGHT_ON "\x1B[1;39m"
|
||||
#define ANSI_RED_ON "\x1B[31m"
|
||||
#define ANSI_HIGHLIGHT_RED_ON "\x1B[1;31m"
|
||||
#define ANSI_GREEN_ON "\x1B[32m"
|
||||
#define ANSI_HIGHLIGHT_GREEN_ON "\x1B[1;32m"
|
||||
#define ANSI_HIGHLIGHT_YELLOW_ON "\x1B[1;33m"
|
||||
#define ANSI_HIGHLIGHT_BLUE_ON "\x1B[1;34m"
|
||||
#define ANSI_HIGHLIGHT_OFF "\x1B[0m"
|
||||
#define ANSI_ERASE_TO_END_OF_LINE "\x1B[K"
|
||||
|
||||
size_t page_size(void) _pure_;
|
||||
#define PAGE_ALIGN(l) ALIGN_TO((l), page_size())
|
||||
|
||||
@ -279,10 +269,6 @@ bool hidden_file(const char *filename) _pure_;
|
||||
|
||||
bool chars_intersect(const char *a, const char *b) _pure_;
|
||||
|
||||
int make_stdio(int fd);
|
||||
int make_null_stdio(void);
|
||||
int make_console_stdio(void);
|
||||
|
||||
/* For basic lookup tables with strictly enumerated entries */
|
||||
#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \
|
||||
scope const char *name##_to_string(type i) { \
|
||||
@ -348,19 +334,6 @@ int close_all_fds(const int except[], unsigned n_except);
|
||||
|
||||
bool fstype_is_network(const char *fstype);
|
||||
|
||||
int chvt(int vt);
|
||||
|
||||
int read_one_char(FILE *f, char *ret, usec_t timeout, bool *need_nl);
|
||||
int ask_char(char *ret, const char *replies, const char *text, ...) _printf_(3, 4);
|
||||
int ask_string(char **ret, const char *text, ...) _printf_(2, 3);
|
||||
|
||||
int reset_terminal_fd(int fd, bool switch_to_text);
|
||||
int reset_terminal(const char *name);
|
||||
|
||||
int open_terminal(const char *name, int mode);
|
||||
int acquire_terminal(const char *name, bool fail, bool force, bool ignore_tiocstty_eperm, usec_t timeout);
|
||||
int release_terminal(void);
|
||||
|
||||
int flush_fd(int fd);
|
||||
|
||||
int ignore_signals(int sig, ...);
|
||||
@ -388,12 +361,6 @@ char* gethostname_malloc(void);
|
||||
char* getlogname_malloc(void);
|
||||
char* getusername_malloc(void);
|
||||
|
||||
int getttyname_malloc(int fd, char **r);
|
||||
int getttyname_harder(int fd, char **r);
|
||||
|
||||
int get_ctty_devnr(pid_t pid, dev_t *d);
|
||||
int get_ctty(pid_t, dev_t *_devnr, char **r);
|
||||
|
||||
int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
|
||||
int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid);
|
||||
|
||||
@ -404,43 +371,8 @@ int pipe_eof(int fd);
|
||||
|
||||
cpu_set_t* cpu_set_malloc(unsigned *ncpus);
|
||||
|
||||
int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char *format, va_list ap) _printf_(4,0);
|
||||
int status_printf(const char *status, bool ellipse, bool ephemeral, const char *format, ...) _printf_(4,5);
|
||||
|
||||
#define xsprintf(buf, fmt, ...) assert_se((size_t) snprintf(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__) < ELEMENTSOF(buf))
|
||||
|
||||
int fd_columns(int fd);
|
||||
unsigned columns(void);
|
||||
int fd_lines(int fd);
|
||||
unsigned lines(void);
|
||||
void columns_lines_cache_reset(int _unused_ signum);
|
||||
|
||||
bool on_tty(void);
|
||||
|
||||
static inline const char *ansi_highlight(void) {
|
||||
return on_tty() ? ANSI_HIGHLIGHT_ON : "";
|
||||
}
|
||||
|
||||
static inline const char *ansi_highlight_red(void) {
|
||||
return on_tty() ? ANSI_HIGHLIGHT_RED_ON : "";
|
||||
}
|
||||
|
||||
static inline const char *ansi_highlight_green(void) {
|
||||
return on_tty() ? ANSI_HIGHLIGHT_GREEN_ON : "";
|
||||
}
|
||||
|
||||
static inline const char *ansi_highlight_yellow(void) {
|
||||
return on_tty() ? ANSI_HIGHLIGHT_YELLOW_ON : "";
|
||||
}
|
||||
|
||||
static inline const char *ansi_highlight_blue(void) {
|
||||
return on_tty() ? ANSI_HIGHLIGHT_BLUE_ON : "";
|
||||
}
|
||||
|
||||
static inline const char *ansi_highlight_off(void) {
|
||||
return on_tty() ? ANSI_HIGHLIGHT_OFF : "";
|
||||
}
|
||||
|
||||
int files_same(const char *filea, const char *fileb);
|
||||
|
||||
int running_in_chroot(void);
|
||||
@ -462,13 +394,6 @@ DIR *xopendirat(int dirfd, const char *name, int flags);
|
||||
|
||||
char *fstab_node_to_udev_node(const char *p);
|
||||
|
||||
char *resolve_dev_console(char **active);
|
||||
bool tty_is_vc(const char *tty);
|
||||
bool tty_is_vc_resolve(const char *tty);
|
||||
bool tty_is_console(const char *tty) _pure_;
|
||||
int vtnr_from_tty(const char *tty);
|
||||
const char *default_term_for_tty(const char *tty);
|
||||
|
||||
void execute_directories(const char* const* directories, usec_t timeout, char *argv[]);
|
||||
|
||||
bool nulstr_contains(const char*nulstr, const char *needle);
|
||||
@ -482,10 +407,6 @@ bool machine_name_is_valid(const char *s) _pure_;
|
||||
|
||||
char* strshorten(char *s, size_t l);
|
||||
|
||||
int terminal_vhangup_fd(int fd);
|
||||
int terminal_vhangup(const char *name);
|
||||
|
||||
int vt_disallocate(const char *name);
|
||||
|
||||
int symlink_atomic(const char *from, const char *to);
|
||||
int mknod_atomic(const char *path, mode_t mode, dev_t dev);
|
||||
@ -583,8 +504,6 @@ bool http_etag_is_valid(const char *etag);
|
||||
|
||||
bool in_initrd(void);
|
||||
|
||||
void warn_melody(void);
|
||||
|
||||
int get_home_dir(char **ret);
|
||||
int get_shell(char **_ret);
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "macro.h"
|
||||
#include "path-util.h"
|
||||
#include "utmp-wtmp.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
int utmp_get_runlevel(int *runlevel, int *previous) {
|
||||
struct utmpx *found, lookup = { .ut_type = RUN_LVL };
|
||||
|
@ -71,6 +71,7 @@
|
||||
#include "efivars.h"
|
||||
#include "formats-util.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static char **arg_types = NULL;
|
||||
static char **arg_states = NULL;
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "terminal-util.h"
|
||||
#include "def.h"
|
||||
|
||||
static void test_one(const char *p) {
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "util.h"
|
||||
#include "macro.h"
|
||||
#include "virt.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static void test_get_process_comm(void) {
|
||||
struct stat st;
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *p;
|
||||
|
84
src/test/test-terminal-util.c
Normal file
84
src/test/test-terminal-util.c
Normal file
@ -0,0 +1,84 @@
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2010 Lennart Poettering
|
||||
Copyright 2013 Thomas H.P. Andersen
|
||||
|
||||
systemd is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
systemd is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "terminal-util.h"
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
|
||||
static void test_default_term_for_tty(void) {
|
||||
puts(default_term_for_tty("/dev/tty23"));
|
||||
puts(default_term_for_tty("/dev/ttyS23"));
|
||||
puts(default_term_for_tty("/dev/tty0"));
|
||||
puts(default_term_for_tty("/dev/pty0"));
|
||||
puts(default_term_for_tty("/dev/pts/0"));
|
||||
puts(default_term_for_tty("/dev/console"));
|
||||
puts(default_term_for_tty("tty23"));
|
||||
puts(default_term_for_tty("ttyS23"));
|
||||
puts(default_term_for_tty("tty0"));
|
||||
puts(default_term_for_tty("pty0"));
|
||||
puts(default_term_for_tty("pts/0"));
|
||||
puts(default_term_for_tty("console"));
|
||||
}
|
||||
|
||||
static void test_read_one_char(void) {
|
||||
_cleanup_fclose_ FILE *file = NULL;
|
||||
char r;
|
||||
bool need_nl;
|
||||
char name[] = "/tmp/test-read_one_char.XXXXXX";
|
||||
int fd;
|
||||
|
||||
fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
|
||||
assert_se(fd >= 0);
|
||||
file = fdopen(fd, "r+");
|
||||
assert_se(file);
|
||||
assert_se(fputs("c\n", file) >= 0);
|
||||
rewind(file);
|
||||
|
||||
assert_se(read_one_char(file, &r, 1000000, &need_nl) >= 0);
|
||||
assert_se(!need_nl);
|
||||
assert_se(r == 'c');
|
||||
assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
|
||||
|
||||
rewind(file);
|
||||
assert_se(fputs("foobar\n", file) >= 0);
|
||||
rewind(file);
|
||||
assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
|
||||
|
||||
rewind(file);
|
||||
assert_se(fputs("\n", file) >= 0);
|
||||
rewind(file);
|
||||
assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
|
||||
|
||||
unlink(name);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
test_default_term_for_tty();
|
||||
test_read_one_char();
|
||||
|
||||
return 0;
|
||||
}
|
@ -522,21 +522,6 @@ static void test_foreach_word_quoted(void) {
|
||||
true);
|
||||
}
|
||||
|
||||
static void test_default_term_for_tty(void) {
|
||||
puts(default_term_for_tty("/dev/tty23"));
|
||||
puts(default_term_for_tty("/dev/ttyS23"));
|
||||
puts(default_term_for_tty("/dev/tty0"));
|
||||
puts(default_term_for_tty("/dev/pty0"));
|
||||
puts(default_term_for_tty("/dev/pts/0"));
|
||||
puts(default_term_for_tty("/dev/console"));
|
||||
puts(default_term_for_tty("tty23"));
|
||||
puts(default_term_for_tty("ttyS23"));
|
||||
puts(default_term_for_tty("tty0"));
|
||||
puts(default_term_for_tty("pty0"));
|
||||
puts(default_term_for_tty("pts/0"));
|
||||
puts(default_term_for_tty("console"));
|
||||
}
|
||||
|
||||
static void test_memdup_multiply(void) {
|
||||
int org[] = {1, 2, 3};
|
||||
int *dup;
|
||||
@ -981,38 +966,6 @@ static void test_readlink_and_make_absolute(void) {
|
||||
assert_se(rm_rf(tempdir, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
|
||||
}
|
||||
|
||||
static void test_read_one_char(void) {
|
||||
_cleanup_fclose_ FILE *file = NULL;
|
||||
char r;
|
||||
bool need_nl;
|
||||
char name[] = "/tmp/test-read_one_char.XXXXXX";
|
||||
int fd;
|
||||
|
||||
fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
|
||||
assert_se(fd >= 0);
|
||||
file = fdopen(fd, "r+");
|
||||
assert_se(file);
|
||||
assert_se(fputs("c\n", file) >= 0);
|
||||
rewind(file);
|
||||
|
||||
assert_se(read_one_char(file, &r, 1000000, &need_nl) >= 0);
|
||||
assert_se(!need_nl);
|
||||
assert_se(r == 'c');
|
||||
assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
|
||||
|
||||
rewind(file);
|
||||
assert_se(fputs("foobar\n", file) >= 0);
|
||||
rewind(file);
|
||||
assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
|
||||
|
||||
rewind(file);
|
||||
assert_se(fputs("\n", file) >= 0);
|
||||
rewind(file);
|
||||
assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
|
||||
|
||||
unlink(name);
|
||||
}
|
||||
|
||||
static void test_ignore_signals(void) {
|
||||
assert_se(ignore_signals(SIGINT, -1) >= 0);
|
||||
assert_se(kill(getpid(), SIGINT) >= 0);
|
||||
@ -1525,7 +1478,6 @@ int main(int argc, char *argv[]) {
|
||||
test_cunescape();
|
||||
test_foreach_word();
|
||||
test_foreach_word_quoted();
|
||||
test_default_term_for_tty();
|
||||
test_memdup_multiply();
|
||||
test_hostname_is_valid();
|
||||
test_u64log2();
|
||||
@ -1552,7 +1504,6 @@ int main(int argc, char *argv[]) {
|
||||
test_close_nointr();
|
||||
test_unlink_noerrno();
|
||||
test_readlink_and_make_absolute();
|
||||
test_read_one_char();
|
||||
test_ignore_signals();
|
||||
test_strshorten();
|
||||
test_strjoina();
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "build.h"
|
||||
#include "strv.h"
|
||||
#include "pager.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static bool arg_no_pager = false;
|
||||
static bool arg_ask_password = true;
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "build.h"
|
||||
#include "def.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static enum {
|
||||
ACTION_LIST,
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "virt.h"
|
||||
#include "fileio.h"
|
||||
#include "process-util.h"
|
||||
#include "terminal-util.h"
|
||||
|
||||
static bool is_vconsole(int fd) {
|
||||
unsigned char data[1];
|
||||
|
Loading…
x
Reference in New Issue
Block a user