Re: [systemd-devel] [PATCH] service: don't create extra cgroup for control process when reloading SysV service

2014-03-13 Thread Lukáš Nykrýn

St 12. březen 2014, 18:34:11 CET, Uoti Urpala napsal:

On Wed, 2014-03-12 at 16:51 +0100, Lennart Poettering wrote:

On Mon, 10.03.14 15:25, Lukas Nykryn (lnyk...@redhat.com) wrote:


Unfortunately common practice in initscripts is to have reload as an
alias for restart (https://fedoraproject.org/wiki/Packaging:SysVInitScript).
In that case the newly started process will be killed immediately after
the reload process ends and its cgroup is destroyed.




I am not sure I grok why this all would be a problem at all, given that
on Fedora/RHEL we redirect those verbs to systemctl anyway, and
systemctl handles reload/restart on its own anyway... What am I missing?


But systemctl supports using the reload functionality in init scripts,
so that doesn't really make a difference. As I understood the problem
description, this is what happens: someone runs systemctl reload
foo.service for a broken sysv script, systemd sees that the script
seems to support a reload argument and runs /etc/init.d/foo reload
in a temporary cgroup, but the broken script stops the running service
and starts a new one in the temporary cgroup.


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Exactly. Systemd exec /etc/init.d/foo reload in control subgroup. 
Than the initscript kills the original deamon, starts a new one and 
quits. Systemd sees that the reload process finished and kills 
remaining processes in the control group, thus kills the daemon.


This patch works quite fine when the initscripts is using pid files, 
systemd correctly updates the information about main pid.



___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 1/4] libsystemd-network: Export checksum function to test case

2014-03-13 Thread Patrik Flykt
Remove identical checksum function implementation from the test
case code.
---
 src/libsystemd-network/dhcp-internal.h|  2 ++
 src/libsystemd-network/dhcp-packet.c  | 10 +-
 src/libsystemd-network/test-dhcp-client.c | 30 +++---
 3 files changed, 10 insertions(+), 32 deletions(-)

diff --git a/src/libsystemd-network/dhcp-internal.h 
b/src/libsystemd-network/dhcp-internal.h
index 3c3e1f6..064b13b 100644
--- a/src/libsystemd-network/dhcp-internal.h
+++ b/src/libsystemd-network/dhcp-internal.h
@@ -48,6 +48,8 @@ int dhcp_option_parse(DHCPMessage *message, size_t len,
 int dhcp_message_init(DHCPMessage *message, uint8_t op, uint32_t xid, uint8_t 
type,
   uint8_t **opt, size_t *optlen);
 
+uint16_t dhcp_packet_checksum(void *buf, int len);
+
 void dhcp_packet_append_ip_headers(DHCPPacket *packet, be32_t source_addr,
uint16_t source, be32_t destination_addr,
uint16_t destination, uint16_t len);
diff --git a/src/libsystemd-network/dhcp-packet.c 
b/src/libsystemd-network/dhcp-packet.c
index 418a977..bed942f 100644
--- a/src/libsystemd-network/dhcp-packet.c
+++ b/src/libsystemd-network/dhcp-packet.c
@@ -69,7 +69,7 @@ int dhcp_message_init(DHCPMessage *message, uint8_t op, 
uint32_t xid,
 return 0;
 }
 
-static uint16_t dhcp_checksum(void *buf, int len) {
+uint16_t dhcp_packet_checksum(void *buf, int len) {
 uint32_t sum;
 uint16_t *check;
 int i;
@@ -109,11 +109,11 @@ void dhcp_packet_append_ip_headers(DHCPPacket *packet, 
be32_t source_addr,
 packet-udp.len = htobe16(len - DHCP_IP_SIZE);
 
 packet-ip.check = packet-udp.len;
-packet-udp.check = dhcp_checksum(packet-ip.ttl, len - 8);
+packet-udp.check = dhcp_packet_checksum(packet-ip.ttl, len - 8);
 
 packet-ip.ttl = IPDEFTTL;
 packet-ip.check = 0;
-packet-ip.check = dhcp_checksum(packet-ip, DHCP_IP_SIZE);
+packet-ip.check = dhcp_packet_checksum(packet-ip, DHCP_IP_SIZE);
 }
 
 int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum) {
@@ -150,7 +150,7 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t 
len, bool checksum) {
 return -EINVAL;
 }
 
-if (dhcp_checksum(packet-ip, hdrlen)) {
+if (dhcp_packet_checksum(packet-ip, hdrlen)) {
 log_dhcp_client(client, ignoring packet: invalid IP 
checksum);
 return -EINVAL;
 }
@@ -175,7 +175,7 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t 
len, bool checksum) {
 packet-ip.check = packet-udp.len;
 packet-ip.ttl = 0;
 
-if (dhcp_checksum(packet-ip.ttl,
+if (dhcp_packet_checksum(packet-ip.ttl,
   be16toh(packet-udp.len) + 12)) {
 log_dhcp_client(client, ignoring packet: invalid UDP 
checksum);
 return -EINVAL;
diff --git a/src/libsystemd-network/test-dhcp-client.c 
b/src/libsystemd-network/test-dhcp-client.c
index 8061e5f..cfc75ae 100644
--- a/src/libsystemd-network/test-dhcp-client.c
+++ b/src/libsystemd-network/test-dhcp-client.c
@@ -102,30 +102,6 @@ static void test_request_basic(sd_event *e)
 assert_se(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
 }
 
-static uint16_t client_checksum(void *buf, int len)
-{
-uint32_t sum;
-uint16_t *check;
-int i;
-uint8_t *odd;
-
-sum = 0;
-check = buf;
-
-for (i = 0; i  len / 2 ; i++)
-sum += check[i];
-
-if (len  0x01) {
-odd = buf;
-sum += odd[len - 1];
-}
-
-while (sum  16)
-sum = (sum  0x) + (sum  16);
-
-return ~sum;
-}
-
 static void test_checksum(void)
 {
 uint8_t buf[20] = {
@@ -137,7 +113,7 @@ static void test_checksum(void)
 if (verbose)
 printf(* %s\n, __FUNCTION__);
 
-assert_se(client_checksum(buf, 20) == be16toh(0x78ae));
+assert_se(dhcp_packet_checksum(buf, 20) == be16toh(0x78ae));
 }
 
 static int check_options(uint8_t code, uint8_t len, const uint8_t *option,
@@ -173,13 +149,13 @@ int dhcp_network_send_raw_socket(int s, const union 
sockaddr_union *link,
 discover-ip.ttl = 0;
 discover-ip.check = discover-udp.len;
 
-udp_check = ~client_checksum(discover-ip.ttl, len - 8);
+udp_check = ~dhcp_packet_checksum(discover-ip.ttl, len - 8);
 assert_se(udp_check == 0x);
 
 discover-ip.ttl = IPDEFTTL;
 discover-ip.check = ip_check;
 
-ip_check = ~client_checksum(discover-ip, sizeof(discover-ip));
+ip_check = ~dhcp_packet_checksum(discover-ip, sizeof(discover-ip));
 assert_se(ip_check == 0x);
 
 assert_se(discover-dhcp.xid);
-- 
1.8.5.2


[systemd-devel] [PATCH 0/4] Add DHCPv4 client restart and Init-Reboot support

2014-03-13 Thread Patrik Flykt

Hi,

Patches 01/04 and 02/04 are minimal fixes that sat in between the
current head and the changes, both of them are pretty trivial.

Patch 03/04 makes the DHCPv4 client implementation automatically restart
DHCP address negotiations if the previous lease expires. This was
discussed off-list as an improvement we'd like to have in the code as
it frees networkd from making trivial decisions where the intention to
keep the device connected with DHCP is very clear.

Already now the code tries continuosly to get a lease in selecting and
requesting states so the only real addition is the restart after lease
expiry. With this modification, DHCP stops if internal errors  0 happen,
networkd stops DHCP with sd_dhcp_stop() or the client receives a NAK
from the server. Restarting address acquisition after a NAK leads to a
horrible amount of discover - offer - request - nak exchanges since
receiving a NAK means the server was already successfully contacted but
is not willing to give a lease to the client.

Patch 04/04 rebases the Init-Reboot patch from some time ago, it
unfortunately got lost in the process last time. With this networkd will
be even faster than before should the previous IP address be acceptable
to the server.


Cheers,

Patrik


Patrik Flykt (4):
  libsystemd-network: Export checksum function to test case
  libsystemd-network: Add hangcheck timer for DHCP client test
  libsystemd-network: Restart DHCP acquisition if the lease expires
  libsystemd-network: Add Init-Reboot support

 src/libsystemd-network/dhcp-internal.h|   2 +
 src/libsystemd-network/dhcp-packet.c  |  10 +--
 src/libsystemd-network/sd-dhcp-client.c   | 131 +++---
 src/libsystemd-network/test-dhcp-client.c |  46 +--
 4 files changed, 129 insertions(+), 60 deletions(-)

-- 
1.8.5.2

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 4/4] libsystemd-network: Add Init-Reboot support

2014-03-13 Thread Patrik Flykt
Init-Reboot is tried if a client IP address has been given when
the DHCP client is started. In Init-Reboot, start by sending a
broadcasted DHCP Request including the supplied client IP address
but without the server identifier. After sending the request,
enter Reboot state.

If a DHCP Ack is received, proceed to Bound state as usual. If a
DHCP Nak is received or the first timeout triggers, start the
address acquisition over from DHCP Init state.

See RFC 2131, sections 4.3.2, 4.4, 4.4.1 and 4.4.2 for details.
---
 src/libsystemd-network/sd-dhcp-client.c | 57 +
 1 file changed, 51 insertions(+), 6 deletions(-)

diff --git a/src/libsystemd-network/sd-dhcp-client.c 
b/src/libsystemd-network/sd-dhcp-client.c
index 74e560b..c301a3f 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -340,7 +340,17 @@ static int client_send_request(sd_dhcp_client *client, 
uint16_t secs) {
 if (err  0)
 return err;
 
-if (client-state == DHCP_STATE_REQUESTING) {
+switch (client-state) {
+
+case DHCP_STATE_INIT_REBOOT:
+err = dhcp_option_append(opt, optlen,
+ DHCP_OPTION_REQUESTED_IP_ADDRESS,
+ 4, client-last_addr);
+if (err  0)
+return err;
+break;
+
+case DHCP_STATE_REQUESTING:
 err = dhcp_option_append(opt, optlen,
  DHCP_OPTION_REQUESTED_IP_ADDRESS,
  4, client-lease-address);
@@ -352,6 +362,16 @@ static int client_send_request(sd_dhcp_client *client, 
uint16_t secs) {
  4, client-lease-server_address);
 if (err  0)
 return err;
+break;
+
+case DHCP_STATE_INIT:
+case DHCP_STATE_SELECTING:
+case DHCP_STATE_REBOOTING:
+case DHCP_STATE_BOUND:
+case DHCP_STATE_RENEWING:
+case DHCP_STATE_REBINDING:
+
+break;
 }
 
 err = dhcp_option_append(opt, optlen, DHCP_OPTION_END, 0, NULL);
@@ -413,9 +433,15 @@ static int client_timeout_resend(sd_event_source *s, 
uint64_t usec,
 next_timeout = usec + time_left * USEC_PER_SEC;
 break;
 
+case DHCP_STATE_REBOOTING:
+/* start over as we did not receive a timely ack or nak */
+client-state = DHCP_STATE_INIT;
+client-attempt = 1;
+client-xid = random_u32();
+
+/* fall through */
 case DHCP_STATE_INIT:
 case DHCP_STATE_INIT_REBOOT:
-case DHCP_STATE_REBOOTING:
 case DHCP_STATE_SELECTING:
 case DHCP_STATE_REQUESTING:
 case DHCP_STATE_BOUND:
@@ -470,6 +496,7 @@ static int client_timeout_resend(sd_event_source *s, 
uint64_t usec,
 
 break;
 
+case DHCP_STATE_INIT_REBOOT:
 case DHCP_STATE_REQUESTING:
 case DHCP_STATE_RENEWING:
 case DHCP_STATE_REBINDING:
@@ -477,11 +504,13 @@ static int client_timeout_resend(sd_event_source *s, 
uint64_t usec,
 if (r  0  client-attempt = 64)
  goto error;
 
+if (client-state == DHCP_STATE_INIT_REBOOT)
+client-state = DHCP_STATE_REBOOTING;
+
 client-request_sent = usec;
 
 break;
 
-case DHCP_STATE_INIT_REBOOT:
 case DHCP_STATE_REBOOTING:
 case DHCP_STATE_BOUND:
 
@@ -859,20 +888,37 @@ static int client_handle_message(sd_dhcp_client *client, 
DHCPMessage *message,
 
 break;
 
+case DHCP_STATE_REBOOTING:
 case DHCP_STATE_REQUESTING:
 case DHCP_STATE_RENEWING:
 case DHCP_STATE_REBINDING:
 
 r = client_handle_ack(client, message, len);
 
-if (r == DHCP_EVENT_NO_LEASE)
+if (r == DHCP_EVENT_NO_LEASE) {
+
+client-timeout_resend =
+sd_event_source_unref(client-timeout_resend);
+
+if (client-state == DHCP_STATE_REBOOTING) {
+r = client_initialize(client);
+if (r  0)
+goto error;
+
+r = client_start(client);
+if (r  0)
+goto error;
+}
+
 goto error;
+}
 
 if (r = 0) {
 client-timeout_resend =
 sd_event_source_unref(client-timeout_resend);
 
-if (client-state == DHCP_STATE_REQUESTING)
+if (client-state == DHCP_STATE_REQUESTING 

[systemd-devel] [PATCH 3/4] libsystemd-network: Restart DHCP acquisition if the lease expires

2014-03-13 Thread Patrik Flykt
This causes the DHCP client struct initialization and DHCP client
starting to be factored out into functions of their own.
---
 src/libsystemd-network/sd-dhcp-client.c | 74 +++--
 1 file changed, 52 insertions(+), 22 deletions(-)

diff --git a/src/libsystemd-network/sd-dhcp-client.c 
b/src/libsystemd-network/sd-dhcp-client.c
index f4a83fb..74e560b 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -178,7 +178,7 @@ static int client_notify(sd_dhcp_client *client, int event) 
{
 return 0;
 }
 
-static int client_stop(sd_dhcp_client *client, int error) {
+static int client_initialize(sd_dhcp_client *client) {
 assert_return(client, -EINVAL);
 
 client-receive_message =
@@ -196,15 +196,24 @@ static int client_stop(sd_dhcp_client *client, int error) 
{
 
 client-attempt = 1;
 
-client_notify(client, error);
-
 client-start_time = 0;
 client-secs = 0;
 client-state = DHCP_STATE_INIT;
+client-xid = 0;
 
 if (client-lease)
 client-lease = sd_dhcp_lease_unref(client-lease);
 
+return 0;
+}
+
+static int client_stop(sd_dhcp_client *client, int error) {
+assert_return(client, -EINVAL);
+
+client_notify(client, error);
+
+client_initialize(client);
+
 log_dhcp_client(client, STOPPED);
 
 return 0;
@@ -528,13 +537,47 @@ error:
 
 }
 
+static int client_start(sd_dhcp_client *client) {
+int r;
+
+assert_return(client, -EINVAL);
+assert_return(client-event, -EINVAL);
+assert_return(client-index  0, -EINVAL);
+assert_return(client-fd  0, -EBUSY);
+assert_return(client-xid == 0, -EINVAL);
+assert_return(client-state == DHCP_STATE_INIT ||
+  client-state == DHCP_STATE_INIT_REBOOT, -EBUSY);
+
+client-xid = random_u32();
+
+r = dhcp_network_bind_raw_socket(client-index, client-link);
+
+if (r  0) {
+client_stop(client, r);
+return r;
+}
+
+client-fd = r;
+client-start_time = now(CLOCK_MONOTONIC);
+client-secs = 0;
+
+log_dhcp_client(client, STARTED);
+
+return client_initialize_events(client, client_receive_message_raw,
+client-start_time);
+}
+
 static int client_timeout_expire(sd_event_source *s, uint64_t usec,
  void *userdata) {
 sd_dhcp_client *client = userdata;
 
 log_dhcp_client(client, EXPIRED);
 
-client_stop(client, DHCP_EVENT_EXPIRED);
+client_notify(client, DHCP_EVENT_EXPIRED);
+
+/* start over as the lease was lost */
+client_initialize(client);
+client_start(client);
 
 return 0;
 }
@@ -967,28 +1010,15 @@ int sd_dhcp_client_start(sd_dhcp_client *client) {
 int r;
 
 assert_return(client, -EINVAL);
-assert_return(client-event, -EINVAL);
-assert_return(client-index  0, -EINVAL);
-assert_return(client-state == DHCP_STATE_INIT ||
-  client-state == DHCP_STATE_INIT_REBOOT, -EBUSY);
 
-client-xid = random_u32();
-
-r = dhcp_network_bind_raw_socket(client-index, client-link);
-
-if (r  0) {
-client_stop(client, r);
+r = client_initialize(client);
+if (r  0)
 return r;
-}
 
-client-fd = r;
-client-start_time = now(CLOCK_MONOTONIC);
-client-secs = 0;
+if (client-last_addr)
+client-state = DHCP_STATE_INIT_REBOOT;
 
-log_dhcp_client(client, STARTED);
-
-return client_initialize_events(client, client_receive_message_raw,
-client-start_time);
+return client_start(client);
 }
 
 int sd_dhcp_client_stop(sd_dhcp_client *client) {
-- 
1.8.5.2

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 2/4] libsystemd-network: Add hangcheck timer for DHCP client test

2014-03-13 Thread Patrik Flykt
---
 src/libsystemd-network/test-dhcp-client.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/src/libsystemd-network/test-dhcp-client.c 
b/src/libsystemd-network/test-dhcp-client.c
index cfc75ae..9509eec 100644
--- a/src/libsystemd-network/test-dhcp-client.c
+++ b/src/libsystemd-network/test-dhcp-client.c
@@ -44,6 +44,15 @@ static bool verbose = false;
 static int test_fd[2];
 static test_callback_recv_t callback_recv;
 static be32_t xid;
+static sd_event_source *test_hangcheck;
+
+static int test_dhcp_hangcheck(sd_event_source *s, uint64_t usec,
+   void *userdata)
+{
+assert(false);
+
+return 0;
+}
 
 static void test_request_basic(sd_event *e)
 {
@@ -419,6 +428,7 @@ static int test_addr_acq_recv_discover(size_t size, 
DHCPMessage *discover)
 
 static void test_addr_acq(sd_event *e)
 {
+usec_t time_now = now(CLOCK_MONOTONIC);
 sd_dhcp_client *client;
 int res, r;
 
@@ -440,11 +450,17 @@ static void test_addr_acq(sd_event *e)
 
 callback_recv = test_addr_acq_recv_discover;
 
+assert_se(sd_event_add_monotonic(e, test_hangcheck,
+ time_now + 2 * USEC_PER_SEC, 0,
+ test_dhcp_hangcheck, NULL) = 0);
+
 res = sd_dhcp_client_start(client);
 assert_se(res == 0 || res == -EINPROGRESS);
 
 sd_event_loop(e);
 
+test_hangcheck = sd_event_source_unref(test_hangcheck);
+
 sd_dhcp_client_set_callback(client, NULL, NULL);
 sd_dhcp_client_stop(client);
 sd_dhcp_client_free(client);
-- 
1.8.5.2

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Memory leak in in sd-bus.c:sd_bus_open_user?

2014-03-13 Thread Vetoshkin Nikita
Hi!

Was lurking trough sources and I think I found memory leak
in sd_bus_open_user if both DBUS_SESSION_BUS_ADDRESS and XDG_RUNTIME_DIR
env variables are not available and ENABLE_KDBUS is not defined. We simply
return -ECONNREFUSED without falling to fail label.

Sorry if I read it all wrong.


Nikita
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] How to compute a value for a service argument or environment value?

2014-03-13 Thread Alan Stern
This question has probably been asked many times before, but I didn't 
see it mentioned anywhere on the systemd web site.

I want to create a unit file for a service where the server program
requires an argument or environment value that has to be computed at
run time; it isn't known in advance.  For example, suppose the server
requires the numeric UID value corresponding to some particular
username, passed as an argument or an environment value.

In a SysV-type shell script, I could simply do:

exec /path/to/server_program `id -u username`

or

export USERID=`id -u username`
exec /path/to/server_program

Neither of these is possible in a systemd service unit file.  So what 
is the best way to accomplish the same result?

All I have been able to think of is to have ExecStart= run a shell 
script that computes the necessary values and then execs the actual 
server program.  Is there a better way?

Alan Stern

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Documentation error for systemctl kill?

2014-03-13 Thread Alan Stern
In systemd 208 (the version currently distributed in Fedora 20), the 
man page for the systemctl(1) kill command says:

Send a signal to one or more processes of the unit. Use --kill-who=
to select which process to kill. Use --kill-mode= to select the
kill mode and --signal= to select the signal to send.

This seems peculiar, because the man page does not mention a
--kill-mode= option anywhere else.  It does mention --kill-who=,
saying:

When used with kill, choose which processes to kill. Must be one of
main, control or all to select whether to kill only the main
process of the unit, the control process or all processes of the
unit. If omitted, defaults to all.

This sounds an awful lot like the description of the KillMode= option 
documented under systemd.kill(5):

Specifies how processes of this service shall be killed. One of
control-group, process, none

As far as I can tell, main for --kill-who= means much the same thing
as process for KillMode=, and all for --kill-who= means much the
same as control-group for KillMode=.

So what does control mean for --kill-who=?  That is, what is the
control process (as opposed to the main process) of the unit?

And what about the --kill-mode= option?  According to the output from
systemctl --help, it doesn't exist.  Is it a relic from an earlier 
version of systemctl?

Alan Stern

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] How to compute a value for a service argument or environment value?

2014-03-13 Thread Cristian Rodríguez

El 13/03/14 15:37, Alan Stern escribió:
sult?


All I have been able to think of is to have ExecStart= run a shell
script that computes the necessary values and then execs the actual
server program.  Is there a better way?


That's a workable hack, however the correct solution is to have the 
daemon itself to either compute the needed value or read it from a 
configuration file.




___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Memory leak in in sd-bus.c:sd_bus_open_user?

2014-03-13 Thread Lennart Poettering
On Thu, 13.03.14 20:56, Vetoshkin Nikita (nikita.vetosh...@gmail.com) wrote:

 Hi!
 
 Was lurking trough sources and I think I found memory leak
 in sd_bus_open_user if both DBUS_SESSION_BUS_ADDRESS and XDG_RUNTIME_DIR
 env variables are not available and ENABLE_KDBUS is not defined. We simply
 return -ECONNREFUSED without falling to fail label.
 
 Sorry if I read it all wrong.

Nope! You are right!

Thanks! Fixed!

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Forwarding logs to another systems journal

2014-03-13 Thread Anand Neeli
Hello,

I have multiple systems, How do i forward logs from one system running
systemd-journald to another remote systems journal service, so that all the
logs are stored on a centralized machine.

Have went through systemd-journal-gatewayd, but this forwards logs on
http/https, doesnt send it to another remote systems journal.

can this be done only using systemd services? without using syslog-ng or
any other tools?

can anyone please give more details. If this is already answered then pls
point me to the mail thread.


Thanks in Advance

Anand Neeli
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Forwarding logs to another systems journal

2014-03-13 Thread Reindl Harald


Am 13.03.2014 20:54, schrieb Anand Neeli:
 I have multiple systems, How do i forward logs from one system running 
 systemd-journald to another remote systems
 journal service, so that all the logs are stored on a centralized machine.

that's not the job of journald and falls into the use-case
of continue with rsyslog which happily receives the log
from systemd-journald



signature.asc
Description: OpenPGP digital signature
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Forwarding logs to another systems journal

2014-03-13 Thread David Timothy Strauss
On Thu, Mar 13, 2014 at 12:54 PM, Anand Neeli anand.ne...@gmail.com wrote:
 I have multiple systems, How do i forward logs from one system running
 systemd-journald to another remote systems journal service, so that all the
 logs are stored on a centralized machine.

 Have went through systemd-journal-gatewayd, but this forwards logs on
 http/https, doesnt send it to another remote systems journal.

 can this be done only using systemd services? without using syslog-ng or any
 other tools?

 can anyone please give more details. If this is already answered then pls
 point me to the mail thread.

You'll really want to use a more sophisticated aggregator than the
journal. We use Kibana [1] with journal2gelf [2].

[1] http://www.elasticsearch.org/overview/kibana/
[2] https://github.com/systemd/journal2gelf
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] nspawn: allow -EEXIST on mkdir_safe /home/${uid}

2014-03-13 Thread Brandon Philips
With systemd 211 nspawn attempts to create the home directory for the
given uid. However, if the home directory already exists then it will
fail. Don't error out on -EEXIST.


0001-nspawn-allow-EEXIST-on-mkdir_safe-home-uid.patch
Description: Binary data
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] nspawn: allow -EEXIST on mkdir_safe /home/${uid}

2014-03-13 Thread Brandon Philips
Also, in commit aca07 my Debian Wheezy container broke because
/usr/bin/getent doesn't understand initgroups. Is there a way to
workaround this?

On Thu, Mar 13, 2014 at 3:31 PM, Brandon Philips bran...@ifup.co wrote:
 With systemd 211 nspawn attempts to create the home directory for the
 given uid. However, if the home directory already exists then it will
 fail. Don't error out on -EEXIST.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [RFC][PATCH v3 0/2] journald: add support for wall forwarding

2014-03-13 Thread Sebastian Thorarensen
These patches add two new options for journald.conf:
 * ForwardToWall (default yes)
 * MaxLevelWall (default emerg)

When ForwardToWall is yes, journald forwards all log messages equal or
below MaxLevelWall to utmp_wall(). This can be used to send emergency
messages to logged-in users. A forwarded log message looks like this when
it gets written to a user's terminal:

Broadcast message from systemd-journald at hostname (Wed 2014-03-05
13:00:00 CET):

some-process[4711]: This is an emergency log message from some-process!


See
http://lists.freedesktop.org/archives/systemd-devel/2014-March/017610.html
for v1 of this patch.

Changes since v3:
 * Added missing documentation of new kernel parameter
   systemd.journald.forward_to_wall= to kernel-command-line(7) and
   systemd-journald.service(8)

Sebastian Thorarensen (2):
  utmp-wtmp: allow overriding username on wall
  journald: add support for wall forwarding

 Makefile.am|2 +
 man/journald.conf.xml  |   40 +++-
 man/kernel-command-line.xml|1 +
 man/systemd-journald.service.xml   |5 +-
 src/journal/journald-gperf.gperf   |2 +
 src/journal/journald-native.c  |4 ++
 src/journal/journald-server.c  |8 +++
 src/journal/journald-server.h  |2 +
 src/journal/journald-stream.c  |4 ++
 src/journal/journald-syslog.c  |4 ++
 src/journal/journald-wall.c|   67 
 src/journal/journald-wall.h|   26 
 src/journal/journald.conf  |2 +
 src/shared/utmp-wtmp.c |   12 ++--
 src/shared/utmp-wtmp.h |2 +-
 src/shutdownd/shutdownd.c  |2 +-
 src/systemctl/systemctl.c  |4 +-
 .../tty-ask-password-agent.c   |2 +-
 18 files changed, 162 insertions(+), 27 deletions(-)
 create mode 100644 src/journal/journald-wall.c
 create mode 100644 src/journal/journald-wall.h

-- 
1.7.10.4
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [RFC][PATCH v3 2/2] journald: add support for wall forwarding

2014-03-13 Thread Sebastian Thorarensen
This will let journald forward logs as messages sent to all logged in
users (like wall).

Two options are added:
 * ForwardToWall (default yes)
 * MaxLevelWall (default emerg)
'ForwardToWall' is overridable by kernel command line option
'systemd.journald.forward_to_wall'.

This is used to emulate the traditional syslogd behaviour of sending
emergency messages to all logged in users.
---
 Makefile.am  |2 ++
 man/journald.conf.xml|   40 ++-
 man/kernel-command-line.xml  |1 +
 man/systemd-journald.service.xml |5 +--
 src/journal/journald-gperf.gperf |2 ++
 src/journal/journald-native.c|4 +++
 src/journal/journald-server.c|8 +
 src/journal/journald-server.h|2 ++
 src/journal/journald-stream.c|4 +++
 src/journal/journald-syslog.c|4 +++
 src/journal/journald-wall.c  |   67 ++
 src/journal/journald-wall.h  |   26 +++
 src/journal/journald.conf|2 ++
 13 files changed, 149 insertions(+), 18 deletions(-)
 create mode 100644 src/journal/journald-wall.c
 create mode 100644 src/journal/journald-wall.h

diff --git a/Makefile.am b/Makefile.am
index 2e4f857..48a3526 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3236,6 +3236,8 @@ libsystemd_journal_core_la_SOURCES = \
src/journal/journald-server.h \
src/journal/journald-console.c \
src/journal/journald-console.h \
+   src/journal/journald-wall.c \
+   src/journal/journald-wall.h \
src/journal/journald-native.c \
src/journal/journald-native.h \
src/journal/journald-rate-limit.c \
diff --git a/man/journald.conf.xml b/man/journald.conf.xml
index a814ec1..239a2ec 100644
--- a/man/journald.conf.xml
+++ b/man/journald.conf.xml
@@ -381,24 +381,28 @@
 
termvarnameForwardToSyslog=/varname/term
 termvarnameForwardToKMsg=/varname/term
 
termvarnameForwardToConsole=/varname/term
+termvarnameForwardToWall=/varname/term
 
 listitemparaControl whether log
 messages received by the journal
 daemon shall be forwarded to a
 traditional syslog daemon, to the
-kernel log buffer (kmsg), or to the
-system console. These options take
-boolean arguments. If forwarding to
-syslog is enabled but no syslog daemon
-is running, the respective option has
-no effect. By default, only forwarding
-to syslog is enabled. These settings
-may be overridden at boot time with
-the kernel command line options
+kernel log buffer (kmsg), to the
+system console, or sent as wall
+messages to all logged-in users. These
+options take boolean arguments. If
+forwarding to syslog is enabled but no
+syslog daemon is running, the
+respective option has no effect. By
+default, only forwarding to syslog and
+wall is enabled. These settings may be
+overridden at boot time with the
+kernel command line options
 
literalsystemd.journald.forward_to_syslog=/literal,
-
literalsystemd.journald.forward_to_kmsg=/literal
+
literalsystemd.journald.forward_to_kmsg=/literal,
+
literalsystemd.journald.forward_to_console=/literal
 and
-
literalsystemd.journald.forward_to_console=/literal.
+
literalsystemd.journald.forward_to_wall=/literal.
 When forwarding to the console, the
 TTY to log to can be changed
 with varnameTTYPath=/varname,
@@ -410,12 +414,14 @@
 termvarnameMaxLevelSyslog=/varname/term
 termvarnameMaxLevelKMsg=/varname/term
 
termvarnameMaxLevelConsole=/varname/term
+termvarnameMaxLevelWall=/varname/term
 
 listitemparaControls the maximum
 log level of messages that are stored
-

Re: [systemd-devel] [PATCH] nspawn: allow -EEXIST on mkdir_safe /home/${uid}

2014-03-13 Thread Lennart Poettering
On Thu, 13.03.14 15:37, Brandon Philips (bran...@ifup.co) wrote:

 Also, in commit aca07 my Debian Wheezy container broke because
 /usr/bin/getent doesn't understand initgroups. Is there a way to
 workaround this?

Oh yikes. I assumed getent with all its verb had been around since a
long time.

Hmm, so to resolve UIDs and GIDs properly we need some way in the
container to do NSS queries, from a binary that links against the
container's libc. getent is quite good for that as it has parsable
output, and given that it is component of glibc we can pretty much
assume that it is installed on any interesting container
guest...

Now, I am not sure how else we can correctly resolve the auxiliary gids
list, other than with getent initgroups. I don't think there's any
other nice command for that with parsable output that is ubiquitously
installed... Or is there? ideas?

IIUC then the the first part of the user transition works correctly
though, i.e. the getent passwd part? If so, maybe we can try the
initgroups part and if it fails simply print a wrning and proceed
without setting the auxiliary groups. Would that be enough for you?

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Passing variables from udev to unit

2014-03-13 Thread Andrey Borzenkov
В Fri, 14 Mar 2014 08:53:45 +1000
Peter Hutterer peter.hutte...@who-t.net пишет:

 Hey,
 
 I have a service file wacom-inputattach@.service that is started from a udev
 rule:
 
   SUBSYSTEM==tty|pnp, KERNEL==ttyS[0-9]*, ATTRS{id}==WACf*,
   TAG+=systemd, ENV{SYSTEMD_WANTS}+=wacom-inputattach@%k.service
 
 and the service file then runs:
 
   ExecStart=/usr/bin/inputattach -w8001 /dev/%I
 
 That works fine, but now I need to pass a second parameter into the service
 file. Ideally I want to run something like:
 
   ExecStart=/usr/bin/inputattach --baud $BAUD -w8001 /dev/%I
 
 I can set the baud rate based on ATTRS{id} in the udev rule, I just don't
 know if there is a way to pass this to the service file. Is there a way to
 do this or do I need to write a wrapper?


One possibility would be to generate 
/run/systemd/system/wacom-inputattach@%k.service.d/baud.conf that
contains

[Service]
BAUD=9600

But this requires systemd reload and may generate burst of reload
requests if there are multiple devices. May be wrapper is simpler.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] Fix permissions on new journal files

2014-03-13 Thread Zbigniew Jędrzejewski-Szmek
On Fri, Mar 14, 2014 at 12:07:35AM +, Greg KH wrote:
 When starting up journald on a new system, set the proper permissions on
 the system.journal file, not only on the journal directory.
 
 diff --git a/tmpfiles.d/systemd.conf b/tmpfiles.d/systemd.conf
 index 7c6d6b9099b9..1aeb5e40f1ee 100644
 --- a/tmpfiles.d/systemd.conf
 +++ b/tmpfiles.d/systemd.conf
 @@ -24,5 +24,7 @@ d /run/systemd/shutdown 0755 root root -
  
  m /var/log/journal 2755 root systemd-journal - -
  m /var/log/journal/%m 2755 root systemd-journal - -
 +m /var/log/journal/%m/system.journal 2755 root systemd-journal - -
  m /run/log/journal 2755 root systemd-journal - -
  m /run/log/journal/%m 2755 root systemd-journal - -
 +m /run/log/journal/%m/system.journal 2755 root systemd-journal - -
This is just a kludge... Why is system.journal to be treated differently?
It seems that the proper fix is to set the mode on the directory properly
during installation.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Help regarding service dependency

2014-03-13 Thread Andrey Borzenkov
В Thu, 13 Mar 2014 21:25:34 -0400 (EDT)
Amit Saha as...@redhat.com пишет:

 Hello,
 
 We have service1 which starts in default.target, and we want it to start 
 After service2 
 (systemd-readahead-done) which starts after the default.target is reached. 
 So, I think what would happen in this case is the After=service2 for service1 
 is ignored
 and it is started before service2 since the default.target must be reached.
 

There is no ordering dependencies between default.target and individual
units; default.target is simply a way to define what is started using
Wants. So it should work.

 For more specific info, here is a snippet of the .timer file for service2:
 
 [Unit]
 Description=Stop Read-Ahead Data Collection 10s After Completed Startup
 Documentation=man:systemd-readahead-replay.service(8)
 DefaultDependencies=no
 Conflicts=shutdown.target
 After=default.target
 Before=shutdown.target
 ConditionVirtualization=no
 
 [Timer]
 OnActiveSec=30s
 
 
 A colleague suggested creating a new target for service1 which 
 the system boots into and has a After=default.target, 
 systemd-readahead-done.service.

You seem to assume default.target is magic - it is not. If you boot
into another target, it becomes default target in this case.

 Even if not exactly how I mention, this idea holds promise.
 
 Also, is there any other suggested solution involving fiddling with the unit 
 dependencies
 but not the system boot target?
 

No fiddling is required.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] Fix permissions on new journal files

2014-03-13 Thread Dave Reisner
On Fri, Mar 14, 2014 at 03:28:27AM +0100, Zbigniew Jędrzejewski-Szmek wrote:
 On Fri, Mar 14, 2014 at 12:07:35AM +, Greg KH wrote:
  When starting up journald on a new system, set the proper permissions on
  the system.journal file, not only on the journal directory.
  
  diff --git a/tmpfiles.d/systemd.conf b/tmpfiles.d/systemd.conf
  index 7c6d6b9099b9..1aeb5e40f1ee 100644
  --- a/tmpfiles.d/systemd.conf
  +++ b/tmpfiles.d/systemd.conf
  @@ -24,5 +24,7 @@ d /run/systemd/shutdown 0755 root root -
   
   m /var/log/journal 2755 root systemd-journal - -
   m /var/log/journal/%m 2755 root systemd-journal - -
  +m /var/log/journal/%m/system.journal 2755 root systemd-journal - -
   m /run/log/journal 2755 root systemd-journal - -
   m /run/log/journal/%m 2755 root systemd-journal - -
  +m /run/log/journal/%m/system.journal 2755 root systemd-journal - -
 This is just a kludge... Why is system.journal to be treated differently?
 It seems that the proper fix is to set the mode on the directory properly
 during installation.

FWIW, this would also solve a problem with users who set
Storage=volatile in journald.conf. I'm not saying this is the correct
solution, but currently non-root users are unable to read from volatile
journals because the journal files are created as root:root before
tmpfiles runs.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] Fix permissions on new journal files

2014-03-13 Thread Greg KH
On Fri, Mar 14, 2014 at 03:28:27AM +0100, Zbigniew Jędrzejewski-Szmek wrote:
 On Fri, Mar 14, 2014 at 12:07:35AM +, Greg KH wrote:
  When starting up journald on a new system, set the proper permissions on
  the system.journal file, not only on the journal directory.
  
  diff --git a/tmpfiles.d/systemd.conf b/tmpfiles.d/systemd.conf
  index 7c6d6b9099b9..1aeb5e40f1ee 100644
  --- a/tmpfiles.d/systemd.conf
  +++ b/tmpfiles.d/systemd.conf
  @@ -24,5 +24,7 @@ d /run/systemd/shutdown 0755 root root -
   
   m /var/log/journal 2755 root systemd-journal - -
   m /var/log/journal/%m 2755 root systemd-journal - -
  +m /var/log/journal/%m/system.journal 2755 root systemd-journal - -
   m /run/log/journal 2755 root systemd-journal - -
   m /run/log/journal/%m 2755 root systemd-journal - -
  +m /run/log/journal/%m/system.journal 2755 root systemd-journal - -
 This is just a kludge... Why is system.journal to be treated differently?
 It seems that the proper fix is to set the mode on the directory properly
 during installation.

And how does one install /run/log/journal/ on your system?  :)

system.journal isn't to be treated differently, what happens if you
boot a box with no /run/log/journal/?  journald will startup and create
systemd.journal, and the directory tree along the way.  Then tmpfiles
will come along and set the permissions properly.

So, do you know of a different way to solve this issue without this
systemd.conf file?

thanks,

greg k-h
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 1/3] shared: add root argument to search_and_fopen

2014-03-13 Thread Michael Marineau
This adds the same root argument to search_and_fopen that
conf_files_list already has. Tools that use those two functions as a
pair can now be easily modified to load configuration files from an
alternate root filesystem tree.
---
 src/binfmt/binfmt.c |  2 +-
 src/modules-load/modules-load.c |  2 +-
 src/shared/util.c   | 12 ++--
 src/shared/util.h   |  4 ++--
 src/sysctl/sysctl.c |  2 +-
 src/tmpfiles/tmpfiles.c |  2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c
index a1877c4..9fc5d4e 100644
--- a/src/binfmt/binfmt.c
+++ b/src/binfmt/binfmt.c
@@ -86,7 +86,7 @@ static int apply_file(const char *path, bool ignore_enoent) {
 
 assert(path);
 
-r = search_and_fopen_nulstr(path, re, conf_file_dirs, f);
+r = search_and_fopen_nulstr(path, re, NULL, conf_file_dirs, f);
 if (r  0) {
 if (ignore_enoent  r == -ENOENT)
 return 0;
diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c
index 49b153d..ecb84da 100644
--- a/src/modules-load/modules-load.c
+++ b/src/modules-load/modules-load.c
@@ -145,7 +145,7 @@ static int apply_file(struct kmod_ctx *ctx, const char 
*path, bool ignore_enoent
 assert(ctx);
 assert(path);
 
-r = search_and_fopen_nulstr(path, re, conf_file_dirs, f);
+r = search_and_fopen_nulstr(path, re, NULL, conf_file_dirs, f);
 if (r  0) {
 if (ignore_enoent  r == -ENOENT)
 return 0;
diff --git a/src/shared/util.c b/src/shared/util.c
index 9e8cd54..8b8d2fb 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5668,14 +5668,14 @@ int on_ac_power(void) {
 return found_online || !found_offline;
 }
 
-static int search_and_fopen_internal(const char *path, const char *mode, char 
**search, FILE **_f) {
+static int search_and_fopen_internal(const char *path, const char *mode, const 
char *root, char **search, FILE **_f) {
 char **i;
 
 assert(path);
 assert(mode);
 assert(_f);
 
-if (!path_strv_canonicalize_absolute_uniq(search, NULL))
+if (!path_strv_canonicalize_absolute_uniq(search, root))
 return -ENOMEM;
 
 STRV_FOREACH(i, search) {
@@ -5699,7 +5699,7 @@ static int search_and_fopen_internal(const char *path, 
const char *mode, char **
 return -ENOENT;
 }
 
-int search_and_fopen(const char *path, const char *mode, const char **search, 
FILE **_f) {
+int search_and_fopen(const char *path, const char *mode, const char *root, 
const char **search, FILE **_f) {
 _cleanup_strv_free_ char **copy = NULL;
 
 assert(path);
@@ -5722,10 +5722,10 @@ int search_and_fopen(const char *path, const char 
*mode, const char **search, FI
 if (!copy)
 return -ENOMEM;
 
-return search_and_fopen_internal(path, mode, copy, _f);
+return search_and_fopen_internal(path, mode, root, copy, _f);
 }
 
-int search_and_fopen_nulstr(const char *path, const char *mode, const char 
*search, FILE **_f) {
+int search_and_fopen_nulstr(const char *path, const char *mode, const char 
*root, const char *search, FILE **_f) {
 _cleanup_strv_free_ char **s = NULL;
 
 if (path_is_absolute(path)) {
@@ -5744,7 +5744,7 @@ int search_and_fopen_nulstr(const char *path, const char 
*mode, const char *sear
 if (!s)
 return -ENOMEM;
 
-return search_and_fopen_internal(path, mode, s, _f);
+return search_and_fopen_internal(path, mode, root, s, _f);
 }
 
 char *strextend(char **x, ...) {
diff --git a/src/shared/util.h b/src/shared/util.h
index 81831e2..e99f8d1 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -696,8 +696,8 @@ char *strip_tab_ansi(char **p, size_t *l);
 
 int on_ac_power(void);
 
-int search_and_fopen(const char *path, const char *mode, const char **search, 
FILE **_f);
-int search_and_fopen_nulstr(const char *path, const char *mode, const char 
*search, FILE **_f);
+int search_and_fopen(const char *path, const char *mode, const char *root, 
const char **search, FILE **_f);
+int search_and_fopen_nulstr(const char *path, const char *mode, const char 
*root, const char *search, FILE **_f);
 
 #define FOREACH_LINE(line, f, on_error) \
 for (;;)\
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c
index 76efacb..8868732 100644
--- a/src/sysctl/sysctl.c
+++ b/src/sysctl/sysctl.c
@@ -123,7 +123,7 @@ static int parse_file(Hashmap *sysctl_options, const char 
*path, bool ignore_eno
 
 assert(path);
 
-r = search_and_fopen_nulstr(path, re, conf_file_dirs, f);
+r = search_and_fopen_nulstr(path, re, NULL, conf_file_dirs, f);
 if (r  0) {
 if (ignore_enoent  r == -ENOENT)
 return 0;
diff --git 

[systemd-devel] [PATCH 3/3] tmpfiles: Add --root to the man page.

2014-03-13 Thread Michael Marineau
---
 man/systemd-tmpfiles.xml | 8 
 1 file changed, 8 insertions(+)

diff --git a/man/systemd-tmpfiles.xml b/man/systemd-tmpfiles.xml
index 0b62640..193acb7 100644
--- a/man/systemd-tmpfiles.xml
+++ b/man/systemd-tmpfiles.xml
@@ -152,6 +152,14 @@
 prefix. This option can be specified
 multiple times./para/listitem
 /varlistentry
+varlistentry
+termoption--root=ROOT/option/term
+listitemparaTakes 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 /
-- 
1.8.3.2

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 2/3] tmpfiles: Add --root option to operate on an alternate fs tree.

2014-03-13 Thread Michael Marineau
This makes it possible to initialize or cleanup an arbitrary filesystem
hierarchy in the same way that it would be during system boot.
---
 src/tmpfiles/tmpfiles.c | 27 ---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 3684289..4ce35b5 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -111,6 +111,7 @@ static bool arg_boot = false;
 
 static char **include_prefixes = NULL;
 static char **exclude_prefixes = NULL;
+static char *arg_root = NULL;
 
 static const char conf_file_dirs[] =
 /etc/tmpfiles.d\0
@@ -1188,6 +1189,15 @@ static int parse_line(const char *fname, unsigned line, 
const char *buffer) {
 if (!should_include_path(i-path))
 return 0;
 
+if (arg_root) {
+char *p = strjoin(arg_root, i-path, NULL);
+if (!p)
+return log_oom();
+
+free(i-path);
+i-path = p;
+}
+
 if (user  !streq(user, -)) {
 const char *u = user;
 
@@ -1277,7 +1287,8 @@ static int help(void) {
 --remove   Remove marked files/directories\n
 --boot Execute actions only safe at 
boot\n
 --prefix=PATH  Only apply rules that apply to 
paths with the specified prefix\n
---exclude-prefix=PATH  Ignore rules that apply to paths 
with the specified prefix\n,
+--exclude-prefix=PATH  Ignore rules that apply to paths 
with the specified prefix\n
+--root=PATHOperate on an alternate filesystem 
root\n,
program_invocation_short_name);
 
 return 0;
@@ -1293,6 +1304,7 @@ static int parse_argv(int argc, char *argv[]) {
 ARG_BOOT,
 ARG_PREFIX,
 ARG_EXCLUDE_PREFIX,
+ARG_ROOT,
 };
 
 static const struct option options[] = {
@@ -1304,6 +1316,7 @@ static int parse_argv(int argc, char *argv[]) {
 { boot,   no_argument, NULL, ARG_BOOT
   },
 { prefix, required_argument,   NULL, ARG_PREFIX  
   },
 { exclude-prefix, required_argument,   NULL, 
ARG_EXCLUDE_PREFIX },
+{ root,   required_argument,   NULL, ARG_ROOT
   },
 {}
 };
 
@@ -1350,6 +1363,13 @@ static int parse_argv(int argc, char *argv[]) {
 return log_oom();
 break;
 
+case ARG_ROOT:
+arg_root = path_make_absolute_cwd(optarg);
+if (!arg_root)
+return log_oom();
+path_kill_slashes(arg_root);
+break;
+
 case '?':
 return -EINVAL;
 
@@ -1376,7 +1396,7 @@ static int read_config_file(const char *fn, bool 
ignore_enoent) {
 
 assert(fn);
 
-r = search_and_fopen_nulstr(fn, re, NULL, conf_file_dirs, f);
+r = search_and_fopen_nulstr(fn, re, arg_root, conf_file_dirs, f);
 if (r  0) {
 if (ignore_enoent  r == -ENOENT)
 return 0;
@@ -1477,7 +1497,7 @@ int main(int argc, char *argv[]) {
 _cleanup_strv_free_ char **files = NULL;
 char **f;
 
-r = conf_files_list_nulstr(files, .conf, NULL, 
conf_file_dirs);
+r = conf_files_list_nulstr(files, .conf, arg_root, 
conf_file_dirs);
 if (r  0) {
 log_error(Failed to enumerate tmpfiles.d files: %s, 
strerror(-r));
 goto finish;
@@ -1508,6 +1528,7 @@ finish:
 
 free(include_prefixes);
 free(exclude_prefixes);
+free(arg_root);
 
 set_free_free(unix_sockets);
 
-- 
1.8.3.2

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] machine-id: add --root option to operate on an alternate fs tree

2014-03-13 Thread Greg KH
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.

diff --git a/man/systemd-machine-id-setup.xml b/man/systemd-machine-id-setup.xml
index 5c34b345d012..b879b40b997d 100644
--- a/man/systemd-machine-id-setup.xml
+++ b/man/systemd-machine-id-setup.xml
@@ -96,6 +96,14 @@
 paraThe following options are understood:/para
 
 variablelist
+varlistentry
+termoption--root=ROOT/option/term
+listitemparaTakes 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 1b55da7e56b8..7d52b468a11a 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]) {
-int fd, r;
+static int generate(char id[34], const char *root) {
+int fd, r = 0;
 unsigned char *p;
 sd_id128_t buf;
 char *q;
 ssize_t k;
 const char *vm_id;
+char *dbus_machine_id;
 
 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);
@@ -83,7 +87,7 @@ static int generate(char id[34]) {
 id[33] = 0;
 
 log_info(Initializing machine ID from D-Bus 
machine ID.);
-return 0;
+goto finish;
 }
 }
 }
@@ -105,7 +109,8 @@ static int generate(char id[34]) {
 r = shorten_uuid(id, uuid);
 if (r = 0) {
 log_info(Initializing machine ID from 
KVM UUID.);
-return 0;
+r = 0;
+goto finish;
 }
 }
 }
@@ -124,7 +129,8 @@ static int generate(char id[34]) {
 r = shorten_uuid(id, e);
 if (r = 0) {
 log_info(Initializing machine ID from 
container UUID.);
-return 0;
+r = 0;
+goto finish;
 }
 }
 }
@@ -134,7 +140,7 @@ static int generate(char id[34]) {
 r = sd_id128_randomize(buf);
 if (r  0) {
 log_error(Failed to open /dev/urandom: %s, strerror(-r));
-return r;
+goto finish;
 }
 
 for (p = buf.bytes, q = id; p  buf.bytes + sizeof(buf); p++, q += 2) {
@@ -147,15 +153,27 @@ static int generate(char id[34]) {
 
 log_info(Initializing machine ID from random generator.);
 
-return 0;
+finish:
+free(dbus_machine_id);
+return r;
 }
 
-int machine_id_setup(void) {
+int machine_id_setup(const char *root) {
 _cleanup_close_ int fd = -1;
-int r;
+int r = 0;
 bool writable = false;
 struct stat st;
 char id[34]; /* 32 + \n + \0 */
+char *etc_machine_id = NULL;
+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) {
+r = log_oom();
+goto finish;
+}
 
 RUN_WITH_UMASK() {
 /* We create this 0444, to indicate that this isn't really
@@ -163,14 +181,15 @@ int machine_id_setup(void) {
  * will be owned by root it doesn't matter much, but maybe
  * people look. */