1
0
mirror of https://github.com/systemd/systemd synced 2026-04-01 04:34:51 +02:00

Compare commits

..

No commits in common. "00725c3c4f044b55c78467a3dc3d3026aba40a9f" and "5b3874929a4fe5a22f1897dc723247b920a43615" have entirely different histories.

15 changed files with 654 additions and 647 deletions

6
NEWS
View File

@ -19,12 +19,6 @@ CHANGES WITH 259 in spe:
command to add recovery keys to existing user accounts. Previously,
recovery keys could only be configured during initial user creation.
* The default storage mode for the journal is now 'persistent'.
Previously, the default was 'auto', so the presence or lack of
/var/log/journal determined the default storage mode, if no
overriding configuration was provided. The default can be changed
with -Djournal-storage-default=.
CHANGES WITH 258:
Incompatible changes:

View File

@ -10,14 +10,13 @@
<!ENTITY FALLBACK_HOSTNAME "{{FALLBACK_HOSTNAME}}">
<!ENTITY MEMORY_ACCOUNTING_DEFAULT "{{ 'yes' if MEMORY_ACCOUNTING_DEFAULT else 'no' }}">
<!ENTITY KILL_USER_PROCESSES "{{ 'yes' if KILL_USER_PROCESSES else 'no' }}">
<!ENTITY JOURNAL_STORAGE_DEFAULT "{{JOURNAL_STORAGE_DEFAULT}}">
<!ENTITY DEBUGTTY "{{DEBUGTTY}}">
<!ENTITY SYSTEM_SYSVRCLOCAL_PATH "{{SYSTEM_SYSVRCLOCAL_PATH}}">
<!ENTITY HIGH_RLIMIT_NOFILE "{{HIGH_RLIMIT_NOFILE}}">
<!ENTITY DEFAULT_DNSSEC_MODE "{{DEFAULT_DNSSEC_MODE_STR}}">
<!ENTITY DEFAULT_DNS_OVER_TLS_MODE "{{DEFAULT_DNS_OVER_TLS_MODE_STR}}">
<!ENTITY DEFAULT_TIMEOUT_SEC "{{DEFAULT_TIMEOUT_SEC}} s">
<!ENTITY DEFAULT_USER_TIMEOUT_SEC "{{DEFAULT_USER_TIMEOUT_SEC}} s">
<!ENTITY SYSTEMD_DEFAULT_KEYMAP "{{SYSTEMD_DEFAULT_KEYMAP}}">
<!ENTITY DEFAULT_TIMEOUT "{{DEFAULT_TIMEOUT_SEC}} s">
<!ENTITY DEFAULT_USER_TIMEOUT "{{DEFAULT_USER_TIMEOUT_SEC}} s">
<!ENTITY DEFAULT_KEYMAP "{{SYSTEMD_DEFAULT_KEYMAP}}">
<!ENTITY fedora_latest_version "43">
<!ENTITY fedora_cloud_release "1.6">

View File

@ -1,9 +1,6 @@
<?xml version='1.0'?> <!--*-nxml-*-->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % entities SYSTEM "custom-entities.ent" >
%entities;
]>
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
<refentry id="journald.conf"
@ -85,9 +82,8 @@
<filename>/var/log/journal</filename> directory exists, and <literal>volatile</literal> otherwise
(the existence of the directory controls the storage mode). <literal>none</literal> turns off all
storage, all log data received will be dropped (but forwarding to other targets, such as the console,
the kernel log buffer, or a syslog socket will still work). Defaults to
<literal>&JOURNAL_STORAGE_DEFAULT;</literal> in the default journal namespace (this value is
determined at compilation time), and <literal>persistent</literal> in all others.</para>
the kernel log buffer, or a syslog socket will still work). Defaults to <literal>auto</literal> in
the default journal namespace, and <literal>persistent</literal> in all others.</para>
<para>Note that journald will initially use volatile storage, until a call to
<command>journalctl --flush</command> (or sending <constant>SIGUSR1</constant> to journald) will cause

View File

@ -581,9 +581,9 @@
</para>
<para><varname>DefaultTimeoutStartSec=</varname> and <varname>DefaultTimeoutStopSec=</varname>
default to &DEFAULT_TIMEOUT_SEC; in the system manager and &DEFAULT_USER_TIMEOUT_SEC; in the user
manager. <varname>DefaultTimeoutAbortSec=</varname> is not set by default so that all units fall back
to <varname>TimeoutStopSec=</varname>. <varname>DefaultRestartSec=</varname> defaults to 100 ms.
default to &DEFAULT_TIMEOUT; in the system manager and &DEFAULT_USER_TIMEOUT; in the user manager.
<varname>DefaultTimeoutAbortSec=</varname> is not set by default so that all units fall back to
<varname>TimeoutStopSec=</varname>. <varname>DefaultRestartSec=</varname> defaults to 100 ms.
</para>
<xi:include href="version-info.xml" xpointer="v209"/></listitem>
@ -597,8 +597,8 @@
and <filename>/etc/crypttab</filename> (see
<citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>crypttab</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
Defaults to &DEFAULT_TIMEOUT_SEC; in the system manager and &DEFAULT_USER_TIMEOUT_SEC; in the user
manager.</para>
Defaults to &DEFAULT_TIMEOUT; in the system manager and &DEFAULT_USER_TIMEOUT; in the user manager.
</para>
<xi:include href="version-info.xml" xpointer="v252"/></listitem>
</varlistentry>

View File

@ -75,11 +75,11 @@
<term><varname>KEYMAP=</varname></term>
<term><varname>KEYMAP_TOGGLE=</varname></term>
<listitem><para>Configures the key mapping table for the keyboard. <varname>KEYMAP=</varname>
defaults to <literal>&SYSTEMD_DEFAULT_KEYMAP;</literal> if not set. As a special case, if
<literal>@kernel</literal> is specified, no keymap will be loaded, i.e. the kernel's default keymap
will be used. The <varname>KEYMAP_TOGGLE=</varname> can be used to configure a second toggle keymap
and is by default unset.</para></listitem>
<listitem><para>Configures the key mapping table for the keyboard. <varname>KEYMAP=</varname>
defaults to <literal>&DEFAULT_KEYMAP;</literal> if not set. Specially, if <literal>@kernel</literal>
is specified, no keymap will be loaded, i.e. the kernel's default keymap is used. The
<varname>KEYMAP_TOGGLE=</varname> can be used to configure a second toggle keymap and is by default
unset.</para></listitem>
</varlistentry>
<varlistentry>

View File

@ -117,9 +117,6 @@ conf.set10('BUMP_PROC_SYS_FS_FILE_MAX', get_option('bump-proc-sys-fs-file-max'))
conf.set10('BUMP_PROC_SYS_FS_NR_OPEN', get_option('bump-proc-sys-fs-nr-open'))
conf.set('HIGH_RLIMIT_NOFILE', 512*1024)
conf.set('JOURNAL_STORAGE_DEFAULT', get_option('journal-storage-default'))
conf.set('JOURNAL_STORAGE_DEFAULT_VAL', 'STORAGE_' + get_option('journal-storage-default').to_upper())
# Meson ignores the preceding arguments when joining paths if an absolute
# component is encountered, so this should canonicalize various paths when they
# are absolute or relative.
@ -3099,7 +3096,6 @@ summary({
'default locale' : default_locale,
'default nspawn locale' : nspawn_locale,
'default status unit format' : status_unit_format_default,
'default journal storage mode' : conf.get('JOURNAL_STORAGE_DEFAULT'),
'default user $PATH' : default_user_path != '' ? default_user_path : '(same as system services)',
'systemd service watchdog' : service_watchdog == '' ? 'disabled' : service_watchdog,
'time epoch' : f'@time_epoch@ (@alt_time_epoch@)',

View File

@ -139,8 +139,6 @@ option('timedated', type : 'boolean',
description : 'install the systemd-timedated daemon')
option('timesyncd', type : 'boolean',
description : 'install the systemd-timesyncd daemon')
option('journal-storage-default', type : 'combo', choices : ['persistent', 'auto', 'volatile', 'none'],
description : 'default storage mode for journald (main namespace)')
option('remote', type : 'feature', deprecated : { 'true' : 'enabled', 'false' : 'disabled' },
description : 'support for "journal over the network"')
option('create-log-dirs', type : 'boolean',

View File

@ -634,6 +634,8 @@ const char* get_tzname(bool dst) {
}
int parse_gmtoff(const char *t, long *ret) {
int r;
assert(t);
struct tm tm;
@ -645,11 +647,6 @@ int parse_gmtoff(const char *t, long *ret) {
return 0;
}
#ifdef __GLIBC__
return -EINVAL;
#else
int r;
/* musl v1.2.5 does not support %z specifier in strptime(). Since
* https://github.com/kraj/musl/commit/fced99e93daeefb0192fd16304f978d4401d1d77
* %z is supported, but it only supports strict RFC-822/ISO 8601 format, that is, 4 digits with sign
@ -717,7 +714,6 @@ finalize:
}
return 0;
#endif
}
static int parse_timestamp_impl(

View File

@ -831,7 +831,7 @@ char* mangle_gecos(const char *d) {
char *mangled;
/* Makes sure the provided string becomes valid as a GEGOS field, by dropping bad chars. glibc's
* putpwent() only changes \n and : to spaces. We do more: replace all CC too, and remove invalid
* putwent() only changes \n and : to spaces. We do more: replace all CC too, and remove invalid
* UTF-8 */
mangled = strdup(d);

View File

@ -5,7 +5,6 @@
#include "conf-parser.h"
#include "creds-util.h"
#include "daemon-util.h"
#include "initrd-util.h"
#include "journald-audit.h"
#include "journald-config.h"
#include "journald-context.h"
@ -117,12 +116,7 @@ void manager_merge_configs(Manager *m) {
journal_config_done(&m->config);
MERGE_NON_NEGATIVE(storage, JOURNAL_STORAGE_DEFAULT_VAL);
/* In the initrd, only 'none' and 'volatile' make sense. */
if (in_initrd() && IN_SET(m->config.storage, STORAGE_PERSISTENT, STORAGE_AUTO))
m->config.storage = STORAGE_VOLATILE;
MERGE_NON_NEGATIVE(storage, STORAGE_AUTO);
manager_merge_journal_compress_options(m);
MERGE_NON_NEGATIVE(seal, true);
/* By default, /dev/kmsg is read only by the main namespace instance. */

View File

@ -17,7 +17,7 @@
# See journald.conf(5) for details.
[Journal]
#Storage={{ JOURNAL_STORAGE_DEFAULT }}
#Storage=auto
#Compress=yes
#Seal=yes
#SplitMode=uid

View File

@ -153,12 +153,10 @@ executables += [
},
]
custom_target(
input : 'journald.conf.in',
output: 'journald.conf',
command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'],
install : install_sysconfdir_samples,
install_dir : pkgconfigfiledir)
if install_sysconfdir_samples
install_data('journald.conf',
install_dir : pkgconfigfiledir)
endif
if get_option('create-log-dirs')
install_emptydir('/var/log/journal',

View File

@ -1,7 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "env-file.h"
#include "env-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
@ -188,315 +187,4 @@ TEST(write_and_load_env_file) {
}
}
TEST(parse_env_file) {
_cleanup_(unlink_tempfilep) char
t[] = "/tmp/test-fileio-in-XXXXXX",
p[] = "/tmp/test-fileio-out-XXXXXX";
FILE *f;
_cleanup_free_ char *one = NULL, *two = NULL, *three = NULL, *four = NULL, *five = NULL,
*six = NULL, *seven = NULL, *eight = NULL, *nine = NULL, *ten = NULL,
*eleven = NULL, *twelve = NULL, *thirteen = NULL;
_cleanup_strv_free_ char **a = NULL, **b = NULL;
unsigned k;
ASSERT_OK(fmkostemp_safe(t, "w", &f));
fputs("one=BAR \n"
"# comment\n"
" # comment \n"
" ; comment \n"
" two = bar \n"
"invalid line\n"
"invalid line #comment\n"
"three = \"333\n"
"xxxx\"\n"
"four = \'44\\\"44\'\n"
"five = \"55\\\"55\" \"FIVE\" cinco \n"
"six = seis sechs\\\n"
" sis\n"
"seven=\"sevenval\" #nocomment\n"
"eight=eightval #nocomment\n"
"export nine=nineval\n"
"ten=ignored\n"
"ten=ignored\n"
"ten=\n"
"eleven=\\value\n"
"twelve=\"\\value\"\n"
"thirteen='\\value'", f);
fflush(f);
fclose(f);
ASSERT_OK(load_env_file(NULL, t, &a));
STRV_FOREACH(i, a)
log_debug("Got: <%s>", *i);
ASSERT_STREQ(a[0], "one=BAR");
ASSERT_STREQ(a[1], "two=bar");
ASSERT_STREQ(a[2], "three=333\nxxxx");
ASSERT_STREQ(a[3], "four=44\\\"44");
ASSERT_STREQ(a[4], "five=55\"55FIVEcinco");
ASSERT_STREQ(a[5], "six=seis sechs sis");
ASSERT_STREQ(a[6], "seven=sevenval#nocomment");
ASSERT_STREQ(a[7], "eight=eightval #nocomment");
ASSERT_STREQ(a[8], "export nine=nineval");
ASSERT_STREQ(a[9], "ten=");
ASSERT_STREQ(a[10], "eleven=value");
ASSERT_STREQ(a[11], "twelve=\\value");
ASSERT_STREQ(a[12], "thirteen=\\value");
ASSERT_NULL(a[13]);
strv_env_clean(a);
k = 0;
STRV_FOREACH(i, b) {
log_debug("Got2: <%s>", *i);
ASSERT_STREQ(*i, a[k++]);
}
ASSERT_OK(parse_env_file(NULL, t,
"one", &one,
"two", &two,
"three", &three,
"four", &four,
"five", &five,
"six", &six,
"seven", &seven,
"eight", &eight,
"export nine", &nine,
"ten", &ten,
"eleven", &eleven,
"twelve", &twelve,
"thirteen", &thirteen));
log_debug("one=[%s]", strna(one));
log_debug("two=[%s]", strna(two));
log_debug("three=[%s]", strna(three));
log_debug("four=[%s]", strna(four));
log_debug("five=[%s]", strna(five));
log_debug("six=[%s]", strna(six));
log_debug("seven=[%s]", strna(seven));
log_debug("eight=[%s]", strna(eight));
log_debug("export nine=[%s]", strna(nine));
log_debug("ten=[%s]", strna(nine));
log_debug("eleven=[%s]", strna(eleven));
log_debug("twelve=[%s]", strna(twelve));
log_debug("thirteen=[%s]", strna(thirteen));
ASSERT_STREQ(one, "BAR");
ASSERT_STREQ(two, "bar");
ASSERT_STREQ(three, "333\nxxxx");
ASSERT_STREQ(four, "44\\\"44");
ASSERT_STREQ(five, "55\"55FIVEcinco");
ASSERT_STREQ(six, "seis sechs sis");
ASSERT_STREQ(seven, "sevenval#nocomment");
ASSERT_STREQ(eight, "eightval #nocomment");
ASSERT_STREQ(nine, "nineval");
ASSERT_NULL(ten);
ASSERT_STREQ(eleven, "value");
ASSERT_STREQ(twelve, "\\value");
ASSERT_STREQ(thirteen, "\\value");
/* prepare a temporary file to write the environment to */
_cleanup_close_ int fd = -EBADF;
ASSERT_OK(fd = mkostemp_safe(p));
ASSERT_OK(write_env_file(AT_FDCWD, p, /* headers= */ NULL, a, /* flags= */ 0));
ASSERT_OK(load_env_file(NULL, p, &b));
}
static void test_one_shell_var(const char *file, const char *variable, const char *value) {
_cleanup_free_ char *cmd = NULL, *from_shell = NULL;
_cleanup_pclose_ FILE *f = NULL;
size_t sz;
ASSERT_NOT_NULL(cmd = strjoin(". ", file, " && /bin/echo -n \"$", variable, "\""));
ASSERT_NOT_NULL(f = popen(cmd, "re"));
ASSERT_OK(read_full_stream(f, &from_shell, &sz));
ASSERT_EQ(sz, strlen(value));
ASSERT_STREQ(from_shell, value);
}
TEST(parse_multiline_env_file) {
_cleanup_(unlink_tempfilep) char
t[] = "/tmp/test-fileio-in-XXXXXX",
p[] = "/tmp/test-fileio-out-XXXXXX";
FILE *f;
_cleanup_strv_free_ char **a = NULL, **b = NULL;
ASSERT_OK(fmkostemp_safe(t, "w", &f));
fputs("one=BAR\\\n"
"\\ \\ \\ \\ VAR\\\n"
"\\\tGAR\n"
"#comment\n"
"two=\"bar\\\n"
" var\\\n"
"\tgar\"\n"
"#comment\n"
"tri=\"bar \\\n"
" var \\\n"
"\tgar \"\n", f);
ASSERT_OK(fflush_and_check(f));
fclose(f);
test_one_shell_var(t, "one", "BAR VAR\tGAR");
test_one_shell_var(t, "two", "bar var\tgar");
test_one_shell_var(t, "tri", "bar var \tgar ");
ASSERT_OK(load_env_file(NULL, t, &a));
STRV_FOREACH(i, a)
log_debug("Got: <%s>", *i);
ASSERT_STREQ(a[0], "one=BAR VAR\tGAR");
ASSERT_STREQ(a[1], "two=bar var\tgar");
ASSERT_STREQ(a[2], "tri=bar var \tgar ");
ASSERT_NULL(a[3]);
_cleanup_close_ int fd = -EBADF;
ASSERT_OK(fd = mkostemp_safe(p));
ASSERT_OK(write_env_file(AT_FDCWD, p, /* headers= */ NULL, a, /* flags= */ 0));
ASSERT_OK(load_env_file(NULL, p, &b));
}
TEST(merge_env_file) {
_cleanup_(unlink_tempfilep) char t[] = "/tmp/test-fileio-XXXXXX";
_cleanup_fclose_ FILE *f = NULL;
_cleanup_strv_free_ char **a = NULL;
ASSERT_OK(fmkostemp_safe(t, "w", &f));
ASSERT_OK(write_string_stream(f,
"one=1 \n"
"twelve=${one}2\n"
"twentyone=2${one}\n"
"one=2\n"
"twentytwo=2${one}\n"
"xxx_minus_three=$xxx - 3\n"
"xxx=0x$one$one$one\n"
"yyy=${one:-fallback}\n"
"zzz=${one:+replacement}\n"
"zzzz=${foobar:-${nothing}}\n"
"zzzzz=${nothing:+${nothing}}\n"
, WRITE_STRING_FILE_AVOID_NEWLINE));
ASSERT_OK(merge_env_file(&a, NULL, t));
strv_sort(a);
STRV_FOREACH(i, a)
log_debug("Got: <%s>", *i);
ASSERT_STREQ(a[0], "one=2");
ASSERT_STREQ(a[1], "twelve=12");
ASSERT_STREQ(a[2], "twentyone=21");
ASSERT_STREQ(a[3], "twentytwo=22");
ASSERT_STREQ(a[4], "xxx=0x222");
ASSERT_STREQ(a[5], "xxx_minus_three= - 3");
ASSERT_STREQ(a[6], "yyy=2");
ASSERT_STREQ(a[7], "zzz=replacement");
ASSERT_STREQ(a[8], "zzzz=");
ASSERT_STREQ(a[9], "zzzzz=");
ASSERT_NULL(a[10]);
ASSERT_OK(merge_env_file(&a, NULL, t));
strv_sort(a);
STRV_FOREACH(i, a)
log_debug("Got2: <%s>", *i);
ASSERT_STREQ(a[0], "one=2");
ASSERT_STREQ(a[1], "twelve=12");
ASSERT_STREQ(a[2], "twentyone=21");
ASSERT_STREQ(a[3], "twentytwo=22");
ASSERT_STREQ(a[4], "xxx=0x222");
ASSERT_STREQ(a[5], "xxx_minus_three=0x222 - 3");
ASSERT_STREQ(a[6], "yyy=2");
ASSERT_STREQ(a[7], "zzz=replacement");
ASSERT_STREQ(a[8], "zzzz=");
ASSERT_STREQ(a[9], "zzzzz=");
ASSERT_NULL(a[10]);
}
TEST(merge_env_file_invalid) {
_cleanup_(unlink_tempfilep) char t[] = "/tmp/test-fileio-XXXXXX";
_cleanup_fclose_ FILE *f = NULL;
_cleanup_strv_free_ char **a = NULL;
ASSERT_OK(fmkostemp_safe(t, "w", &f));
ASSERT_OK(write_string_stream(f,
"unset one \n"
"unset one= \n"
"unset one=1 \n"
"one \n"
"one = \n"
"one two =\n"
"\x20two=\n"
"#comment=comment\n"
";comment2=comment2\n"
"#\n"
"\n\n" /* empty line */
, WRITE_STRING_FILE_AVOID_NEWLINE));
ASSERT_OK(merge_env_file(&a, NULL, t));
STRV_FOREACH(i, a)
log_debug("Got: <%s>", *i);
ASSERT_TRUE(strv_isempty(a));
}
static void check_file_pairs_one(char **l) {
ASSERT_EQ(strv_length(l), 14U);
STRV_FOREACH_PAIR(k, v, l) {
if (streq(*k, "NAME"))
ASSERT_STREQ(*v, "Arch Linux");
else if (streq(*k, "ID"))
ASSERT_STREQ(*v, "arch");
else if (streq(*k, "PRETTY_NAME"))
ASSERT_STREQ(*v, "Arch Linux");
else if (streq(*k, "ANSI_COLOR"))
ASSERT_STREQ(*v, "0;36");
else if (streq(*k, "HOME_URL"))
ASSERT_STREQ(*v, "https://www.archlinux.org/");
else if (streq(*k, "SUPPORT_URL"))
ASSERT_STREQ(*v, "https://bbs.archlinux.org/");
else if (streq(*k, "BUG_REPORT_URL"))
ASSERT_STREQ(*v, "https://bugs.archlinux.org/");
else
assert_not_reached();
}
}
TEST(load_env_file_pairs) {
_cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-load_env_file_pairs-XXXXXX";
_cleanup_fclose_ FILE *f = NULL;
_cleanup_strv_free_ char **l = NULL;
int fd;
ASSERT_OK(fd = mkostemp_safe(fn));
ASSERT_OK(write_string_file(fn,
"NAME=\"Arch Linux\"\n"
"ID=arch\n"
"PRETTY_NAME=\"Arch Linux\"\n"
"ANSI_COLOR=\"0;36\"\n"
"HOME_URL=\"https://www.archlinux.org/\"\n"
"SUPPORT_URL=\"https://bbs.archlinux.org/\"\n"
"BUG_REPORT_URL=\"https://bugs.archlinux.org/\"\n"
, WRITE_STRING_FILE_CREATE));
ASSERT_OK(load_env_file_pairs_fd(fd, fn, &l));
check_file_pairs_one(l);
l = strv_free(l);
ASSERT_NOT_NULL(f = fdopen(fd, "r"));
ASSERT_OK(load_env_file_pairs(f, fn, &l));
check_file_pairs_one(l);
}
DEFINE_TEST_MAIN(LOG_INFO);

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -11,7 +10,6 @@
#include "fileio.h"
#include "format-util.h"
#include "fs-util.h"
#include "iovec-util.h"
#include "log.h"
#include "path-util.h"
#include "process-util.h"
@ -19,62 +17,6 @@
#include "tests.h"
#include "tmpfile-util.h"
TEST(writing_tmpfile) {
_cleanup_(unlink_tempfilep) char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX";
_cleanup_free_ char *contents = NULL;
size_t size;
_cleanup_close_ int fd = -EBADF;
struct iovec iov[] = {
IOVEC_MAKE_STRING("abc\n"),
IOVEC_MAKE_STRING(ALPHANUMERICAL "\n"),
IOVEC_MAKE_STRING(""),
};
ASSERT_OK(fd = mkostemp_safe(name));
ASSERT_OK_ERRNO(writev(fd, iov, 3));
ASSERT_OK(read_full_file(name, &contents, &size));
ASSERT_STREQ(contents, "abc\n" ALPHANUMERICAL "\n");
}
TEST(tempfn) {
char *ret = NULL, *p;
ASSERT_OK(tempfn_xxxxxx("/foo/bar/waldo", NULL, &ret));
ASSERT_STREQ(ret, "/foo/bar/.#waldoXXXXXX");
free(ret);
ASSERT_OK(tempfn_xxxxxx("/foo/bar/waldo", "[miau]", &ret));
ASSERT_STREQ(ret, "/foo/bar/.#[miau]waldoXXXXXX");
free(ret);
ASSERT_OK(tempfn_random("/foo/bar/waldo", NULL, &ret));
ASSERT_NOT_NULL(p = startswith(ret, "/foo/bar/.#waldo"));
ASSERT_EQ(strlen(p), 16U);
ASSERT_TRUE(in_charset(p, "0123456789abcdef"));
free(ret);
ASSERT_OK(tempfn_random("/foo/bar/waldo", "[wuff]", &ret));
ASSERT_NOT_NULL(p = startswith(ret, "/foo/bar/.#[wuff]waldo"));
ASSERT_EQ(strlen(p), 16U);
ASSERT_TRUE(in_charset(p, "0123456789abcdef"));
free(ret);
ASSERT_OK(tempfn_random_child("/foo/bar/waldo", NULL, &ret));
ASSERT_NOT_NULL(p = startswith(ret, "/foo/bar/waldo/.#"));
ASSERT_EQ(strlen(p), 16U);
ASSERT_TRUE(in_charset(p, "0123456789abcdef"));
free(ret);
ASSERT_OK(tempfn_random_child("/foo/bar/waldo", "[kikiriki]", &ret));
ASSERT_NOT_NULL(p = startswith(ret, "/foo/bar/waldo/.#[kikiriki]"));
ASSERT_EQ(strlen(p), 16U);
ASSERT_TRUE(in_charset(p, "0123456789abcdef"));
free(ret);
}
static void test_tempfn_random_one(const char *p, const char *extra, const char *expect, int ret) {
_cleanup_free_ char *s = NULL;
int r;