chiark / gitweb /
util: add various utility calls
[elogind.git] / socket.c
index dd5076552020e9a79918e06f2afcd2873fed2a78..b979e58d390fb9f18e0a3e1cce45d2f45ac97ee9 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -1,5 +1,24 @@
 /*-*- Mode: C; c-basic-offset: 8 -*-*/
 
+/***
+  This file is part of systemd.
+
+  Copyright 2010 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -86,6 +105,8 @@ static int socket_init(Unit *u) {
         s->bind_ipv6_only = false;
         s->backlog = SOMAXCONN;
         s->timeout_usec = DEFAULT_TIMEOUT_USEC;
+        s->directory_mode = 0755;
+        s->socket_mode = 0666;
         exec_context_init(&s->exec_context);
 
         if ((r = unit_load_fragment_and_dropin(u)) <= 0) {
@@ -140,22 +161,26 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
         SocketExecCommand c;
         Socket *s = SOCKET(u);
         SocketPort *p;
-        char *prefix2;
+        const char *prefix2;
+        char *p2;
 
         assert(s);
         assert(f);
 
-        prefix2 = strappend(prefix, "\t");
-        if (!prefix2)
-                prefix2 = "";
+        p2 = strappend(prefix, "\t");
+        prefix2 = p2 ? p2 : prefix;
 
         fprintf(f,
                 "%sSocket State: %s\n"
                 "%sBindIPv6Only: %s\n"
-                "%sBacklog: %u\n",
+                "%sBacklog: %u\n"
+                "%sSocketMode: %04o\n"
+                "%sDirectoryMode: %04o\n",
                 prefix, state_string_table[s->state],
                 prefix, yes_no(s->bind_ipv6_only),
-                prefix, s->backlog);
+                prefix, s->backlog,
+                prefix, s->socket_mode,
+                prefix, s->directory_mode);
 
         if (s->bind_to_device)
                 fprintf(f,
@@ -192,7 +217,7 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
                 exec_command_dump_list(s->exec_command[c], f, prefix2);
         }
 
-        free(prefix2);
+        free(p2);
 }
 
 static void socket_close_fds(Socket *s) {
@@ -224,7 +249,14 @@ static int socket_open_fds(Socket *s) {
 
                 if (p->type == SOCKET_SOCKET) {
 
-                        if ((r = socket_address_listen(&p->address, s->backlog, s->bind_ipv6_only, s->bind_to_device, &p->fd)) < 0)
+                        if ((r = socket_address_listen(
+                                             &p->address,
+                                             s->backlog,
+                                             s->bind_ipv6_only,
+                                             s->bind_to_device,
+                                             s->directory_mode,
+                                             s->socket_mode,
+                                             &p->fd)) < 0)
                                 goto rollback;
 
                 } else {