chiark / gitweb /
util: rename write_one_line_file() to write_string_file()
authorLennart Poettering <lennart@poettering.net>
Tue, 2 Apr 2013 18:31:42 +0000 (20:31 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 3 Apr 2013 18:12:56 +0000 (20:12 +0200)
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:
src/binfmt/binfmt.c
src/core/cgroup-attr.c
src/core/execute.c
src/core/machine-id-setup.c
src/core/unit.c
src/hostname/hostnamed.c
src/login/logind-dbus.c
src/login/user-sessions.c
src/nspawn/nspawn.c
src/readahead/readahead-common.c
src/shared/capability.c
src/shared/cgroup-util.c
src/shared/fileio-label.c
src/shared/fileio-label.h
src/shared/fileio.c
src/shared/fileio.h
src/shutdownd/shutdownd.c
src/sleep/sleep.c
src/sysctl/sysctl.c
src/timedate/timedated.c
src/udev/udevd.c
src/vconsole/vconsole-setup.c

index 909eef732c14485c1b5c781de121c16d5ad37a24..9ca1e604c498aa095fda3200d41af79c8f90406c 100644 (file)
@@ -62,7 +62,7 @@ static int delete_rule(const char *rule) {
         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) {
@@ -70,7 +70,7 @@ static int apply_rule(const char *rule) {
 
         delete_rule(rule);
 
 
         delete_rule(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;
@@ -197,7 +197,7 @@ int main(int argc, char *argv[]) {
                 }
 
                 /* 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);
index 2ab4d4623e1870b9218ebeedba3fb81b56f384d1..7e3e08eabb2e952d2700580bbb7d81ee557f88b3 100644 (file)
@@ -44,7 +44,7 @@ int cgroup_attribute_apply(CGroupAttribute *a, CGroupBonding *b) {
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
-        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));
 
index f7353579e9ff4fa517c8d3e19ed1ace52618b7dd..91815b838e374ab5cea304f2872012137f4d1a63 100644 (file)
@@ -1195,7 +1195,7 @@ int exec_spawn(ExecCommand *command,
                         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;
index 146c5653c96af4b91ac12ed5b268684429136c3a..51074fea449058b5433f1c80adb10e06a659f2ea 100644 (file)
@@ -216,7 +216,7 @@ int machine_id_setup(void) {
          * /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);
         umask(m);
 
         if (r < 0) {
         umask(m);
 
         if (r < 0) {
index 91a00edf7196ab58dfcee3f03099102d31dcc895..a0d36569a885f93f486f04e59aafdd30dfd7b279 100644 (file)
@@ -2910,7 +2910,7 @@ int unit_write_drop_in(Unit *u, bool runtime, const char *name, const char *data
                 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) {
index 859b5a07845400ce1bd86523f642422415802d53..b4d6d51402c71b7c84344ef452030302c8e07979 100644 (file)
@@ -289,7 +289,7 @@ static int write_data_static_hostname(void) {
 
                 return 0;
         }
 
                 return 0;
         }
-        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) {
index 4ae8362211122b094ac3056c9c2bf789cf8f9d26..aa212d1fedfb4591ad96530cbf9f4ca2ccc4dd55 100644 (file)
@@ -886,7 +886,7 @@ static int trigger_device(Manager *m, struct udev_device *d) {
                         goto finish;
                 }
 
                         goto finish;
                 }
 
-                write_one_line_file(t, "change");
+                write_string_file(t, "change");
                 free(t);
         }
 
                 free(t);
         }
 
@@ -936,7 +936,7 @@ static int attach_device(Manager *m, const char *seat, const char *sysfs) {
 
         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);
         if (r < 0)
                 goto finish;
 
         if (r < 0)
                 goto finish;
 
index c6f8fa79e2ddb649b923e352a7eaadedb7f49a90..41d32044e976e3e58cbbe75f514738043e2e6548 100644 (file)
@@ -70,7 +70,7 @@ int main(int argc, char*argv[]) {
                 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));
 
index b8b692b47462929f6b2fe75992141f290b48705d..01ef12bf67bbbf0dda4095bad7d2bb037988dd15 100644 (file)
@@ -528,7 +528,7 @@ static int setup_boot_id(const char *dest) {
                  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;
index 81bb16c7a3c81319fe7f0735dee872de1967a68b..ed81c14d896647a1af425312a5c9866fd0323666 100644 (file)
@@ -316,7 +316,7 @@ int block_bump_request_nr(const char *p) {
                 goto finish;
         }
 
                 goto finish;
         }
 
-        r = write_one_line_file(ap, line);
+        r = write_string_file(ap, line);
         if (r < 0)
                 goto finish;
 
         if (r < 0)
                 goto finish;
 
@@ -399,7 +399,7 @@ int block_set_readahead(const char *p, uint64_t bytes) {
                 goto finish;
         }
 
                 goto finish;
         }
 
-        r = write_one_line_file(ap, line);
+        r = write_string_file(ap, line);
         if (r < 0)
                 goto finish;
 
         if (r < 0)
                 goto finish;
 
index cad718d749959e839616ce05ea8ec2fe2763f629..321952067d71469c3e9c683ff85c191695dac730 100644 (file)
@@ -204,7 +204,7 @@ static int drop_from_file(const char *fn, uint64_t drop) {
         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);
         free(p);
 
         return r;
         free(p);
 
         return r;
index be00b40fa2346afb2ebf43ab6847d4d61a025f6f..15e1b7c055331279e1ff471826cb4565e39d5b70 100644 (file)
@@ -677,9 +677,9 @@ int cg_delete(const char *controller, const char *path) {
 }
 
 int cg_attach(const char *controller, const char *path, pid_t pid) {
 }
 
 int cg_attach(const char *controller, const char *path, pid_t pid) {
-        char *fs;
+        _cleanup_free_ char *fs = NULL;
+        char c[DECIMAL_STR_MAX(pid_t) + 2];
         int r;
         int r;
-        char c[32];
 
         assert(controller);
         assert(path);
 
         assert(controller);
         assert(path);
@@ -693,16 +693,12 @@ int cg_attach(const char *controller, const char *path, pid_t pid) {
                 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 r;
+        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) {
-        char *fs;
+        _cleanup_free_ char *fs = NULL;
         int r;
 
         assert(controller);
         int r;
 
         assert(controller);
@@ -715,10 +711,7 @@ int cg_set_group_access(const char *controller, const char *path, mode_t mode, u
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
-        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) {
@@ -857,7 +850,8 @@ int cg_install_release_agent(const char *controller, const char *agent) {
                         goto finish;
                 }
 
                         goto finish;
                 }
 
-                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)) {
@@ -878,7 +872,7 @@ int cg_install_release_agent(const char *controller, const char *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)
                         goto finish;
 
                 r = 1;
                         goto finish;
 
                 r = 1;
index 5bf127bcf19f6c713c341fc101b4b457760664ef..0711826e85915fc067e96550667a68ac70fdda09 100644 (file)
 #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);
 
         label_context_clear();
 
 
         label_context_clear();
 
index cc5ce347083cc556a6eb0aa7cd20df5dc5460315..fce4fe0d73eb12045b17310e95139cb86bae21c4 100644 (file)
@@ -25,5 +25,5 @@
 #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);
index 1c7d4851303af7ba9caae54809dc83207c8d55a5..5b8be5ce2d38ed0181c2c8834512ab4c499941de 100644 (file)
@@ -24,7 +24,7 @@
 #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);
@@ -49,7 +49,7 @@ int write_one_line_file(const char *fn, const char *line) {
         return 0;
 }
 
         return 0;
 }
 
-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;
index 0023204a73b558b686c38162b1365c409c79ea63..612968b93d09e84ec0b5bfb29214617b223aa021 100644 (file)
@@ -23,8 +23,8 @@
 #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);
 
index 119385d67fb3c586baaf9cbc88aaf2410e124ac5..ee2a328b4eb311807402ca859e65fffba59ee552 100644 (file)
@@ -421,7 +421,7 @@ int main(int argc, char *argv[]) {
 
                         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
index 070762546bbb1c435824ea658a31641bb5a11770..f5e78c13c60a56947f92f09ed82f9b79ba9e861d 100644 (file)
@@ -57,12 +57,12 @@ int main(int argc, char *argv[]) {
 
         /* 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");
index 79f3f77676c81efdf3cc584123d9131e23402d0d..e0ba78a2fe240ea13df2bc4eb384f5c53638a46d 100644 (file)
@@ -88,7 +88,7 @@ static int apply_sysctl(const char *property, const char *value) {
                 }
         }
 
                 }
         }
 
-        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));
index 1d4d73911e20362b5674160333a0e797fa8ef5bb..e068724903f57bd85758c77f919cdd3e95b1e079 100644 (file)
@@ -275,7 +275,7 @@ static int write_data_local_rtc(void) {
                 }
         }
         label_init("/etc");
                 }
         }
         label_init("/etc");
-        r = write_one_line_file_atomic_label("/etc/adjtime", w);
+        r = write_string_file_atomic_label("/etc/adjtime", w);
         free(w);
 
         return r;
         free(w);
 
         return r;
index 42cf994b0d8d7887cf9aafb8316e5d4e00d3db75..2d9093d741c4780d4f5e17eadfb609ea4bdcb4b3 100644 (file)
@@ -267,7 +267,7 @@ static void worker_new(struct event *event)
                 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;
@@ -1168,7 +1168,7 @@ int main(int argc, char *argv[])
 
                 setsid();
 
 
                 setsid();
 
-                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");
         }
index e11fd589cb3a89a2f005097604bfe8f1dd459af6..84d7c5cba223d50ef2d5e398a4f1aae1e8537707 100644 (file)
@@ -57,7 +57,7 @@ static int disable_utf8(int fd) {
         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 (k < 0)
                 r = k;
 
         if (k < 0)
                 r = k;
 
@@ -89,7 +89,7 @@ static int enable_utf8(int fd) {
         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");
         if (k < 0)
                 r = k;
 
         if (k < 0)
                 r = k;