You can write much more than just one line with this call (and we
frequently do), so let's correct the naming.
22 files changed:
if (!fn)
return log_oom();
if (!fn)
return log_oom();
- return write_one_line_file(fn, "-1");
+ return write_string_file(fn, "-1");
}
static int apply_rule(const char *rule) {
}
static int apply_rule(const char *rule) {
- r = write_one_line_file("/proc/sys/fs/binfmt_misc/register", rule);
+ r = write_string_file("/proc/sys/fs/binfmt_misc/register", rule);
if (r < 0) {
log_error("Failed to add binary format: %s", strerror(-r));
return r;
if (r < 0) {
log_error("Failed to add binary format: %s", strerror(-r));
return r;
}
/* Flush out all rules */
}
/* Flush out all rules */
- write_one_line_file("/proc/sys/fs/binfmt_misc/status", "-1");
+ write_string_file("/proc/sys/fs/binfmt_misc/status", "-1");
STRV_FOREACH(f, files) {
k = apply_file(*f, true);
STRV_FOREACH(f, files) {
k = apply_file(*f, true);
- r = write_one_line_file(path, v ? v : a->value);
+ r = write_string_file(path, v ? v : a->value);
if (r < 0)
log_warning("Failed to write '%s' to %s: %s", v ? v : a->value, path, strerror(-r));
if (r < 0)
log_warning("Failed to write '%s' to %s: %s", v ? v : a->value, path, strerror(-r));
snprintf(t, sizeof(t), "%i", context->oom_score_adjust);
char_array_0(t);
snprintf(t, sizeof(t), "%i", context->oom_score_adjust);
char_array_0(t);
- if (write_one_line_file("/proc/self/oom_score_adj", t) < 0) {
+ if (write_string_file("/proc/self/oom_score_adj", t) < 0) {
err = -errno;
r = EXIT_OOM_ADJUST;
goto fail_child;
err = -errno;
r = EXIT_OOM_ADJUST;
goto fail_child;
* /run/machine-id as a replacement */
m = umask(0022);
* /run/machine-id as a replacement */
m = umask(0022);
- r = write_one_line_file("/run/machine-id", id);
+ r = write_string_file("/run/machine-id", id);
return r;
mkdir_p(p, 0755);
return r;
mkdir_p(p, 0755);
- return write_one_line_file_atomic_label(q, data);
+ return write_string_file_atomic_label(q, data);
}
int unit_remove_drop_in(Unit *u, bool runtime, const char *name) {
}
int unit_remove_drop_in(Unit *u, bool runtime, const char *name) {
- return write_one_line_file_atomic_label("/etc/hostname", data[PROP_STATIC_HOSTNAME]);
+ return write_string_file_atomic_label("/etc/hostname", data[PROP_STATIC_HOSTNAME]);
}
static int write_data_other(void) {
}
static int write_data_other(void) {
- write_one_line_file(t, "change");
+ write_string_file(t, "change");
mkdir_p_label("/etc/udev/rules.d", 0755);
label_init("/etc");
mkdir_p_label("/etc/udev/rules.d", 0755);
label_init("/etc");
- r = write_one_line_file_atomic_label(file, rule);
+ r = write_string_file_atomic_label(file, rule);
int r, q;
char *cgroup_user_tree = NULL;
int r, q;
char *cgroup_user_tree = NULL;
- r = write_one_line_file_atomic("/run/nologin", "System is going down.");
+ r = write_string_file_atomic("/run/nologin", "System is going down.");
if (r < 0)
log_error("Failed to create /run/nologin: %s", strerror(-r));
if (r < 0)
log_error("Failed to create /run/nologin: %s", strerror(-r));
SD_ID128_FORMAT_VAL(rnd));
char_array_0(as_uuid);
SD_ID128_FORMAT_VAL(rnd));
char_array_0(as_uuid);
- r = write_one_line_file(from, as_uuid);
+ r = write_string_file(from, as_uuid);
if (r < 0) {
log_error("Failed to write boot id: %s", strerror(-r));
return r;
if (r < 0) {
log_error("Failed to write boot id: %s", strerror(-r));
return r;
- r = write_one_line_file(ap, line);
+ r = write_string_file(ap, line);
- r = write_one_line_file(ap, line);
+ r = write_string_file(ap, line);
if (asprintf(&p, "%u %u", lo, hi) < 0)
return -ENOMEM;
if (asprintf(&p, "%u %u", lo, hi) < 0)
return -ENOMEM;
- r = write_one_line_file(fn, p);
+ r = write_string_file(fn, p);
}
int cg_attach(const char *controller, const char *path, pid_t pid) {
}
int cg_attach(const char *controller, const char *path, pid_t pid) {
+ _cleanup_free_ char *fs = NULL;
+ char c[DECIMAL_STR_MAX(pid_t) + 2];
assert(controller);
assert(path);
assert(controller);
assert(path);
pid = getpid();
snprintf(c, sizeof(c), "%lu\n", (unsigned long) pid);
pid = getpid();
snprintf(c, sizeof(c), "%lu\n", (unsigned long) pid);
- char_array_0(c);
-
- r = write_one_line_file(fs, c);
- free(fs);
+ return write_string_file(fs, c);
}
int cg_set_group_access(const char *controller, const char *path, mode_t mode, uid_t uid, gid_t gid) {
}
int cg_set_group_access(const char *controller, const char *path, mode_t mode, uid_t uid, gid_t gid) {
+ _cleanup_free_ char *fs = NULL;
int r;
assert(controller);
int r;
assert(controller);
- r = chmod_and_chown(fs, mode, uid, gid);
- free(fs);
-
- return r;
+ return chmod_and_chown(fs, mode, uid, gid);
}
int cg_set_task_access(const char *controller, const char *path, mode_t mode, uid_t uid, gid_t gid, int sticky) {
}
int cg_set_task_access(const char *controller, const char *path, mode_t mode, uid_t uid, gid_t gid, int sticky) {
- if ((r = write_one_line_file(fs, line)) < 0)
+ r = write_string_file(fs, line);
+ if (r < 0)
goto finish;
} else if (!streq(sc, agent)) {
goto finish;
} else if (!streq(sc, agent)) {
sc = strstrip(contents);
if (streq(sc, "0")) {
sc = strstrip(contents);
if (streq(sc, "0")) {
- if ((r = write_one_line_file(fs, "1\n")) < 0)
+ if ((r = write_string_file(fs, "1\n")) < 0)
#include "fileio-label.h"
#include "label.h"
#include "fileio-label.h"
#include "label.h"
-int write_one_line_file_atomic_label(const char *fn, const char *line) {
+int write_string_file_atomic_label(const char *fn, const char *line) {
int r;
r = label_context_set(fn, S_IFREG);
if (r < 0)
return r;
int r;
r = label_context_set(fn, S_IFREG);
if (r < 0)
return r;
- write_one_line_file_atomic(fn, line);
+ write_string_file_atomic(fn, line);
#include <stdio.h>
#include "fileio.h"
#include <stdio.h>
#include "fileio.h"
-int write_one_line_file_atomic_label(const char *fn, const char *line);
+int write_string_file_atomic_label(const char *fn, const char *line);
int write_env_file_label(const char *fname, char **l);
int write_env_file_label(const char *fname, char **l);
#include "util.h"
#include "strv.h"
#include "util.h"
#include "strv.h"
-int write_one_line_file(const char *fn, const char *line) {
+int write_string_file(const char *fn, const char *line) {
_cleanup_fclose_ FILE *f = NULL;
assert(fn);
_cleanup_fclose_ FILE *f = NULL;
assert(fn);
-int write_one_line_file_atomic(const char *fn, const char *line) {
+int write_string_file_atomic(const char *fn, const char *line) {
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *p = NULL;
int r;
_cleanup_fclose_ FILE *f = NULL;
_cleanup_free_ char *p = NULL;
int r;
#include <stddef.h>
#include "macro.h"
#include <stddef.h>
#include "macro.h"
-int write_one_line_file(const char *fn, const char *line);
-int write_one_line_file_atomic(const char *fn, const char *line);
+int write_string_file(const char *fn, const char *line);
+int write_string_file_atomic(const char *fn, const char *line);
int read_one_line_file(const char *fn, char **line);
int read_full_file(const char *fn, char **contents, size_t *size);
int read_one_line_file(const char *fn, char **line);
int read_full_file(const char *fn, char **contents, size_t *size);
log_info("Creating /run/nologin, blocking further logins...");
log_info("Creating /run/nologin, blocking further logins...");
- e = write_one_line_file_atomic("/run/nologin", "System is going down.");
+ e = write_string_file_atomic("/run/nologin", "System is going down.");
if (e < 0)
log_error("Failed to create /run/nologin: %s", strerror(-e));
else
if (e < 0)
log_error("Failed to create /run/nologin: %s", strerror(-e));
else
/* Configure the hibernation mode */
if (streq(argv[1], "hibernate")) {
/* Configure the hibernation mode */
if (streq(argv[1], "hibernate")) {
- if (write_one_line_file("/sys/power/disk", "platform") < 0)
- write_one_line_file("/sys/power/disk", "shutdown");
+ if (write_string_file("/sys/power/disk", "platform") < 0)
+ write_string_file("/sys/power/disk", "shutdown");
} else if (streq(argv[1], "hybrid-sleep")) {
} else if (streq(argv[1], "hybrid-sleep")) {
- if (write_one_line_file("/sys/power/disk", "suspend") < 0)
- if (write_one_line_file("/sys/power/disk", "platform") < 0)
- write_one_line_file("/sys/power/disk", "shutdown");
+ if (write_string_file("/sys/power/disk", "suspend") < 0)
+ if (write_string_file("/sys/power/disk", "platform") < 0)
+ write_string_file("/sys/power/disk", "shutdown");
}
f = fopen("/sys/power/state", "we");
}
f = fopen("/sys/power/state", "we");
- k = write_one_line_file(p, value);
+ k = write_string_file(p, value);
if (k < 0) {
log_full(k == -ENOENT ? LOG_DEBUG : LOG_WARNING,
"Failed to write '%s' to '%s': %s", value, p, strerror(-k));
if (k < 0) {
log_full(k == -ENOENT ? LOG_DEBUG : LOG_WARNING,
"Failed to write '%s' to '%s': %s", value, p, strerror(-k));
- r = write_one_line_file_atomic_label("/etc/adjtime", w);
+ r = write_string_file_atomic_label("/etc/adjtime", w);
prctl(PR_SET_PDEATHSIG, SIGTERM);
/* reset OOM score, we only protect the main daemon */
prctl(PR_SET_PDEATHSIG, SIGTERM);
/* reset OOM score, we only protect the main daemon */
- write_one_line_file("/proc/self/oom_score_adj", "0");
+ write_string_file("/proc/self/oom_score_adj", "0");
for (;;) {
struct udev_event *udev_event;
for (;;) {
struct udev_event *udev_event;
- write_one_line_file("/proc/self/oom_score_adj", "-1000");
+ write_string_file("/proc/self/oom_score_adj", "-1000");
} else {
sd_notify(1, "READY=1");
}
} else {
sd_notify(1, "READY=1");
}
if (loop_write(fd, "\033%@", 3, false) < 0)
r = -errno;
if (loop_write(fd, "\033%@", 3, false) < 0)
r = -errno;
- k = write_one_line_file("/sys/module/vt/parameters/default_utf8", "0");
+ k = write_string_file("/sys/module/vt/parameters/default_utf8", "0");
if (loop_write(fd, "\033%G", 3, false) < 0)
r = -errno;
if (loop_write(fd, "\033%G", 3, false) < 0)
r = -errno;
- k = write_one_line_file("/sys/module/vt/parameters/default_utf8", "1");
+ k = write_string_file("/sys/module/vt/parameters/default_utf8", "1");