tree-wide: fix write_string_file() user that should not create files

The latest consolidation cleanup of write_string_file() revealed some users
of that helper which should have used write_string_file_no_create() in the
past but didn't. Basically, all existing users that write to files in /sys
and /proc should not expect to write to a file which is not yet existant.
This commit is contained in:
Daniel Mack 2015-07-06 19:27:20 -04:00
parent 4c1fc3e404
commit ad118bda15
7 changed files with 11 additions and 11 deletions

View file

@ -139,7 +139,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, WRITE_STRING_FILE_CREATE);
r = write_string_file(p, label, 0);
if (r < 0)
return r;
#endif

View file

@ -191,7 +191,7 @@ int main(int argc, char *argv[]) {
}
/* Flush out all rules */
write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", WRITE_STRING_FILE_CREATE);
write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", 0);
STRV_FOREACH(f, files) {
k = apply_file(*f, true);

View file

@ -1446,7 +1446,7 @@ static int exec_child(
* shouldn't trip up over that. */
sprintf(t, "%i", context->oom_score_adjust);
r = write_string_file("/proc/self/oom_score_adj", t, WRITE_STRING_FILE_CREATE);
r = write_string_file("/proc/self/oom_score_adj", t, 0);
if (r == -EPERM || r == -EACCES) {
log_open();
log_unit_debug_errno(unit, r, "Failed to adjust OOM setting, assuming containerized execution, ignoring: %m");

View file

@ -2508,7 +2508,7 @@ static int reset_audit_loginuid(void) {
if (streq(p, "4294967295"))
return 0;
r = write_string_file("/proc/self/loginuid", "4294967295", WRITE_STRING_FILE_CREATE);
r = write_string_file("/proc/self/loginuid", "4294967295", 0);
if (r < 0) {
log_error_errno(r,
"Failed to reset audit login UID. This probably means that your kernel is too\n"
@ -4448,13 +4448,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, WRITE_STRING_FILE_CREATE);
r = write_string_file(uid_map, line, 0);
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, WRITE_STRING_FILE_CREATE);
r = write_string_file(uid_map, line, 0);
if (r < 0)
return log_error_errno(r, "Failed to write GID map: %m");

View file

@ -66,7 +66,7 @@ int sysctl_write(const char *property, const char *value) {
log_debug("Setting '%s' to '%s'", property, value);
p = strjoina("/proc/sys/", property);
return write_string_file(p, value, WRITE_STRING_FILE_CREATE);
return write_string_file(p, value, 0);
}
int sysctl_read(const char *property, char **content) {

View file

@ -398,7 +398,7 @@ static void worker_spawn(Manager *manager, struct event *event) {
prctl(PR_SET_PDEATHSIG, SIGTERM);
/* reset OOM score, we only protect the main daemon */
write_string_file("/proc/self/oom_score_adj", "0", WRITE_STRING_FILE_CREATE);
write_string_file("/proc/self/oom_score_adj", "0", 0);
for (;;) {
struct udev_event *udev_event;
@ -1747,7 +1747,7 @@ int main(int argc, char *argv[]) {
setsid();
write_string_file("/proc/self/oom_score_adj", "-1000", WRITE_STRING_FILE_CREATE);
write_string_file("/proc/self/oom_score_adj", "-1000", 0);
}
r = run(fd_ctrl, fd_uevent, cgroup);

View file

@ -56,7 +56,7 @@ static int disable_utf8(int fd) {
if (k < 0)
r = k;
k = write_string_file("/sys/module/vt/parameters/default_utf8", "0", WRITE_STRING_FILE_CREATE);
k = write_string_file("/sys/module/vt/parameters/default_utf8", "0", 0);
if (k < 0)
r = k;
@ -89,7 +89,7 @@ static int enable_utf8(int fd) {
if (k < 0)
r = k;
k = write_string_file("/sys/module/vt/parameters/default_utf8", "1", WRITE_STRING_FILE_CREATE);
k = write_string_file("/sys/module/vt/parameters/default_utf8", "1", 0);
if (k < 0)
r = k;