[systemd-commits] 4 commits - man/systemd-machine-id-setup.xml man/systemd.network.xml src/core src/libsystemd-network src/machine-id-setup src/network
Tom Gundersen
tomegun at kemper.freedesktop.org
Fri Mar 14 04:44:18 PDT 2014
man/systemd-machine-id-setup.xml | 8 ++++
man/systemd.network.xml | 4 +-
src/core/machine-id-setup.c | 44 +++++++++++++++++----------
src/core/machine-id-setup.h | 2 -
src/core/main.c | 2 -
src/libsystemd-network/sd-dhcp-lease.c | 4 --
src/machine-id-setup/machine-id-setup-main.c | 15 +++++++--
src/network/networkd-address.c | 4 +-
src/network/networkd-link.c | 11 +++---
src/network/networkd-manager.c | 19 ++++++-----
src/network/networkd-network.c | 10 +++++-
src/network/networkd.c | 16 ++++++++-
src/network/networkd.h | 4 +-
13 files changed, 97 insertions(+), 46 deletions(-)
New commits:
commit 92f2f92edcad46ce4098ee26504edca0a1dad68e
Author: Greg KH <gregkh at linuxfoundation.org>
Date: Fri Mar 14 04:43:04 2014 +0000
machine-id: add --root option to operate on an alternate fs tree
This makes it possible to initialize the /etc/machine-id file on an
arbitrary filesystem hierarchy. This helps systems that wish to run
this at image creation time in a subdirectory, or from initramfs before
pivot-root is called.
[tomegun: converted to using _cleanup_free_ macros]
diff --git a/man/systemd-machine-id-setup.xml b/man/systemd-machine-id-setup.xml
index 5c34b34..b879b40 100644
--- a/man/systemd-machine-id-setup.xml
+++ b/man/systemd-machine-id-setup.xml
@@ -96,6 +96,14 @@
<para>The following options are understood:</para>
<variablelist>
+ <varlistentry>
+ <term><option>--root=ROOT</option></term>
+ <listitem><para>Takes a directory path
+ as an argument. All paths will be
+ prefixed with the given alternate ROOT
+ path, including config search paths.
+ </para></listitem>
+ </varlistentry>
<xi:include href="standard-options.xml" xpointer="help" />
<xi:include href="standard-options.xml" xpointer="version" />
</variablelist>
diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
index 1b55da7..f3b1b31 100644
--- a/src/core/machine-id-setup.c
+++ b/src/core/machine-id-setup.c
@@ -59,18 +59,22 @@ static int shorten_uuid(char destination[36], const char *source) {
return -EINVAL;
}
-static int generate(char id[34]) {
+static int generate(char id[34], const char *root) {
int fd, r;
unsigned char *p;
sd_id128_t buf;
char *q;
ssize_t k;
const char *vm_id;
+ _cleanup_free_ char *dbus_machine_id = NULL;
assert(id);
+ if (asprintf(&dbus_machine_id, "%s/var/lib/dbus/machine-id", root) < 0)
+ return log_oom();
+
/* First, try reading the D-Bus machine id, unless it is a symlink */
- fd = open("/var/lib/dbus/machine-id", O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
+ fd = open(dbus_machine_id, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
if (fd >= 0) {
k = loop_read(fd, id, 33, false);
close_nointr_nofail(fd);
@@ -150,12 +154,20 @@ static int generate(char id[34]) {
return 0;
}
-int machine_id_setup(void) {
+int machine_id_setup(const char *root) {
_cleanup_close_ int fd = -1;
int r;
bool writable = false;
struct stat st;
char id[34]; /* 32 + \n + \0 */
+ _cleanup_free_ char *etc_machine_id = NULL;
+ _cleanup_free_ char *run_machine_id = NULL;
+
+ if (asprintf(&etc_machine_id, "%s/etc/machine-id", root) < 0)
+ return log_oom();
+
+ if (asprintf(&run_machine_id, "%s/run/machine-id", root) < 0)
+ return log_oom();
RUN_WITH_UMASK(0000) {
/* We create this 0444, to indicate that this isn't really
@@ -163,13 +175,13 @@ int machine_id_setup(void) {
* will be owned by root it doesn't matter much, but maybe
* people look. */
- fd = open("/etc/machine-id", O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY, 0444);
+ fd = open(etc_machine_id, O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY, 0444);
if (fd >= 0)
writable = true;
else {
- fd = open("/etc/machine-id", O_RDONLY|O_CLOEXEC|O_NOCTTY);
+ fd = open(etc_machine_id, O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0) {
- log_error("Cannot open /etc/machine-id: %m");
+ log_error("Cannot open %s: %m", etc_machine_id);
return -errno;
}
@@ -193,7 +205,7 @@ int machine_id_setup(void) {
/* Hmm, so, the id currently stored is not useful, then let's
* generate one */
- r = generate(id);
+ r = generate(id, root);
if (r < 0)
return r;
@@ -211,27 +223,27 @@ int machine_id_setup(void) {
* /run/machine-id as a replacement */
RUN_WITH_UMASK(0022) {
- r = write_string_file("/run/machine-id", id);
+ r = write_string_file(run_machine_id, id);
}
if (r < 0) {
- log_error("Cannot write /run/machine-id: %s", strerror(-r));
- unlink("/run/machine-id");
+ log_error("Cannot write %s: %s", run_machine_id, strerror(-r));
+ unlink(run_machine_id);
return r;
}
/* And now, let's mount it over */
- r = mount("/run/machine-id", "/etc/machine-id", NULL, MS_BIND, NULL);
+ r = mount(run_machine_id, etc_machine_id, NULL, MS_BIND, NULL);
if (r < 0) {
- log_error("Failed to mount /etc/machine-id: %m");
- unlink_noerrno("/run/machine-id");
+ log_error("Failed to mount %s: %m", etc_machine_id);
+ unlink_noerrno(run_machine_id);
return -errno;
}
- log_info("Installed transient /etc/machine-id file.");
+ log_info("Installed transient %s file.", etc_machine_id);
/* Mark the mount read-only */
- if (mount(NULL, "/etc/machine-id", NULL, MS_BIND|MS_RDONLY|MS_REMOUNT, NULL) < 0)
- log_warning("Failed to make transient /etc/machine-id read-only: %m");
+ if (mount(NULL, etc_machine_id, NULL, MS_BIND|MS_RDONLY|MS_REMOUNT, NULL) < 0)
+ log_warning("Failed to make transient %s read-only: %m", etc_machine_id);
return 0;
}
diff --git a/src/core/machine-id-setup.h b/src/core/machine-id-setup.h
index b9e6b4d..b0583ee 100644
--- a/src/core/machine-id-setup.h
+++ b/src/core/machine-id-setup.h
@@ -21,4 +21,4 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-int machine_id_setup(void);
+int machine_id_setup(const char *root);
diff --git a/src/core/main.c b/src/core/main.c
index f1b06d8..cc876ef 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1582,7 +1582,7 @@ int main(int argc, char *argv[]) {
kmod_setup();
#endif
hostname_setup();
- machine_id_setup();
+ machine_id_setup("");
loopback_setup();
test_mtab();
diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c
index 84af925..a67d436 100644
--- a/src/machine-id-setup/machine-id-setup-main.c
+++ b/src/machine-id-setup/machine-id-setup-main.c
@@ -29,12 +29,15 @@
#include "log.h"
#include "build.h"
+static const char *arg_root = "";
+
static int help(void) {
printf("%s [OPTIONS...]\n\n"
"Initialize /etc/machine-id from a random source.\n\n"
" -h --help Show this help\n"
- " --version Show package version\n",
+ " --version Show package version\n"
+ " --root Filesystem root\n",
program_invocation_short_name);
return 0;
@@ -43,12 +46,14 @@ static int help(void) {
static int parse_argv(int argc, char *argv[]) {
enum {
- ARG_VERSION = 0x100
+ ARG_VERSION = 0x100,
+ ARG_ROOT,
};
static const struct option options[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, ARG_VERSION },
+ { "root", required_argument, NULL, ARG_ROOT },
{}
};
@@ -69,6 +74,10 @@ static int parse_argv(int argc, char *argv[]) {
puts(SYSTEMD_FEATURES);
return 0;
+ case ARG_ROOT:
+ arg_root = optarg;
+ break;
+
case '?':
return -EINVAL;
@@ -95,5 +104,5 @@ int main(int argc, char *argv[]) {
if (r <= 0)
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
- return machine_id_setup() < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+ return machine_id_setup(arg_root) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
commit 06f021a8048583d66202e3ac5cd0a12386d33ac2
Author: Tom Gundersen <teg at jklm.no>
Date: Thu Mar 13 20:46:45 2014 +0100
networkd: allow more than one static DNS server
diff --git a/man/systemd.network.xml b/man/systemd.network.xml
index 4118fc9..7609128 100644
--- a/man/systemd.network.xml
+++ b/man/systemd.network.xml
@@ -221,8 +221,8 @@
<term><varname>DNS=</varname></term>
<listitem>
<para>A DNS server address, which must be in the format described in
- <citerefentry><refentrytitle>inet_pton</refentrytitle><manvolnum>3</manvolnum></citerefentry>
- .</para>
+ <citerefentry><refentrytitle>inet_pton</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
+ This option may be specified repeatedly.</para>
</listitem>
</varlistentry>
<varlistentry>
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index c924189..414b3bc 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -225,7 +225,7 @@ int config_parse_dns(const char *unit,
const char *rvalue,
void *data,
void *userdata) {
- Address **dns = data;
+ Set **dns = data;
_cleanup_address_free_ Address *n = NULL;
int r;
@@ -246,7 +246,7 @@ int config_parse_dns(const char *unit,
return 0;
}
- *dns = n;
+ set_put(*dns, n);
n = NULL;
return 0;
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 8c2f5ef..c730e71 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -442,10 +442,17 @@ int manager_update_resolv_conf(Manager *m) {
}
}
- HASHMAP_FOREACH(link, m->links, i)
- if (link->network && link->network->dns)
- append_dns(f, &link->network->dns->in_addr.in,
- link->network->dns->family, &count);
+ HASHMAP_FOREACH(link, m->links, i) {
+ if (link->network && link->network->dns) {
+ Address *address;
+ Iterator j;
+
+ SET_FOREACH(address, link->network->dns, j) {
+ append_dns(f, &address->in_addr.in,
+ address->family, &count);
+ }
+ }
+ }
fflush(f);
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 6437ff4..6e9915b 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -69,6 +69,10 @@ static int network_load_one(Manager *manager, const char *filename) {
if (!network->routes_by_section)
return log_oom();
+ network->dns = set_new(NULL, NULL);
+ if (!network->dns)
+ return log_oom();
+
network->filename = strdup(filename);
if (!network->filename)
return log_oom();
@@ -136,6 +140,7 @@ int network_load(Manager *manager) {
void network_free(Network *network) {
Route *route;
Address *address;
+ Iterator i;
if (!network)
return;
@@ -150,7 +155,10 @@ void network_free(Network *network) {
free(network->description);
- address_free(network->dns);
+ SET_FOREACH(address, network->dns, i)
+ address_free(address);
+
+ set_free(network->dns);
hashmap_free(network->vlans);
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 0c01719..311350c 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -33,6 +33,7 @@
#include "rtnl-util.h"
#include "hashmap.h"
#include "list.h"
+#include "set.h"
#include "condition-util.h"
typedef struct NetDev NetDev;
@@ -130,11 +131,12 @@ struct Network {
LIST_HEAD(Address, static_addresses);
LIST_HEAD(Route, static_routes);
- Address *dns;
Hashmap *addresses_by_section;
Hashmap *routes_by_section;
+ Set *dns;
+
LIST_FIELDS(Network, networks);
};
commit 0ea51a1129b9984a3c6d96cef1b0e33c99b5e9cf
Author: Tom Gundersen <teg at jklm.no>
Date: Thu Mar 13 19:02:28 2014 +0100
networkd: fix creation of runtime dirs at startup
This allows us to drop the repeated attempted creations of the runtime dirs during runtime.
diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index f7a204a..e6d80d4 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -297,10 +297,6 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
assert(lease);
assert(lease_file);
- r = mkdir_safe_label("/run/systemd/network/leases", 0755, 0, 0);
- if (r < 0)
- goto finish;
-
r = fopen_temporary(lease_file, &f, &temp_path);
if (r < 0)
goto finish;
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 39cef22..2650f86 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1367,10 +1367,6 @@ int link_save(Link *link) {
assert(link);
assert(link->state_file);
- r = mkdir_safe_label("/run/systemd/network/links", 0755, 0, 0);
- if (r < 0)
- goto finish;
-
r = fopen_temporary(link->state_file, &f, &temp_path);
if (r < 0)
goto finish;
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index f41914f..8c2f5ef 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -407,10 +407,6 @@ int manager_update_resolv_conf(Manager *m) {
assert(m);
- r = mkdir_safe_label("/run/systemd/network", 0755, 0, 0);
- if (r < 0)
- return r;
-
r = fopen_temporary("/run/systemd/network/resolv.conf", &f, &temp_path);
if (r < 0)
return r;
diff --git a/src/network/networkd.c b/src/network/networkd.c
index 2f6a12d..f0e6ad5 100644
--- a/src/network/networkd.c
+++ b/src/network/networkd.c
@@ -42,8 +42,20 @@ int main(int argc, char *argv[]) {
/* Always create the directories people can create inotify
* watches in. */
- mkdir_label("/run/systemd/network/links", 0755);
- mkdir_label("/run/systemd/network/leases", 0755);
+ r = mkdir_label("/run/systemd/network", 0755);
+ if (r < 0)
+ log_error("Could not create runtime directory: %s",
+ strerror(-r));
+
+ r = mkdir_label("/run/systemd/network/links", 0755);
+ if (r < 0)
+ log_error("Could not create runtime directory 'links': %s",
+ strerror(-r));
+
+ r = mkdir_label("/run/systemd/network/leases", 0755);
+ if (r < 0)
+ log_error("Could not create runtime directory 'leases': %s",
+ strerror(-r));
r = manager_new(&m);
if (r < 0) {
commit 2a1763edfbdb95be643d595afbcc64f3fc092e46
Author: Tom Gundersen <teg at jklm.no>
Date: Thu Mar 13 18:42:56 2014 +0100
networkd: lease - store (up to) one dhcp lease file per interface
This removes an accidentally left-over test fragment.
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index fdc351f..39cef22 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1383,7 +1383,12 @@ int link_save(Link *link) {
link_state_to_string(link->state));
if (link->dhcp_lease) {
- const char *lease_file = "/run/systemd/network/leases/test.lease";
+ char *lease_file;
+
+ r = asprintf(&lease_file, "/run/systemd/network/leases/%u",
+ (unsigned) link->ifindex);
+ if (r < 0)
+ return r;
r = dhcp_lease_save(link->dhcp_lease, lease_file);
if (r < 0)
More information about the systemd-commits
mailing list