X Tutup
Skip to content

Commit 294bf0c

Browse files
committed
Split out pretty-print.c and move pager.c and main-func.h to shared/
This is high-level functionality, and fits better in shared/ (which is for our executables), than in basic/ (which is also for libraries).
1 parent 0166c42 commit 294bf0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+353
-286
lines changed

src/activate/activate.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "fd-util.h"
1515
#include "log.h"
1616
#include "macro.h"
17+
#include "pretty-print.h"
1718
#include "process-util.h"
1819
#include "signal-util.h"
1920
#include "socket-util.h"

src/analyze/analyze.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
#include "pager.h"
3131
#include "parse-util.h"
3232
#include "path-util.h"
33+
#include "pretty-print.h"
3334
#if HAVE_SECCOMP
34-
#include "seccomp-util.h"
35+
# include "seccomp-util.h"
3536
#endif
3637
#include "special.h"
3738
#include "strv.h"

src/ask-password/ask-password.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "log.h"
1111
#include "macro.h"
1212
#include "main-func.h"
13+
#include "pretty-print.h"
1314
#include "strv.h"
14-
#include "terminal-util.h"
1515

1616
static const char *arg_icon = NULL;
1717
static const char *arg_id = NULL;

src/basic/conf-files.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -328,36 +328,3 @@ int conf_files_list_with_replacement(
328328
*replace_file = TAKE_PTR(p);
329329
return 0;
330330
}
331-
332-
int conf_files_cat(const char *root, const char *name) {
333-
_cleanup_strv_free_ char **dirs = NULL, **files = NULL;
334-
_cleanup_free_ char *path = NULL;
335-
const char *dir;
336-
char **t;
337-
int r;
338-
339-
NULSTR_FOREACH(dir, CONF_PATHS_NULSTR("")) {
340-
assert(endswith(dir, "/"));
341-
r = strv_extendf(&dirs, "%s%s.d", dir, name);
342-
if (r < 0)
343-
return log_error_errno(r, "Failed to build directory list: %m");
344-
}
345-
346-
r = conf_files_list_strv(&files, ".conf", root, 0, (const char* const*) dirs);
347-
if (r < 0)
348-
return log_error_errno(r, "Failed to query file list: %m");
349-
350-
path = path_join(root, "/etc", name);
351-
if (!path)
352-
return log_oom();
353-
354-
if (DEBUG_LOGGING) {
355-
log_debug("Looking for configuration in:");
356-
log_debug(" %s", path);
357-
STRV_FOREACH(t, dirs)
358-
log_debug(" %s/*.conf", *t);
359-
}
360-
361-
/* show */
362-
return cat_files(path, files, CAT_FLAGS_MAIN_FILE_OPTIONAL);
363-
}

src/basic/conf-files.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ int conf_files_list_with_replacement(
2222
const char *replacement,
2323
char ***files,
2424
char **replace_file);
25-
int conf_files_cat(const char *root, const char *name);

src/basic/meson.build

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ basic_sources = files('''
9999
nss-util.h
100100
ordered-set.c
101101
ordered-set.h
102-
pager.c
103-
pager.h
104102
parse-util.c
105103
parse-util.h
106104
path-util.c

src/basic/terminal-util.c

Lines changed: 0 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "io-util.h"
3333
#include "log.h"
3434
#include "macro.h"
35-
#include "pager.h"
3635
#include "parse-util.h"
3736
#include "path-util.h"
3837
#include "proc-cmdline.h"
@@ -1272,184 +1271,3 @@ int vt_reset_keyboard(int fd) {
12721271

12731272
return 0;
12741273
}
1275-
1276-
static bool urlify_enabled(void) {
1277-
static int cached_urlify_enabled = -1;
1278-
1279-
/* Unfortunately 'less' doesn't support links like this yet 😭, hence let's disable this as long as there's a
1280-
* pager in effect. Let's drop this check as soon as less got fixed a and enough time passed so that it's safe
1281-
* to assume that a link-enabled 'less' version has hit most installations. */
1282-
1283-
if (cached_urlify_enabled < 0) {
1284-
int val;
1285-
1286-
val = getenv_bool("SYSTEMD_URLIFY");
1287-
if (val >= 0)
1288-
cached_urlify_enabled = val;
1289-
else
1290-
cached_urlify_enabled = colors_enabled() && !pager_have();
1291-
}
1292-
1293-
return cached_urlify_enabled;
1294-
}
1295-
1296-
int terminal_urlify(const char *url, const char *text, char **ret) {
1297-
char *n;
1298-
1299-
assert(url);
1300-
1301-
/* Takes an URL and a pretty string and formats it as clickable link for the terminal. See
1302-
* https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda for details. */
1303-
1304-
if (isempty(text))
1305-
text = url;
1306-
1307-
if (urlify_enabled())
1308-
n = strjoin("\x1B]8;;", url, "\a", text, "\x1B]8;;\a");
1309-
else
1310-
n = strdup(text);
1311-
if (!n)
1312-
return -ENOMEM;
1313-
1314-
*ret = n;
1315-
return 0;
1316-
}
1317-
1318-
int terminal_urlify_path(const char *path, const char *text, char **ret) {
1319-
_cleanup_free_ char *absolute = NULL;
1320-
struct utsname u;
1321-
const char *url;
1322-
int r;
1323-
1324-
assert(path);
1325-
1326-
/* Much like terminal_urlify() above, but takes a file system path as input
1327-
* and turns it into a proper file:// URL first. */
1328-
1329-
if (isempty(path))
1330-
return -EINVAL;
1331-
1332-
if (isempty(text))
1333-
text = path;
1334-
1335-
if (!urlify_enabled()) {
1336-
char *n;
1337-
1338-
n = strdup(text);
1339-
if (!n)
1340-
return -ENOMEM;
1341-
1342-
*ret = n;
1343-
return 0;
1344-
}
1345-
1346-
if (uname(&u) < 0)
1347-
return -errno;
1348-
1349-
if (!path_is_absolute(path)) {
1350-
r = path_make_absolute_cwd(path, &absolute);
1351-
if (r < 0)
1352-
return r;
1353-
1354-
path = absolute;
1355-
}
1356-
1357-
/* As suggested by https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda, let's include the local
1358-
* hostname here. Note that we don't use gethostname_malloc() or gethostname_strict() since we are interested
1359-
* in the raw string the kernel has set, whatever it may be, under the assumption that terminals are not overly
1360-
* careful with validating the strings either. */
1361-
1362-
url = strjoina("file://", u.nodename, path);
1363-
1364-
return terminal_urlify(url, text, ret);
1365-
}
1366-
1367-
int terminal_urlify_man(const char *page, const char *section, char **ret) {
1368-
const char *url, *text;
1369-
1370-
url = strjoina("man:", page, "(", section, ")");
1371-
text = strjoina(page, "(", section, ") man page");
1372-
1373-
return terminal_urlify(url, text, ret);
1374-
}
1375-
1376-
static int cat_file(const char *filename, bool newline) {
1377-
_cleanup_fclose_ FILE *f = NULL;
1378-
_cleanup_free_ char *urlified = NULL;
1379-
int r;
1380-
1381-
f = fopen(filename, "re");
1382-
if (!f)
1383-
return -errno;
1384-
1385-
r = terminal_urlify_path(filename, NULL, &urlified);
1386-
if (r < 0)
1387-
return r;
1388-
1389-
printf("%s%s# %s%s\n",
1390-
newline ? "\n" : "",
1391-
ansi_highlight_blue(),
1392-
urlified,
1393-
ansi_normal());
1394-
fflush(stdout);
1395-
1396-
for (;;) {
1397-
_cleanup_free_ char *line = NULL;
1398-
1399-
r = read_line(f, LONG_LINE_MAX, &line);
1400-
if (r < 0)
1401-
return log_error_errno(r, "Failed to read \"%s\": %m", filename);
1402-
if (r == 0)
1403-
break;
1404-
1405-
puts(line);
1406-
}
1407-
1408-
return 0;
1409-
}
1410-
1411-
int cat_files(const char *file, char **dropins, CatFlags flags) {
1412-
char **path;
1413-
int r;
1414-
1415-
if (file) {
1416-
r = cat_file(file, false);
1417-
if (r == -ENOENT && (flags & CAT_FLAGS_MAIN_FILE_OPTIONAL))
1418-
printf("%s# config file %s not found%s\n",
1419-
ansi_highlight_magenta(),
1420-
file,
1421-
ansi_normal());
1422-
else if (r < 0)
1423-
return log_warning_errno(r, "Failed to cat %s: %m", file);
1424-
}
1425-
1426-
STRV_FOREACH(path, dropins) {
1427-
r = cat_file(*path, file || path != dropins);
1428-
if (r < 0)
1429-
return log_warning_errno(r, "Failed to cat %s: %m", *path);
1430-
}
1431-
1432-
return 0;
1433-
}
1434-
1435-
void print_separator(void) {
1436-
1437-
/* Outputs a separator line that resolves to whitespace when copied from the terminal. We do that by outputting
1438-
* one line filled with spaces with ANSI underline set, followed by a second (empty) line. */
1439-
1440-
if (underline_enabled()) {
1441-
size_t i, c;
1442-
1443-
c = columns();
1444-
1445-
flockfile(stdout);
1446-
fputs_unlocked(ANSI_UNDERLINE, stdout);
1447-
1448-
for (i = 0; i < c; i++)
1449-
fputc_unlocked(' ', stdout);
1450-
1451-
fputs_unlocked(ANSI_NORMAL "\n\n", stdout);
1452-
funlockfile(stdout);
1453-
} else
1454-
fputs("\n\n", stdout);
1455-
}

src/basic/terminal-util.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,3 @@ int open_terminal_in_namespace(pid_t pid, const char *name, int mode);
154154

155155
int vt_default_utf8(void);
156156
int vt_reset_keyboard(int fd);
157-
158-
int terminal_urlify(const char *url, const char *text, char **ret);
159-
int terminal_urlify_path(const char *path, const char *text, char **ret);
160-
int terminal_urlify_man(const char *page, const char *section, char **ret);
161-
162-
typedef enum CatFlags {
163-
CAT_FLAGS_MAIN_FILE_OPTIONAL = 1 << 0,
164-
} CatFlags;
165-
166-
int cat_files(const char *file, char **dropins, CatFlags flags);
167-
168-
void print_separator(void);

src/binfmt/binfmt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#include "main-func.h"
1818
#include "pager.h"
1919
#include "path-util.h"
20+
#include "pretty-print.h"
2021
#include "string-util.h"
2122
#include "strv.h"
22-
#include "terminal-util.h"
2323
#include "util.h"
2424

2525
static bool arg_cat_config = false;

src/boot/bootctl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "main-func.h"
3333
#include "pager.h"
3434
#include "parse-util.h"
35+
#include "pretty-print.h"
3536
#include "rm-rf.h"
3637
#include "stat-util.h"
3738
#include "string-util.h"

0 commit comments

Comments
 (0)
X Tutup