mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
tree-wide: set WRITE_STRING_FILE_DISABLE_BUFFER flag when we write files under /proc or /sys
This commit is contained in:
parent
76cdddfb9d
commit
57512c893e
@ -115,7 +115,7 @@ int mac_smack_apply_pid(pid_t pid, const char *label) {
|
||||
return 0;
|
||||
|
||||
p = procfs_file_alloca(pid, "attr/current");
|
||||
r = write_string_file(p, label, 0);
|
||||
r = write_string_file(p, label, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -606,7 +606,7 @@ void disable_coredumps(void) {
|
||||
if (detect_container() > 0)
|
||||
return;
|
||||
|
||||
r = write_string_file("/proc/sys/kernel/core_pattern", "|/bin/false", 0);
|
||||
r = write_string_file("/proc/sys/kernel/core_pattern", "|/bin/false", WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to turn off coredumps, ignoring: %m");
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ static int delete_rule(const char *rule) {
|
||||
if (!fn)
|
||||
return log_oom();
|
||||
|
||||
return write_string_file(fn, "-1", 0);
|
||||
return write_string_file(fn, "-1", WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
}
|
||||
|
||||
static int apply_rule(const char *rule) {
|
||||
@ -55,7 +55,7 @@ static int apply_rule(const char *rule) {
|
||||
|
||||
(void) delete_rule(rule);
|
||||
|
||||
r = write_string_file("/proc/sys/fs/binfmt_misc/register", rule, 0);
|
||||
r = write_string_file("/proc/sys/fs/binfmt_misc/register", rule, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add binary format: %m");
|
||||
|
||||
@ -219,7 +219,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
/* Flush out all rules */
|
||||
write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", 0);
|
||||
write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
|
||||
STRV_FOREACH(f, files) {
|
||||
k = apply_file(*f, true);
|
||||
|
@ -1400,7 +1400,7 @@ static int bump_unix_max_dgram_qlen(void) {
|
||||
if (v >= DEFAULT_UNIX_MAX_DGRAM_QLEN)
|
||||
return 0;
|
||||
|
||||
r = write_string_filef("/proc/sys/net/unix/max_dgram_qlen", 0, "%lu", DEFAULT_UNIX_MAX_DGRAM_QLEN);
|
||||
r = write_string_filef("/proc/sys/net/unix/max_dgram_qlen", WRITE_STRING_FILE_DISABLE_BUFFER, "%lu", DEFAULT_UNIX_MAX_DGRAM_QLEN);
|
||||
if (r < 0)
|
||||
return log_full_errno(IN_SET(r, -EROFS, -EPERM, -EACCES) ? LOG_DEBUG : LOG_WARNING, r,
|
||||
"Failed to bump AF_UNIX datagram queue length, ignoring: %m");
|
||||
@ -1615,7 +1615,7 @@ static void initialize_core_pattern(bool skip_setup) {
|
||||
if (getpid_cached() != 1)
|
||||
return;
|
||||
|
||||
r = write_string_file("/proc/sys/kernel/core_pattern", arg_early_core_pattern, 0);
|
||||
r = write_string_file("/proc/sys/kernel/core_pattern", arg_early_core_pattern, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to write '%s' to /proc/sys/kernel/core_pattern, ignoring: %m", arg_early_core_pattern);
|
||||
}
|
||||
|
@ -351,17 +351,17 @@ int mac_smack_setup(bool *loaded_policy) {
|
||||
}
|
||||
|
||||
#ifdef SMACK_RUN_LABEL
|
||||
r = write_string_file("/proc/self/attr/current", SMACK_RUN_LABEL, 0);
|
||||
r = write_string_file("/proc/self/attr/current", SMACK_RUN_LABEL, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to set SMACK label \"" SMACK_RUN_LABEL "\" on self: %m");
|
||||
r = write_string_file("/sys/fs/smackfs/ambient", SMACK_RUN_LABEL, 0);
|
||||
r = write_string_file("/sys/fs/smackfs/ambient", SMACK_RUN_LABEL, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to set SMACK ambient label \"" SMACK_RUN_LABEL "\": %m");
|
||||
r = write_string_file("/sys/fs/smackfs/netlabel",
|
||||
"0.0.0.0/0 " SMACK_RUN_LABEL, 0);
|
||||
"0.0.0.0/0 " SMACK_RUN_LABEL, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to set SMACK netlabel rule \"0.0.0.0/0 " SMACK_RUN_LABEL "\": %m");
|
||||
r = write_string_file("/sys/fs/smackfs/netlabel", "127.0.0.1 -CIPSO", 0);
|
||||
r = write_string_file("/sys/fs/smackfs/netlabel", "127.0.0.1 -CIPSO", WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to set SMACK netlabel rule \"127.0.0.1 -CIPSO\": %m");
|
||||
#endif
|
||||
|
@ -47,7 +47,7 @@ int main(int argc, char *argv[]) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
r = write_string_file("/sys/power/resume", major_minor, WRITE_STRING_FILE_CREATE);
|
||||
r = write_string_file("/sys/power/resume", major_minor, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to write '%s' to /sys/power/resume: %m", major_minor);
|
||||
return EXIT_FAILURE;
|
||||
|
@ -1226,7 +1226,7 @@ static int trigger_device(Manager *m, sd_device *d) {
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
|
||||
(void) write_string_file(t, "change", 0);
|
||||
(void) write_string_file(t, "change", WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -43,7 +43,7 @@ static int ipv6_proxy_ndp_set(Link *link) {
|
||||
v = ipv6_proxy_ndp_is_needed(link);
|
||||
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/proxy_ndp");
|
||||
|
||||
r = write_string_file(p, one_zero(v), WRITE_STRING_FILE_VERIFY_ON_FAILURE);
|
||||
r = write_string_file(p, one_zero(v), WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot configure proxy NDP for interface: %m");
|
||||
|
||||
|
@ -270,7 +270,7 @@ static int link_enable_ipv6(Link *link) {
|
||||
|
||||
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/disable_ipv6");
|
||||
|
||||
r = write_string_file(p, one_zero(disabled), WRITE_STRING_FILE_VERIFY_ON_FAILURE);
|
||||
r = write_string_file(p, one_zero(disabled), WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot %s IPv6 for interface %s: %m",
|
||||
enable_disable(!disabled), link->ifname);
|
||||
@ -1256,7 +1256,7 @@ static int link_set_proxy_arp(Link *link) {
|
||||
|
||||
p = strjoina("/proc/sys/net/ipv4/conf/", link->ifname, "/proxy_arp");
|
||||
|
||||
r = write_string_file(p, one_zero(link->network->proxy_arp), WRITE_STRING_FILE_VERIFY_ON_FAILURE);
|
||||
r = write_string_file(p, one_zero(link->network->proxy_arp), WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot configure proxy ARP for interface: %m");
|
||||
|
||||
@ -2463,7 +2463,7 @@ static int link_set_ipv4_forward(Link *link) {
|
||||
* primarily to keep IPv4 and IPv6 packet forwarding behaviour
|
||||
* somewhat in sync (see below). */
|
||||
|
||||
r = write_string_file("/proc/sys/net/ipv4/ip_forward", "1", WRITE_STRING_FILE_VERIFY_ON_FAILURE);
|
||||
r = write_string_file("/proc/sys/net/ipv4/ip_forward", "1", WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot turn on IPv4 packet forwarding, ignoring: %m");
|
||||
|
||||
@ -2485,7 +2485,7 @@ static int link_set_ipv6_forward(Link *link) {
|
||||
* same behaviour there and also propagate the setting from
|
||||
* one to all, to keep things simple (see above). */
|
||||
|
||||
r = write_string_file("/proc/sys/net/ipv6/conf/all/forwarding", "1", WRITE_STRING_FILE_VERIFY_ON_FAILURE);
|
||||
r = write_string_file("/proc/sys/net/ipv6/conf/all/forwarding", "1", WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot configure IPv6 packet forwarding, ignoring: %m");
|
||||
|
||||
@ -2505,7 +2505,7 @@ static int link_set_ipv6_privacy_extensions(Link *link) {
|
||||
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/use_tempaddr");
|
||||
xsprintf(buf, "%u", (unsigned) link->network->ipv6_privacy_extensions);
|
||||
|
||||
r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE);
|
||||
r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot configure IPv6 privacy extension for interface: %m");
|
||||
|
||||
@ -2529,7 +2529,7 @@ static int link_set_ipv6_accept_ra(Link *link) {
|
||||
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/accept_ra");
|
||||
|
||||
/* We handle router advertisements ourselves, tell the kernel to GTFO */
|
||||
r = write_string_file(p, "0", WRITE_STRING_FILE_VERIFY_ON_FAILURE);
|
||||
r = write_string_file(p, "0", WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot disable kernel IPv6 accept_ra for interface: %m");
|
||||
|
||||
@ -2557,7 +2557,7 @@ static int link_set_ipv6_dad_transmits(Link *link) {
|
||||
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/dad_transmits");
|
||||
xsprintf(buf, "%i", link->network->ipv6_dad_transmits);
|
||||
|
||||
r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE);
|
||||
r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot set IPv6 dad transmits for interface: %m");
|
||||
|
||||
@ -2585,7 +2585,7 @@ static int link_set_ipv6_hop_limit(Link *link) {
|
||||
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/hop_limit");
|
||||
xsprintf(buf, "%i", link->network->ipv6_hop_limit);
|
||||
|
||||
r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE);
|
||||
r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot set IPv6 hop limit for interface: %m");
|
||||
|
||||
@ -2611,7 +2611,7 @@ static int link_set_ipv6_mtu(Link *link) {
|
||||
|
||||
xsprintf(buf, "%" PRIu32, link->network->ipv6_mtu);
|
||||
|
||||
r = write_string_file(p, buf, 0);
|
||||
r = write_string_file(p, buf, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot set IPv6 MTU for interface: %m");
|
||||
|
||||
|
@ -122,7 +122,7 @@ int sync_cgroup(pid_t pid, CGroupUnified unified_requested, uid_t uid_shift) {
|
||||
(void) mkdir_parents(fn, 0755);
|
||||
|
||||
sprintf(pid_string, PID_FMT, pid);
|
||||
r = write_string_file(fn, pid_string, 0);
|
||||
r = write_string_file(fn, pid_string, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to move process: %m");
|
||||
goto finish;
|
||||
|
@ -2176,7 +2176,7 @@ static int reset_audit_loginuid(void) {
|
||||
if (streq(p, "4294967295"))
|
||||
return 0;
|
||||
|
||||
r = write_string_file("/proc/self/loginuid", "4294967295", 0);
|
||||
r = write_string_file("/proc/self/loginuid", "4294967295", WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0) {
|
||||
log_error_errno(r,
|
||||
"Failed to reset audit login UID. This probably means that your kernel is too\n"
|
||||
@ -3265,13 +3265,13 @@ static int setup_uid_map(pid_t pid) {
|
||||
|
||||
xsprintf(uid_map, "/proc/" PID_FMT "/uid_map", pid);
|
||||
xsprintf(line, UID_FMT " " UID_FMT " " UID_FMT "\n", 0, arg_uid_shift, arg_uid_range);
|
||||
r = write_string_file(uid_map, line, 0);
|
||||
r = write_string_file(uid_map, line, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to write UID map: %m");
|
||||
|
||||
/* We always assign the same UID and GID ranges */
|
||||
xsprintf(uid_map, "/proc/" PID_FMT "/gid_map", pid);
|
||||
r = write_string_file(uid_map, line, 0);
|
||||
r = write_string_file(uid_map, line, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to write GID map: %m");
|
||||
|
||||
|
@ -42,7 +42,7 @@ static int write_hibernate_location_info(void) {
|
||||
|
||||
/* if it's a swap partition, we just write the disk to /sys/power/resume */
|
||||
if (streq(type, "partition")) {
|
||||
r = write_string_file("/sys/power/resume", device, 0);
|
||||
r = write_string_file("/sys/power/resume", device, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Faileed to write partitoin device to /sys/power/resume: %m");
|
||||
|
||||
@ -80,12 +80,12 @@ static int write_hibernate_location_info(void) {
|
||||
|
||||
offset = fiemap->fm_extents[0].fe_physical / page_size();
|
||||
xsprintf(offset_str, "%" PRIu64, offset);
|
||||
r = write_string_file("/sys/power/resume_offset", offset_str, 0);
|
||||
r = write_string_file("/sys/power/resume_offset", offset_str, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to write offset '%s': %m", offset_str);
|
||||
|
||||
xsprintf(device_str, "%lx", (unsigned long)stb.st_dev);
|
||||
r = write_string_file("/sys/power/resume", device_str, 0);
|
||||
r = write_string_file("/sys/power/resume", device_str, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to write device '%s': %m", device_str);
|
||||
|
||||
@ -99,7 +99,7 @@ static int write_mode(char **modes) {
|
||||
STRV_FOREACH(mode, modes) {
|
||||
int k;
|
||||
|
||||
k = write_string_file("/sys/power/disk", *mode, 0);
|
||||
k = write_string_file("/sys/power/disk", *mode, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (k >= 0)
|
||||
return 0;
|
||||
|
||||
@ -118,7 +118,7 @@ static int write_state(FILE **f, char **states) {
|
||||
STRV_FOREACH(state, states) {
|
||||
int k;
|
||||
|
||||
k = write_string_stream(*f, *state, 0);
|
||||
k = write_string_stream(*f, *state, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (k >= 0)
|
||||
return 0;
|
||||
log_debug_errno(k, "Failed to write '%s' to /sys/power/state: %m", *state);
|
||||
@ -155,6 +155,8 @@ static int execute(char **modes, char **states) {
|
||||
if (!f)
|
||||
return log_error_errno(errno, "Failed to open /sys/power/state: %m");
|
||||
|
||||
setvbuf(f, NULL, _IONBF, 0);
|
||||
|
||||
/* Configure the hibernation mode */
|
||||
if (!strv_isempty(modes)) {
|
||||
r = write_hibernate_location_info();
|
||||
@ -211,7 +213,7 @@ static int rtc_write_wake_alarm(uint64_t sec) {
|
||||
|
||||
xsprintf(buf, "%" PRIu64, sec);
|
||||
|
||||
r = write_string_file("/sys/class/rtc/rtc0/wakealarm", buf, 0);
|
||||
r = write_string_file("/sys/class/rtc/rtc0/wakealarm", buf, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to write '%s' to /sys/class/rtc/rtc0/wakealarm: %m", buf);
|
||||
|
||||
|
@ -1123,7 +1123,7 @@ static int synthesize_change(sd_device *dev) {
|
||||
*/
|
||||
log_debug("Device '%s' is closed, synthesising 'change'", devname);
|
||||
strscpyl(filename, sizeof(filename), syspath, "/uevent", NULL);
|
||||
write_string_file(filename, "change", WRITE_STRING_FILE_CREATE);
|
||||
write_string_file(filename, "change", WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
|
||||
FOREACH_DEVICE(e, d) {
|
||||
const char *t, *n, *s;
|
||||
@ -1138,7 +1138,7 @@ static int synthesize_change(sd_device *dev) {
|
||||
|
||||
log_debug("Device '%s' is closed, synthesising partition '%s' 'change'", devname, n);
|
||||
strscpyl(filename, sizeof(filename), s, "/uevent", NULL);
|
||||
write_string_file(filename, "change", WRITE_STRING_FILE_CREATE);
|
||||
write_string_file(filename, "change", WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -1146,7 +1146,7 @@ static int synthesize_change(sd_device *dev) {
|
||||
|
||||
log_debug("Device %s is closed, synthesising 'change'", devname);
|
||||
strscpyl(filename, sizeof(filename), syspath, "/uevent", NULL);
|
||||
write_string_file(filename, "change", WRITE_STRING_FILE_CREATE);
|
||||
write_string_file(filename, "change", WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ static int toggle_utf8(const char *name, int fd, bool utf8) {
|
||||
static int toggle_utf8_sysfs(bool utf8) {
|
||||
int r;
|
||||
|
||||
r = write_string_file("/sys/module/vt/parameters/default_utf8", one_zero(utf8), 0);
|
||||
r = write_string_file("/sys/module/vt/parameters/default_utf8", one_zero(utf8), WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
if (r < 0)
|
||||
return log_warning_errno(r, "Failed to %s sysfs UTF-8 flag: %m", enable_disable(utf8));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user