summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-04-02 20:31:42 +0200
committerLennart Poettering <lennart@poettering.net>2013-04-03 20:12:56 +0200
commit574d5f2dfc25226afc718aa5ba1a145fe5cad221 (patch)
tree01fc6b70bd622d40da1c60fd04d1f15c85aebd93 /src/shared
parentb6e8f1f03dc8b7579f8c6b00372f136d74c45232 (diff)
util: rename write_one_line_file() to write_string_file()
You can write much more than just one line with this call (and we frequently do), so let's correct the naming.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/capability.c2
-rw-r--r--src/shared/cgroup-util.c22
-rw-r--r--src/shared/fileio-label.c4
-rw-r--r--src/shared/fileio-label.h2
-rw-r--r--src/shared/fileio.c4
-rw-r--r--src/shared/fileio.h4
6 files changed, 16 insertions, 22 deletions
diff --git a/src/shared/capability.c b/src/shared/capability.c
index cad718d749..321952067d 100644
--- a/src/shared/capability.c
+++ b/src/shared/capability.c
@@ -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;
- r = write_one_line_file(fn, p);
+ r = write_string_file(fn, p);
free(p);
return r;
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index be00b40fa2..15e1b7c055 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -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) {
- char *fs;
+ _cleanup_free_ char *fs = NULL;
+ char c[DECIMAL_STR_MAX(pid_t) + 2];
int r;
- char c[32];
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);
- 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) {
- char *fs;
+ _cleanup_free_ char *fs = NULL;
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;
- 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) {
@@ -857,7 +850,8 @@ int cg_install_release_agent(const char *controller, const char *agent) {
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)) {
@@ -878,7 +872,7 @@ int cg_install_release_agent(const char *controller, const char *agent) {
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;
diff --git a/src/shared/fileio-label.c b/src/shared/fileio-label.c
index 5bf127bcf1..0711826e85 100644
--- a/src/shared/fileio-label.c
+++ b/src/shared/fileio-label.c
@@ -26,14 +26,14 @@
#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;
- write_one_line_file_atomic(fn, line);
+ write_string_file_atomic(fn, line);
label_context_clear();
diff --git a/src/shared/fileio-label.h b/src/shared/fileio-label.h
index cc5ce34708..fce4fe0d73 100644
--- a/src/shared/fileio-label.h
+++ b/src/shared/fileio-label.h
@@ -25,5 +25,5 @@
#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);
diff --git a/src/shared/fileio.c b/src/shared/fileio.c
index 1c7d485130..5b8be5ce2d 100644
--- a/src/shared/fileio.c
+++ b/src/shared/fileio.c
@@ -24,7 +24,7 @@
#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);
@@ -49,7 +49,7 @@ int write_one_line_file(const char *fn, const char *line) {
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;
diff --git a/src/shared/fileio.h b/src/shared/fileio.h
index 0023204a73..612968b93d 100644
--- a/src/shared/fileio.h
+++ b/src/shared/fileio.h
@@ -23,8 +23,8 @@
#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);