]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/sysctl-util.c
tree-wide: remove Emacs lines from all files
[thirdparty/systemd.git] / src / shared / sysctl-util.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2010 Lennart Poettering
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include <stdio.h>
21 #include <string.h>
22
23 #include "fileio.h"
24 #include "log.h"
25 #include "macro.h"
26 #include "string-util.h"
27 #include "sysctl-util.h"
28
29 char *sysctl_normalize(char *s) {
30 char *n;
31
32 n = strpbrk(s, "/.");
33 /* If the first separator is a slash, the path is
34 * assumed to be normalized and slashes remain slashes
35 * and dots remains dots. */
36 if (!n || *n == '/')
37 return s;
38
39 /* Otherwise, dots become slashes and slashes become
40 * dots. Fun. */
41 while (n) {
42 if (*n == '.')
43 *n = '/';
44 else
45 *n = '.';
46
47 n = strpbrk(n + 1, "/.");
48 }
49
50 return s;
51 }
52
53 int sysctl_write(const char *property, const char *value) {
54 char *p;
55
56 assert(property);
57 assert(value);
58
59 log_debug("Setting '%s' to '%s'", property, value);
60
61 p = strjoina("/proc/sys/", property);
62 return write_string_file(p, value, 0);
63 }
64
65 int sysctl_read(const char *property, char **content) {
66 char *p;
67
68 assert(property);
69 assert(content);
70
71 p = strjoina("/proc/sys/", property);
72 return read_full_file(p, content, NULL);
73 }