summaryrefslogtreecommitdiff
path: root/src/core/socket.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-10-01 14:28:13 +0200
committerLennart Poettering <lennart@poettering.net>2015-10-01 14:28:13 +0200
commit55301ec028937eab4722c9fd586fd77ffdbc50dd (patch)
treec329e5846069c3f80c8facfc17d604878081fabe /src/core/socket.c
parent7e9d36e06b85d87eb2c3aed507fe3aa1574c7880 (diff)
core: add new setting Writable= to ListenSpecial= socket units
Writable= is a new boolean setting. If ture, then ListenSpecial= will open the specified path in O_RDWR mode, rather than just O_RDONLY. This is useful for implementing services like rfkill, where /dev/rfkill is more useful when opened in write mode, if we want to not only save but also restore its state.
Diffstat (limited to 'src/core/socket.c')
-rw-r--r--src/core/socket.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/core/socket.c b/src/core/socket.c
index a0b5bba1b9..3250e7efc6 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -507,6 +507,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
"%sPassSecurity: %s\n"
"%sTCPCongestion: %s\n"
"%sRemoveOnStop: %s\n"
+ "%sWritable: %s\n"
"%sSELinuxContextFromNet: %s\n",
prefix, socket_state_to_string(s->state),
prefix, socket_result_to_string(s->result),
@@ -523,6 +524,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
prefix, yes_no(s->pass_sec),
prefix, strna(s->tcp_congestion),
prefix, yes_no(s->remove_on_stop),
+ prefix, yes_no(s->writable),
prefix, yes_no(s->selinux_context_from_net));
if (s->control_pid > 0)
@@ -1031,14 +1033,14 @@ fail:
return r;
}
-static int special_address_create(const char *path) {
+static int special_address_create(const char *path, bool writable) {
_cleanup_close_ int fd = -1;
struct stat st;
int r;
assert(path);
- fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW);
+ fd = open(path, (writable ? O_RDWR : O_RDONLY)|O_CLOEXEC|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW);
if (fd < 0)
return -errno;
@@ -1280,7 +1282,7 @@ static int socket_open_fds(Socket *s) {
case SOCKET_SPECIAL:
- p->fd = special_address_create(p->path);
+ p->fd = special_address_create(p->path, s->writable);
if (p->fd < 0) {
r = p->fd;
goto rollback;