[systemd-devel] Regression: loop device detach errors in 220

2015-06-03 Thread Jan Janssen

Hi,

systemd-shutdown in 220 has errors when detaching loop devices:

systemd-shutdown[1]: Failed to detach loop devices: Invalid argument
cgroup: option or name mismatch, new: 0x0 , old: 0x4 systemd
systemd-shutdown[1]: Failed to detach loop devices: Invalid argument
systemd-shutdown[1]: Failed to detach loop devices: Invalid argument
systemd-shutdown[1]: Failed to finalize _ loop devices, ignoring

https://bugs.archlinux.org/task/45111

c32eb440bab953a0169cd207dfef5cad16dfb340 is the first bad commit
Author: Tom Gundersen t...@jklm.no
Date:   Tue Apr 14 16:25:06 2015 +0200

libudev: make libudev-enumerate a thin wrapper around sd-device

:100644 100644 837fd36381315029171562b344dca8620528d327 
68d8252b84c13591cf8e0b0e15a99780f5dd0309 M  Makefile.am
:04 04 c54e32bc21e34cc28693fbf653c4128a0383d3d7 
11e1eeec94338e9294e25e720007c35f229d24cf M  src


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


Re: [systemd-devel] [PATCH v3] journalctl: Improve boot ID lookup

2015-05-20 Thread Jan Janssen

Works fine. Don't forget to close the bug, though. :P

On 2015-05-19 00:37, Lennart Poettering wrote:

On Fri, 01.05.15 15:15, Jan Janssen (medhe...@web.de) wrote:


This method should greatly improve offset based lookup, by simply jumping
from one boot to the next boot. It starts at the journal head to get the
a boot ID, makes a _BOOT_ID match and then comes from the opposite
journal direction (tail) to get to the end that boot. After flushing the matches
and advancing the journal from that exact position, we arrive at the start
of next boot. Rinse and repeat.

This is faster than the old method of aggregating the full boot listing just
so we can jump to a specific boot, which can be a real pain on big journals
just for a mere -b -1 case.

As an additional benefit --list-boots should improve slightly too, because
it does less seeking.

Note that there can be a change in boot order with this lookup method
because it will use the order of boots in the journal, not the realtime stamp
stored in them. That's arguably better, though.
Another deficiency is that it will get confused with boots interleaving in the
journal, therefore, it will refuse operation in --merge, --file and
--directory mode.


I have now applied this. Afterwards I added a couple of (mostly
unrelated) clean-ups to journalctl.

Would be nice if you could verify that things still work as intended!

Lennart


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


[systemd-devel] [PATCH v3] journalctl: Improve boot ID lookup

2015-05-01 Thread Jan Janssen
This method should greatly improve offset based lookup, by simply jumping
from one boot to the next boot. It starts at the journal head to get the
a boot ID, makes a _BOOT_ID match and then comes from the opposite
journal direction (tail) to get to the end that boot. After flushing the matches
and advancing the journal from that exact position, we arrive at the start
of next boot. Rinse and repeat.

This is faster than the old method of aggregating the full boot listing just
so we can jump to a specific boot, which can be a real pain on big journals
just for a mere -b -1 case.

As an additional benefit --list-boots should improve slightly too, because
it does less seeking.

Note that there can be a change in boot order with this lookup method
because it will use the order of boots in the journal, not the realtime stamp
stored in them. That's arguably better, though.
Another deficiency is that it will get confused with boots interleaving in the
journal, therefore, it will refuse operation in --merge, --file and --directory 
mode.

https://bugs.freedesktop.org/show_bug.cgi?id=72601
---
 src/journal/journalctl.c | 275 ++-
 1 file changed, 174 insertions(+), 101 deletions(-)

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 666aa20..c059b77 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -129,6 +129,7 @@ typedef struct boot_id_t {
 sd_id128_t id;
 uint64_t first;
 uint64_t last;
+LIST_FIELDS(struct boot_id_t, boot_list);
 } boot_id_t;
 
 static void pager_open_if_enabled(void) {
@@ -733,6 +734,11 @@ static int parse_argv(int argc, char *argv[]) {
 return -EINVAL;
 }
 
+if ((arg_boot || arg_action == ACTION_LIST_BOOTS)  (arg_file || 
arg_directory || arg_merge)) {
+log_error(Using --boot or --list-boots with --file, 
--directory or --merge is not supported.);
+return -EINVAL;
+}
+
 return 1;
 }
 
@@ -852,111 +858,203 @@ static int add_matches(sd_journal *j, char **args) {
 return 0;
 }
 
-static int boot_id_cmp(const void *a, const void *b) {
-uint64_t _a, _b;
+static int discover_next_boot(sd_journal *j,
+  boot_id_t **boot,
+  bool advance_older,
+  bool read_realtime) {
+int r;
+char match[9+32+1] = _BOOT_ID=;
+_cleanup_free_ boot_id_t *next_boot = NULL;
 
-_a = ((const boot_id_t *)a)-first;
-_b = ((const boot_id_t *)b)-first;
+assert(j);
+assert(boot);
 
-return _a  _b ? -1 : (_a  _b ? 1 : 0);
-}
+/* We expect the journal to be on the last position of a boot
+ * (in relation to the direction we are going), so that the next
+ * invocation of sd_journal_next/previous will be from a different
+ * boot. We then collect any information we desire and then jump
+ * to the last location of the new boot by using a _BOOT_ID match
+ * coming from the other journal direction. */
 
-static int get_boots(sd_journal *j,
- boot_id_t **boots,
- unsigned int *count,
- boot_id_t *query_ref_boot) {
-int r;
-const void *data;
-size_t length, allocated = 0;
+/* Make sure we aren't restricted by any _BOOT_ID matches, so that
+ * we can actually advance to a *different* boot. */
+sd_journal_flush_matches(j);
 
-assert(j);
-assert(boots);
-assert(count);
+if (advance_older)
+r = sd_journal_previous(j);
+else
+r = sd_journal_next(j);
+if (r  0)
+return r;
+else if (r == 0)
+return 0; /* End of journal, yay. */
+
+next_boot = new0(boot_id_t, 1);
+if (!next_boot)
+return log_oom();
 
-r = sd_journal_query_unique(j, _BOOT_ID);
+r = sd_journal_get_monotonic_usec(j, NULL, next_boot-id);
 if (r  0)
 return r;
 
-*count = 0;
-SD_JOURNAL_FOREACH_UNIQUE(j, data, length) {
-boot_id_t *id;
+if (read_realtime) {
+r = sd_journal_get_realtime_usec(j, next_boot-first);
+if (r  0)
+return r;
+}
 
-assert(startswith(data, _BOOT_ID=));
+/* Now seek to the last occurrence of this boot ID. */
+sd_id128_to_string(next_boot-id, match + 9);
+r = sd_journal_add_match(j, match, sizeof(match) - 1);
+if (r  0)
+return r;
 
-if (!GREEDY_REALLOC(*boots, allocated, *count + 1))
-return log_oom();
+if (advance_older)
+r = sd_journal_seek_head(j);
+else
+r = sd_journal_seek_tail(j);
+if (r  0)
+  

Re: [systemd-devel] [PATCH v2] journalctl: Improve boot ID lookup

2015-04-25 Thread Jan Janssen

On 2015-04-08 16:14, Jan Janssen wrote:



On 2015-04-08 14:39, Lennart Poettering wrote:

On Thu, 02.04.15 17:08, Jan Janssen (medhe...@web.de) wrote:


This method should greatly improve offset based lookup. We now don't
have
to aggregate the full boot listing just so we can jump to a specific
position,
which can be a real pain on big journals just for a mere -b -1 case.

As an additional benefit --list-boots should improve slightly too,
because
we now need to do less seeking.

Note that there can be a change in boot order with this lookup method
because it will use the order of boots in the journal, not the
realtime stamp
stored in them. That's arguably better, though.

https://bugs.freedesktop.org/show_bug.cgi?id=72601
---
Hi,

today I realized that it would be nice if we could do without the
cursor seeking.
Turns out we can! I could swear that I tested
sd_journal_flush_matches() would
reset our position in the journal. But it seems that
sd_journal_next/previous
will advance just fine from the last position we were in, even after
a flush.

Though, I would still like someone with better journal internals
knowledge confirm
that this is how it's supposed to work.

Some testing/timing from others than me would be nice too.


Hmm, the patch is hard to read, can you explain what precisely the new
algorithm is you propose?

Lennart



Yeah, patches like these always do end up looking messy. It's much
easier to read after applying it.

Well, it jumps from one boot to the next boot using _BOOT_ID matches. It
starts at the journal head to get the boot ID, makes a _BOOT_ID match
and then comes from the opposite journal direction (tail) to get the end
a boot. And then flushes the matches, and advances the journal from that
exact position one further (which gives us the start and ID of our next
boot). Rinse and repeat.
Note, v1 differs in that it assumes sd_journal_flush_matches() will also
reset the position we are in the journal at that moment. That version
went around that by using a cursor and seeking to the after flushing.
Hence why I wonder if this behavior of slush_matches is expected/desired
or not.

This is much faster for relative boot ID lookups, for the very reason
that you don't have to look at all boots. Though, it does make the
assumption that all boots (IDs) are assumed to not interleave
(constellations like A B A C cannot happen), which afaik would be
satisfied on single host machines.

Later after sending this patch I realized that it could probably break
on journals with more than one machine ID, since then boot IDs can
interleave due to them running in parallel, breaking a important
assumption. Though, I *should* be able to fix that by adding some
_MACHINE_ID matches in the mix.

Adding machine ID matches would make --list-boots behavior differ quite
a lot. For one, with this approach, there isn't any global ordering of
boots across machine IDs. Personally, I find this ordering (although you
can define it as *a* valid ordering) to be useless. Doing a journalctl
-b boodID-1 match, for example, should use that bootID's machine ID to
get to the previous boot (of that machine). Right now it can get you any
bootID from any other machine, so long as it was booted right before it.

So yeah, I will make this patch work for journals with more than one
machine ID if this approach is desired.

Jan


I gave this another look today. Since journalctl uses 
SD_JOURNAL_LOCAL_ONLY by default, the new algorithm cannot trip up on 
interleaving boot IDs (since they shouldn't be interleaving in that 
case, per the above assumption). Same goes for --machine mode. Now, 
--file, --directory and --merge mode on the other hand does confuse the 
new algorithm.


But I think it might be worth it to go with my above suggestion if 
that'll be accepted. Alternatively, we could either refuse --boot and 
--list-boots in those cases, or ship the old algorithm along with the 
new one and use that one in those cases where the faster one gets confused.


Or we stick with status quo and don't improve on the algorithm 
altogether. I'd like to know the option to go with, to ease me mind...


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


Re: [systemd-devel] [PATCH] systemctl: Use logind for --firmware-setup if possible

2015-04-08 Thread Jan Janssen

What's the point in retrying if you got EOPNOTSUPP the first time? :P

Jan

On 2015-04-08 18:24, Lennart Poettering wrote:

On Wed, 08.04.15 16:49, Jan Janssen (medhe...@web.de) wrote:

Awesome! Thanks!

Applied! (Though I took the liberty to swap the order around, to first
try direct access, and only the fall back via logind.

Thanks,

Lennart


---
  src/systemctl/systemctl.c | 43 ++-
  1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index ae87e44..caa8d07 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2913,6 +2913,41 @@ static int check_inhibitors(sd_bus *bus, enum action a) {
  #endif
  }

+static int prepare_firmware_setup(sd_bus *bus) {
+int r;
+_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+
+if (!arg_firmware_setup)
+return 0;
+
+#ifdef HAVE_LOGIND
+r = sd_bus_call_method(
+bus,
+org.freedesktop.login1,
+/org/freedesktop/login1,
+org.freedesktop.login1.Manager,
+SetRebootToFirmwareSetup,
+error,
+NULL,
+b, true);
+if (r  0)
+log_error(Cannot indicate to EFI to boot into setup mode: %s, 
bus_error_message(error, r));
+
+/* No point trying to fall back. */
+if (r == -EOPNOTSUPP)
+return r;
+#endif
+
+if (arg_transport != BUS_TRANSPORT_LOCAL)
+return log_error_errno(-EINVAL, Cannot remotely indicate to EFI to 
boot into setup mode.);
+
+r = efi_set_reboot_to_firmware(true);
+if (r  0)
+return log_error_errno(r, Cannot indicate to EFI to boot into 
setup mode: %m);
+
+return 0;
+}
+
  static int start_special(sd_bus *bus, char **args) {
  enum action a;
  int r;
@@ -2930,11 +2965,9 @@ static int start_special(sd_bus *bus, char **args) {
  return -EPERM;
  }

-if (arg_firmware_setup) {
-r = efi_set_reboot_to_firmware(true);
-if (r  0)
-return log_error_errno(r, Cannot indicate to EFI to boot 
into setup mode: %m);
-}
+r = prepare_firmware_setup(bus);
+if (r  0)
+return r;

  if (a == ACTION_REBOOT  args[1]) {
  r = update_reboot_param_file(args[1]);
--
2.3.5

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



Lennart


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


Re: [systemd-devel] [PATCH v2] journalctl: Improve boot ID lookup

2015-04-08 Thread Jan Janssen



On 2015-04-08 14:39, Lennart Poettering wrote:

On Thu, 02.04.15 17:08, Jan Janssen (medhe...@web.de) wrote:


This method should greatly improve offset based lookup. We now don't have
to aggregate the full boot listing just so we can jump to a specific position,
which can be a real pain on big journals just for a mere -b -1 case.

As an additional benefit --list-boots should improve slightly too, because
we now need to do less seeking.

Note that there can be a change in boot order with this lookup method
because it will use the order of boots in the journal, not the realtime stamp
stored in them. That's arguably better, though.

https://bugs.freedesktop.org/show_bug.cgi?id=72601
---
Hi,

today I realized that it would be nice if we could do without the cursor 
seeking.
Turns out we can! I could swear that I tested sd_journal_flush_matches() would
reset our position in the journal. But it seems that sd_journal_next/previous
will advance just fine from the last position we were in, even after a flush.

Though, I would still like someone with better journal internals knowledge 
confirm
that this is how it's supposed to work.

Some testing/timing from others than me would be nice too.


Hmm, the patch is hard to read, can you explain what precisely the new
algorithm is you propose?

Lennart



Yeah, patches like these always do end up looking messy. It's much 
easier to read after applying it.


Well, it jumps from one boot to the next boot using _BOOT_ID matches. It 
starts at the journal head to get the boot ID, makes a _BOOT_ID match 
and then comes from the opposite journal direction (tail) to get the end 
a boot. And then flushes the matches, and advances the journal from that 
exact position one further (which gives us the start and ID of our next 
boot). Rinse and repeat.
Note, v1 differs in that it assumes sd_journal_flush_matches() will also 
reset the position we are in the journal at that moment. That version 
went around that by using a cursor and seeking to the after flushing. 
Hence why I wonder if this behavior of slush_matches is expected/desired 
or not.


This is much faster for relative boot ID lookups, for the very reason 
that you don't have to look at all boots. Though, it does make the 
assumption that all boots (IDs) are assumed to not interleave 
(constellations like A B A C cannot happen), which afaik would be 
satisfied on single host machines.


Later after sending this patch I realized that it could probably break 
on journals with more than one machine ID, since then boot IDs can 
interleave due to them running in parallel, breaking a important 
assumption. Though, I *should* be able to fix that by adding some 
_MACHINE_ID matches in the mix.


Adding machine ID matches would make --list-boots behavior differ quite 
a lot. For one, with this approach, there isn't any global ordering of 
boots across machine IDs. Personally, I find this ordering (although you 
can define it as *a* valid ordering) to be useless. Doing a journalctl 
-b boodID-1 match, for example, should use that bootID's machine ID to 
get to the previous boot (of that machine). Right now it can get you any 
bootID from any other machine, so long as it was booted right before it.


So yeah, I will make this patch work for journals with more than one 
machine ID if this approach is desired.


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


[systemd-devel] [PATCH] systemctl: Use logind for --firmware-setup if possible

2015-04-08 Thread Jan Janssen
---
 src/systemctl/systemctl.c | 43 ++-
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index ae87e44..caa8d07 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2913,6 +2913,41 @@ static int check_inhibitors(sd_bus *bus, enum action a) {
 #endif
 }
 
+static int prepare_firmware_setup(sd_bus *bus) {
+int r;
+_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+
+if (!arg_firmware_setup)
+return 0;
+
+#ifdef HAVE_LOGIND
+r = sd_bus_call_method(
+bus,
+org.freedesktop.login1,
+/org/freedesktop/login1,
+org.freedesktop.login1.Manager,
+SetRebootToFirmwareSetup,
+error,
+NULL,
+b, true);
+if (r  0)
+log_error(Cannot indicate to EFI to boot into setup mode: 
%s, bus_error_message(error, r));
+
+/* No point trying to fall back. */
+if (r == -EOPNOTSUPP)
+return r;
+#endif
+
+if (arg_transport != BUS_TRANSPORT_LOCAL)
+return log_error_errno(-EINVAL, Cannot remotely indicate to 
EFI to boot into setup mode.);
+
+r = efi_set_reboot_to_firmware(true);
+if (r  0)
+return log_error_errno(r, Cannot indicate to EFI to boot into 
setup mode: %m);
+
+return 0;
+}
+
 static int start_special(sd_bus *bus, char **args) {
 enum action a;
 int r;
@@ -2930,11 +2965,9 @@ static int start_special(sd_bus *bus, char **args) {
 return -EPERM;
 }
 
-if (arg_firmware_setup) {
-r = efi_set_reboot_to_firmware(true);
-if (r  0)
-return log_error_errno(r, Cannot indicate to EFI to 
boot into setup mode: %m);
-}
+r = prepare_firmware_setup(bus);
+if (r  0)
+return r;
 
 if (a == ACTION_REBOOT  args[1]) {
 r = update_reboot_param_file(args[1]);
-- 
2.3.5

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


[systemd-devel] [PATCH v3] Add reboot to EFI support

2015-04-03 Thread Jan Janssen
---
Hi,

Changes in v3:
 - call the feature reboot to firmware everywhere
 - make the login interface a property and methods to change it and
   don't couple it with a reboot action
 - changed/added policykit action defaulting to auth_admin_keep. Please
   change this if something else is desired.

The policy kit behavior feels weird to me: if I call bus_verify_polkit()
with interactive = false, I still get a password prompt for CanRebootToFirmware.
Is this a bug or am I doing something wrong here? Do I need to make a separate
get policy (with no auth_admin_keep) for this to work?

Jan

 man/systemctl.xml  | 10 
 shell-completion/bash/systemctl.in |  2 +-
 shell-completion/zsh/_systemctl.in |  1 +
 src/login/logind-dbus.c| 96 ++
 src/login/org.freedesktop.login1.conf  |  8 +++
 src/login/org.freedesktop.login1.policy.in | 10 
 src/shared/efivars.c   | 73 +++
 src/shared/efivars.h   |  3 +
 src/systemctl/systemctl.c  | 18 ++
 9 files changed, 220 insertions(+), 1 deletion(-)

diff --git a/man/systemctl.xml b/man/systemctl.xml
index 50e6bc9..b77f4ab 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -527,6 +527,16 @@
   /varlistentry
 
   varlistentry
+termoption--firmware-setup/option/term
+
+listitem
+  paraIndicate to the firmware to boot into setup mode. Note
+  that this is currently only supported on some EFI systems and
+  only if it was booted in EFI mode./para
+/listitem
+  /varlistentry
+
+  varlistentry
 termoption--plain/option/term
 
 listitem
diff --git a/shell-completion/bash/systemctl.in 
b/shell-completion/bash/systemctl.in
index 8063316..773a59d 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -92,7 +92,7 @@ _systemctl () {
 local -A OPTS=(
[STANDALONE]='--all -a --reverse --after --before --defaults 
--fail --ignore-dependencies --failed --force -f --full -l --global
  --help -h --no-ask-password --no-block 
--no-legend --no-pager --no-reload --no-wall
- --quiet -q --privileged -P --system --user 
--version --runtime --recursive -r'
+ --quiet -q --privileged -P --system --user 
--version --runtime --recursive -r --firmware-setup'
   [ARG]='--host -H --kill-who --property -p --signal -s 
--type -t --state --root'
 )
 
diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index 7f2d5ac..3bbfb6f 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -384,5 +384,6 @@ _arguments -s \
 {-P,--privileged}'[Acquire privileges before execution]' \
 {-n+,--lines=}'[Journal entries to show]:number of entries' \
 {-o+,--output=}'[Change journal output mode]:modes:_sd_outputmodes' \
+'--firmware-setup[Tell the firmware to show the setup menu on next boot]' \
 '--plain[When used with list-dependencies, print output as a list]' \
 '*::systemctl command:_systemctl_command'
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index a3d49ef..cea99fc 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -38,6 +38,7 @@
 #include bus-common-errors.h
 #include udev-util.h
 #include selinux-util.h
+#include efivars.h
 #include logind.h
 
 int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const 
char *name, sd_bus_error *error, Session **ret) {
@@ -1850,6 +1851,98 @@ static int method_can_hybrid_sleep(sd_bus *bus, 
sd_bus_message *message, void *u
 error);
 }
 
+static int property_get_reboot_to_firmware(
+sd_bus *bus,
+const char *path,
+const char *interface,
+const char *property,
+sd_bus_message *reply,
+void *userdata,
+sd_bus_error *error) {
+int r;
+
+assert(bus);
+assert(reply);
+assert(userdata);
+
+r = efi_get_reboot_to_fw();
+if (r  0  r != -EOPNOTSUPP)
+return r;
+
+return sd_bus_message_append(reply, b, r  0);
+}
+
+static int method_set_reboot_to_firmware(sd_bus *bus,
+ sd_bus_message *message,
+ void *userdata,
+ sd_bus_error *error) {
+int b, r;
+int interactive;
+Manager *m = userdata;
+
+assert(bus);
+assert(message);
+assert(m);
+
+r = sd_bus_message_read(message, bb, b, interactive);
+if (r  0)
+return r;
+
+r = bus_verify_polkit_async(message,
+CAP_SYS_ADMIN,
+  

[systemd-devel] [PATCH v4] Add reboot to EFI support

2015-04-03 Thread Jan Janssen
---
Changes in v4:
 - better logind API naming
 - don't write to efi vars if they don't change

 man/systemctl.xml  | 10 +++
 shell-completion/bash/systemctl.in |  2 +-
 shell-completion/zsh/_systemctl.in |  1 +
 src/login/logind-dbus.c| 99 ++
 src/login/org.freedesktop.login1.conf  |  8 +++
 src/login/org.freedesktop.login1.policy.in | 10 +++
 src/shared/efivars.c   | 72 ++
 src/shared/efivars.h   |  3 +
 src/systemctl/systemctl.c  | 15 +
 9 files changed, 219 insertions(+), 1 deletion(-)

diff --git a/man/systemctl.xml b/man/systemctl.xml
index 50e6bc9..b77f4ab 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -527,6 +527,16 @@
   /varlistentry
 
   varlistentry
+termoption--firmware-setup/option/term
+
+listitem
+  paraIndicate to the firmware to boot into setup mode. Note
+  that this is currently only supported on some EFI systems and
+  only if it was booted in EFI mode./para
+/listitem
+  /varlistentry
+
+  varlistentry
 termoption--plain/option/term
 
 listitem
diff --git a/shell-completion/bash/systemctl.in 
b/shell-completion/bash/systemctl.in
index 8063316..773a59d 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -92,7 +92,7 @@ _systemctl () {
 local -A OPTS=(
[STANDALONE]='--all -a --reverse --after --before --defaults 
--fail --ignore-dependencies --failed --force -f --full -l --global
  --help -h --no-ask-password --no-block 
--no-legend --no-pager --no-reload --no-wall
- --quiet -q --privileged -P --system --user 
--version --runtime --recursive -r'
+ --quiet -q --privileged -P --system --user 
--version --runtime --recursive -r --firmware-setup'
   [ARG]='--host -H --kill-who --property -p --signal -s 
--type -t --state --root'
 )
 
diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index 7f2d5ac..3bbfb6f 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -384,5 +384,6 @@ _arguments -s \
 {-P,--privileged}'[Acquire privileges before execution]' \
 {-n+,--lines=}'[Journal entries to show]:number of entries' \
 {-o+,--output=}'[Change journal output mode]:modes:_sd_outputmodes' \
+'--firmware-setup[Tell the firmware to show the setup menu on next boot]' \
 '--plain[When used with list-dependencies, print output as a list]' \
 '*::systemctl command:_systemctl_command'
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index a3d49ef..c14f02d 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -38,6 +38,7 @@
 #include bus-common-errors.h
 #include udev-util.h
 #include selinux-util.h
+#include efivars.h
 #include logind.h
 
 int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const 
char *name, sd_bus_error *error, Session **ret) {
@@ -1850,6 +1851,101 @@ static int method_can_hybrid_sleep(sd_bus *bus, 
sd_bus_message *message, void *u
 error);
 }
 
+static int property_get_reboot_to_firmware_setup(
+sd_bus *bus,
+const char *path,
+const char *interface,
+const char *property,
+sd_bus_message *reply,
+void *userdata,
+sd_bus_error *error) {
+int r;
+
+assert(bus);
+assert(reply);
+assert(userdata);
+
+r = efi_get_reboot_to_firmware();
+if (r  0  r != -EOPNOTSUPP)
+return r;
+
+return sd_bus_message_append(reply, b, r  0);
+}
+
+static int method_set_reboot_to_firmware_setup(sd_bus *bus,
+ sd_bus_message *message,
+ void *userdata,
+ sd_bus_error *error) {
+int b, r;
+int interactive;
+Manager *m = userdata;
+
+assert(bus);
+assert(message);
+assert(m);
+
+r = sd_bus_message_read(message, bb, b, interactive);
+if (r  0)
+return r;
+
+r = bus_verify_polkit_async(message,
+CAP_SYS_ADMIN,
+
org.freedesktop.login1.set-reboot-to-firmware-setup,
+interactive,
+UID_INVALID,
+m-polkit_registry,
+error);
+if (r  0)
+return r;
+if (r == 0)
+return 1; /* No authorization for now, but the async polkit 
stuff will call us again when it has it */
+
+r = 

[systemd-devel] [PATCH v2] journalctl: Improve boot ID lookup

2015-04-02 Thread Jan Janssen
This method should greatly improve offset based lookup. We now don't have
to aggregate the full boot listing just so we can jump to a specific position,
which can be a real pain on big journals just for a mere -b -1 case.

As an additional benefit --list-boots should improve slightly too, because
we now need to do less seeking.

Note that there can be a change in boot order with this lookup method
because it will use the order of boots in the journal, not the realtime stamp
stored in them. That's arguably better, though.

https://bugs.freedesktop.org/show_bug.cgi?id=72601
---
Hi,

today I realized that it would be nice if we could do without the cursor 
seeking.
Turns out we can! I could swear that I tested sd_journal_flush_matches() would
reset our position in the journal. But it seems that sd_journal_next/previous
will advance just fine from the last position we were in, even after a flush.

Though, I would still like someone with better journal internals knowledge 
confirm
that this is how it's supposed to work.

Some testing/timing from others than me would be nice too.

Jan
 src/journal/journalctl.c | 270 +--
 1 file changed, 169 insertions(+), 101 deletions(-)

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index b4f88bc..08cd749 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -128,6 +128,7 @@ typedef struct boot_id_t {
 sd_id128_t id;
 uint64_t first;
 uint64_t last;
+LIST_FIELDS(struct boot_id_t, boot_list);
 } boot_id_t;
 
 static void pager_open_if_enabled(void) {
@@ -851,111 +852,203 @@ static int add_matches(sd_journal *j, char **args) {
 return 0;
 }
 
-static int boot_id_cmp(const void *a, const void *b) {
-uint64_t _a, _b;
+static int discover_next_boot(sd_journal *j,
+  boot_id_t **boot,
+  bool advance_older,
+  bool read_realtime) {
+int r;
+char match[9+32+1] = _BOOT_ID=;
+_cleanup_free_ boot_id_t *next_boot = NULL;
 
-_a = ((const boot_id_t *)a)-first;
-_b = ((const boot_id_t *)b)-first;
+assert(j);
+assert(boot);
 
-return _a  _b ? -1 : (_a  _b ? 1 : 0);
-}
+/* We expect the journal to be on the last position of a boot
+ * (in relation to the direction we are going), so that the next
+ * invocation of sd_journal_next/previous will be from a different
+ * boot. We then collect any information we desire and then jump
+ * to the last location of the new boot by using a _BOOT_ID match
+ * coming from the other journal direction. */
 
-static int get_boots(sd_journal *j,
- boot_id_t **boots,
- unsigned int *count,
- boot_id_t *query_ref_boot) {
-int r;
-const void *data;
-size_t length, allocated = 0;
+/* Make sure we aren't restricted by any _BOOT_ID matches, so that
+ * we can actually advance to a *different* boot. */
+sd_journal_flush_matches(j);
 
-assert(j);
-assert(boots);
-assert(count);
+if (advance_older)
+r = sd_journal_previous(j);
+else
+r = sd_journal_next(j);
+if (r  0)
+return r;
+else if (r == 0)
+return 0; /* End of journal, yay. */
 
-r = sd_journal_query_unique(j, _BOOT_ID);
+next_boot = new0(boot_id_t, 1);
+if (!next_boot)
+return log_oom();
+
+r = sd_journal_get_monotonic_usec(j, NULL, next_boot-id);
 if (r  0)
 return r;
 
-*count = 0;
-SD_JOURNAL_FOREACH_UNIQUE(j, data, length) {
-boot_id_t *id;
+if (read_realtime) {
+r = sd_journal_get_realtime_usec(j, next_boot-first);
+if (r  0)
+return r;
+}
 
-assert(startswith(data, _BOOT_ID=));
+/* Now seek to the last occurrence of this boot ID. */
+sd_id128_to_string(next_boot-id, match + 9);
+r = sd_journal_add_match(j, match, sizeof(match) - 1);
+if (r  0)
+return r;
 
-if (!GREEDY_REALLOC(*boots, allocated, *count + 1))
-return log_oom();
+if (advance_older)
+r = sd_journal_seek_head(j);
+else
+r = sd_journal_seek_tail(j);
+if (r  0)
+return r;
 
-id = *boots + *count;
+if (advance_older)
+r = sd_journal_next(j);
+else
+r = sd_journal_previous(j);
+if (r  0)
+return r;
+else if (r == 0)
+return -ENODATA; /* This shouldn't happen. We just came from 
this very boot ID. */
 
-r = 

Re: [systemd-devel] [PATCH v2] Add reboot to EFI support

2015-04-02 Thread Jan Janssen

Hi,

On 2015-04-02 11:34, Lennart Poettering wrote:

On Thu, 26.03.15 16:09, Jan Janssen (medhe...@web.de) wrote:

Heya,

Hmm, so we already support passing special reboot() parameters, and
this is done by manipulating a file in /run, without introducing any
new targets. To me it appears that boot-into-firmware-setup is
something hat should be handled the same way, i.e. as a special
parameter for the *normal* poweroff path, instead of introducing a new
poweroff path for it. Of course, instead of manipulating /run for this
we should directly manipulate the respective EFI variable.

I hence think this should be a new switch --firmware-setup or so to
systemctl. Of course, that sounds awfully specific and I don't really
like too much adding a new switch just for this flag, but it's the
least best option I see.


That was my original approach. Kay said --firmware sounded weird.


The existing boot argument is passed as-is to the kernel, hence
giving the argument efi a special meaning would mean once couldn't
pass that parameter anymore to the kernel.


I had the same reservation, but it was suggested to ignore this and just 
piggyback on this instead.



I would strongly prefer naming the switch something like firmware
instead of EFI, since we shouldn't encode the technology here, but
the generic term. Also, this should mention that this is about the
setup tool of the firmware, since EFI is available all the time, and
this is really about the *setup* tool of the firmware...


Someone suggested firmware is too generic, so I switched to EFI. Would 
be nice if people made up their mind on that one...



I think ultimately we need to expose this even in GNOME, similar to
the way Window exposes this. To cover that we should probably add a
bus API to logind in some form to manipulate the EFI var in question,
and systemctl reboot --firmware-setup would use that. (And yes, a
similar bus API for specifying the generic reboot parameter probably
should exist alongside it).


Äääähm... this is exactly what this patch does, adding CanRebootToEfi()
and a RebootToEfi() functions. What did I miss?

Unless you mean changing those into a pair of properties to just set the
indication and then the bus client would have to manually trigger Reboot()?
In fact, that's what I kind of got in my mind after sending this patch. 
It would also work nicely with a separate RebootArguments property 
without the hassle of introducing more complex logic into the target 
related functions in logind. My original approach was adding a 
RebootWithArguments function, but my brain cannot get the code to look 
nicely. But making them into properties and requiring the client to 
issue a Reboot themselves would be a neat way around that.



Of course the bus API should also support a CanFirmwareSetup() call or
so, that reports whether the logic is available at all.


As I said, this patch adds this. Though, it would be nice if some 
consensus would come about whether to call this firmware or EFI. I think 
being specific is probably nicer. Unless this were to return a string 
indicating what kind of firmware setup is supported (if ever any others 
would come about in the future), returning efi for EFI systems.



Does this make sense?

Lennart



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


[systemd-devel] [RFC/PATCH] journalctl: Improve boot ID lookup

2015-04-01 Thread Jan Janssen
This method shouldn't provide any noticeable speedup for the --list-boots
case, but any offset based lookup should be greatly improved.
We now don't have to aggregate the full boot listing just so we can jump
to specific position, which can be a real pain on big journals just for
a mere -b -1 case.

--list-boots might get a little slower, but not by much. And keeping
--boot and --list-boots' idea of boots consistent should justify the slight
increase.

Note that there can be a change in boot order in this --list-boots version
because it will use the order of boots in journals, not the realtime stamp
stored in them. That's arguably better, though.

https://bugs.freedesktop.org/show_bug.cgi?id=72601
---
Hi,

I can't believe I didn't come up with this one sooner. The details how it works
are in the comments, but I could use some testing by people who have tons of
boots in their journal. I only have 58, which doesn't make --boot -1 that big a
pain, but I still do get an improvement: ~2s without and ~0s lookup with this 
patch
applied (using /proc/sys/vm/drop_caches of course).

The patch could use some testing/timing with huge journals, and *especially* 
with
some corrupted journals in the mix, since I have none right now (fresh 
computer, yay).

Jan

 src/journal/journalctl.c | 301 +++
 1 file changed, 200 insertions(+), 101 deletions(-)

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index b4f88bc..bdfa0b0 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -128,6 +128,7 @@ typedef struct boot_id_t {
 sd_id128_t id;
 uint64_t first;
 uint64_t last;
+LIST_FIELDS(struct boot_id_t, boot_list);
 } boot_id_t;
 
 static void pager_open_if_enabled(void) {
@@ -851,111 +852,234 @@ static int add_matches(sd_journal *j, char **args) {
 return 0;
 }
 
-static int boot_id_cmp(const void *a, const void *b) {
-uint64_t _a, _b;
+static int discover_next_boot(sd_journal *j,
+  boot_id_t **boot,
+  char **cursor,
+  bool advance_left,
+  bool read_realtime) {
+int r;
+char match[9+32+1] = _BOOT_ID=;
+_cleanup_free_ boot_id_t *next_boot = NULL;
 
-_a = ((const boot_id_t *)a)-first;
-_b = ((const boot_id_t *)b)-first;
+assert(j);
+assert(boot);
+assert(cursor);
 
-return _a  _b ? -1 : (_a  _b ? 1 : 0);
-}
+/* We expect the cursor to point us to the last position
+ * of a boot, so that the next invocation of sd_j_next would be
+ * from a different boot. We collect any information we desire
+ * and then jump to the last location of the new boot by using
+ * a _BOOT_ID match and coming from the other journal direction
+ * (the tail). Since we wouldn't then be able to advance to the
+ * next boot using sd_j_next, we take a cursor and rinse and repeat. */
 
-static int get_boots(sd_journal *j,
- boot_id_t **boots,
- unsigned int *count,
- boot_id_t *query_ref_boot) {
-int r;
-const void *data;
-size_t length, allocated = 0;
+sd_journal_flush_matches(j);
 
-assert(j);
-assert(boots);
-assert(count);
+if (*cursor) {
+r = sd_journal_seek_cursor(j, *cursor);
+if (r  0)
+return r;
+
+if (advance_left)
+r = sd_journal_previous(j);
+else
+r = sd_journal_next(j);
+if (r  0)
+return r;
+else if (r == 0)
+return -ENODATA; /* We were here last time, odd. */
+} else {
+if (advance_left)
+r = sd_journal_seek_tail(j);
+else
+r = sd_journal_seek_head(j);
+if (r  0)
+return r;
+}
 
-r = sd_journal_query_unique(j, _BOOT_ID);
+/* Advance to next boot. */
+if (advance_left)
+r = sd_journal_previous(j);
+else
+r = sd_journal_next(j);
 if (r  0)
 return r;
+else if (r == 0) {
+/* End of journal, yay. */
+*boot = NULL;
+return 0;
+}
 
-*count = 0;
-SD_JOURNAL_FOREACH_UNIQUE(j, data, length) {
-boot_id_t *id;
+next_boot = new0(boot_id_t, 1);
+if (!next_boot)
+return log_oom();
 
-assert(startswith(data, _BOOT_ID=));
+r = sd_journal_get_monotonic_usec(j, NULL, next_boot-id);
+if (r  0)
+return r;
 
-if (!GREEDY_REALLOC(*boots, allocated, *count + 1))

Re: [systemd-devel] journalctl not showing most boots/logs

2015-03-27 Thread Jan Janssen



On 2015-03-27 21:06, Michael Biebl wrote:

2015-03-27 20:45 GMT+01:00 Jan Janssen medhe...@web.de:

Martin Pitt martin.pitt at ubuntu.com writes:



Hello all,

in [1] I just got a report that journalctl --list-boots (with
persistant journal) only shows a few old boots, but not current ones.
I checked this on my system (which has had persistant journal for a
while), and confirm that:


What does journalctl -F _BOOT_ID | wc -l vs journalctl --list-boots | wc
-l say?


I can confirm the issue:


# journalctl -F _BOOT_ID | wc -l
160
# journalctl --list-boots | wc -l
106


This is on an ext4, no separate /var partition.




Well, the one reason I could think of right now is that there must be 
some corrupted journals in there. Can you see if there are any using 
--verify and then moving them out of the journal directory?


journalctl -F vs journalctl --list-boots use different code paths while 
digging through the journal. Afaik, one of them is stricter when it 
comes to interleaving intact and corrupted journals.


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


Re: [systemd-devel] journalctl not showing most boots/logs

2015-03-27 Thread Jan Janssen
Martin Pitt martin.pitt at ubuntu.com writes:

 
 Hello all,
 
 in [1] I just got a report that journalctl --list-boots (with
 persistant journal) only shows a few old boots, but not current ones.
 I checked this on my system (which has had persistant journal for a
 while), and confirm that:

What does journalctl -F _BOOT_ID | wc -l vs journalctl --list-boots | wc
-l say?


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


Re: [systemd-devel] journalctl not showing most boots/logs

2015-03-27 Thread Jan Janssen
There are still some journal~ files there. They may not be corrupted, 
but maybe still trip some journal interleaving code up. Can see how it 
fares without those?


Jan

On 2015-03-27 21:44, Michael Biebl wrote:

# journalctl --verify
PASS: 
/var/log/journal/567a68a5c2672114bcf5192d0008/system@32eb70b2195d4cf69066be8d99a7a407-0001-00050f6ed83c9f0d.journal
PASS: 
/var/log/journal/567a68a5c2672114bcf5192d0008/user-1000@690216233b624f11a2201e9f98176515-0021f2f2-00050c4b51fd09dc.journal
PASS: /var/log/journal/567a68a5c2672114bcf5192d0008/user-65534.journal
PASS: /var/log/journal/567a68a5c2672114bcf5192d0008/user-109.journal
PASS: 
/var/log/journal/567a68a5c2672114bcf5192d0008/system@00050f6458a7e3b4-0b0258d981908105.journal~
PASS: /var/log/journal/567a68a5c2672114bcf5192d0008/user-1000.journal
PASS: 
/var/log/journal/567a68a5c2672114bcf5192d0008/system@32eb70b2195d4cf69066be8d99a7a407-0009-00050f6ee60496f2.journal
PASS: 
/var/log/journal/567a68a5c2672114bcf5192d0008/system@00050f6483661de1-53b8b8eea3ee8e5e.journal~
PASS: /var/log/journal/567a68a5c2672114bcf5192d0008/system.journal
PASS: 
/var/log/journal/567a68a5c2672114bcf5192d0008/user-65534@00050f646a4541ba-a7026dec325dbd3f.journal~
PASS: 
/var/log/journal/567a68a5c2672114bcf5192d0008/user-65534@e4481be943ee4a06b58d354296d7-002a7bbc-000511cf7a32c29a.journal
PASS: 
/var/log/journal/567a68a5c2672114bcf5192d0008/system@000511cfb123cc25-32fec68ddf36aac2.journal~
PASS: 
/var/log/journal/567a68a5c2672114bcf5192d0008/system@00050e650144ab12-15158e9a9df4f071.journal~
7fffee0: unused data
(entry_offset==0)██
  48%
PASS: 
/var/log/journal/567a68a5c2672114bcf5192d0008/system@718656154e1546fcb5d438a9edf3155f-0001-00050c4b51788fe4.journal
PASS: 
/var/log/journal/567a68a5c2672114bcf5192d0008/system@718656154e1546fcb5d438a9edf3155f-0026448b-00050de41b746eac.journal
PASS: 
/var/log/journal/567a68a5c2672114bcf5192d0008/user-1000@00050e6501bfa725-1728cb2f60eede7c.journal~
PASS: 
/var/log/journal/567a68a5c2672114bcf5192d0008/system@85e08ed6443c49929fe2c1b8a46447c7-0001-000511cfb0d62522.journal
#  journalctl -F _BOOT_ID | wc -l
160
# journalctl --list-boots | wc -l
106


Even after moving away the file
system@00050e650144ab12-15158e9a9df4f071.journal~ which caused the
unused data message, I get

# journalctl --list-boots | wc -l
101
#  journalctl -F _BOOT_ID | wc -l
158

2015-03-27 21:23 GMT+01:00 Jan Janssen medhe...@web.de:



On 2015-03-27 21:06, Michael Biebl wrote:


2015-03-27 20:45 GMT+01:00 Jan Janssen medhe...@web.de:


Martin Pitt martin.pitt at ubuntu.com writes:



Hello all,

in [1] I just got a report that journalctl --list-boots (with
persistant journal) only shows a few old boots, but not current ones.
I checked this on my system (which has had persistant journal for a
while), and confirm that:



What does journalctl -F _BOOT_ID | wc -l vs journalctl --list-boots |
wc
-l say?



I can confirm the issue:


# journalctl -F _BOOT_ID | wc -l
160
# journalctl --list-boots | wc -l
106


This is on an ext4, no separate /var partition.




Well, the one reason I could think of right now is that there must be some
corrupted journals in there. Can you see if there are any using --verify and
then moving them out of the journal directory?

journalctl -F vs journalctl --list-boots use different code paths while
digging through the journal. Afaik, one of them is stricter when it comes to
interleaving intact and corrupted journals.

Jan





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


[systemd-devel] [PATCH v2] Add reboot to EFI support

2015-03-26 Thread Jan Janssen
---
 man/systemctl.xml |  6 +++-
 src/libsystemd/sd-bus/bus-common-errors.h |  1 +
 src/login/logind-dbus.c   | 49 +++--
 src/login/org.freedesktop.login1.conf |  8 +
 src/shared/efivars.c  | 52 +++
 src/shared/efivars.h  |  2 ++
 src/systemctl/systemctl.c | 16 --
 7 files changed, 127 insertions(+), 7 deletions(-)

diff --git a/man/systemctl.xml b/man/systemctl.xml
index 50e6bc9..eafdd73 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -1538,7 +1538,11 @@ kobject-uevent 1 systemd-udevd-kernel.socket 
systemd-udevd.service
 systems. This may result in data loss./para
 
 paraIf the optional argument
-replaceablearg/replaceable is given, it will be passed
+replaceablearg/replaceable is given and is equal to
+literalefi/literal, the system will be rebooted to
+the EFI firmware interface on machines that support it.
+Note that this requires the system to be booted in EFI mode.
+Otherwise, the argument will be passed
 as the optional argument to the
 
citerefentryrefentrytitlereboot/refentrytitlemanvolnum2/manvolnum/citerefentry
 system call. The value is architecture and firmware
diff --git a/src/libsystemd/sd-bus/bus-common-errors.h 
b/src/libsystemd/sd-bus/bus-common-errors.h
index b17b62a..3019140 100644
--- a/src/libsystemd/sd-bus/bus-common-errors.h
+++ b/src/libsystemd/sd-bus/bus-common-errors.h
@@ -57,6 +57,7 @@
 #define BUS_ERROR_DEVICE_IS_TAKEN org.freedesktop.login1.DeviceIsTaken
 #define BUS_ERROR_DEVICE_NOT_TAKEN org.freedesktop.login1.DeviceNotTaken
 #define BUS_ERROR_OPERATION_IN_PROGRESS 
org.freedesktop.login1.OperationInProgress
+#define BUS_ERROR_REBOOT_TO_EFI_NOT_SUPPORTED 
org.freedesktop.login1.RebootToEfiNotSupported
 #define BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED 
org.freedesktop.login1.SleepVerbNotSupported
 
 #define BUS_ERROR_AUTOMATIC_TIME_SYNC_ENABLED 
org.freedesktop.timedate1.AutomaticTimeSyncEnabled
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index a3d49ef..8fec90f 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -38,8 +38,11 @@
 #include bus-common-errors.h
 #include udev-util.h
 #include selinux-util.h
+#include efivars.h
 #include logind.h
 
+#define SPECIAL_REBOOT_TO_EFI_TARGET x-logind-reboot-to-efi.target
+
 int manager_get_session_from_creds(Manager *m, sd_bus_message *message, const 
char *name, sd_bus_error *error, Session **ret) {
 _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
 Session *session;
@@ -1422,6 +1425,13 @@ static int execute_shutdown_or_sleep(
 assert(w  _INHIBIT_WHAT_MAX);
 assert(unit_name);
 
+if (streq(unit_name, SPECIAL_REBOOT_TO_EFI_TARGET)) {
+unit_name = SPECIAL_REBOOT_TARGET;
+r = efi_indicate_reboot_to_fw();
+if (r  0)
+return r;
+}
+
 bus_manager_log_shutdown(m, w, unit_name);
 
 r = sd_bus_call_method(
@@ -1563,6 +1573,9 @@ static int method_do_shutdown_or_sleep(
 if (m-action_what)
 return sd_bus_error_setf(error, 
BUS_ERROR_OPERATION_IN_PROGRESS, There's already a shutdown or sleep operation 
in progress);
 
+if (streq(unit_name, SPECIAL_REBOOT_TO_EFI_TARGET)  
!is_efi_reboot_to_fw_supported())
+return sd_bus_error_setf(error, 
BUS_ERROR_REBOOT_TO_EFI_NOT_SUPPORTED, Reboot to EFI not supported);
+
 if (sleep_verb) {
 r = can_sleep(sleep_verb);
 if (r  0)
@@ -1648,6 +1661,21 @@ static int method_reboot(sd_bus *bus, sd_bus_message 
*message, void *userdata, s
 error);
 }
 
+static int method_reboot_to_efi(sd_bus *bus, sd_bus_message *message, void 
*userdata, sd_bus_error *error) {
+Manager *m = userdata;
+
+return method_do_shutdown_or_sleep(
+m, message,
+SPECIAL_REBOOT_TO_EFI_TARGET,
+INHIBIT_SHUTDOWN,
+org.freedesktop.login1.reboot,
+org.freedesktop.login1.reboot-multiple-sessions,
+org.freedesktop.login1.reboot-ignore-inhibit,
+NULL,
+method_reboot_to_efi,
+error);
+}
+
 static int method_suspend(sd_bus *bus, sd_bus_message *message, void 
*userdata, sd_bus_error *error) {
 Manager *m = userdata;
 
@@ -1700,7 +1728,7 @@ static int method_can_shutdown_or_sleep(
 const char *action,
 const char *action_multiple_sessions,
 const char *action_ignore_inhibit,
-const char *sleep_verb,
+const char *arg,
 sd_bus_error *error) {
 

Re: [systemd-devel] [PATCH 2/2] fsck: Add support for EFI variable based fsck indication

2015-03-17 Thread Jan Janssen


 Gesendet: Sonntag, 15. März 2015 um 19:58 Uhr
 Von: Kay Sievers k...@vrfy.org
 An: Zbigniew Jędrzejewski-Szmek zbys...@in.waw.pl
 Cc: Jan Janssen medhe...@web.de, systemd-devel@lists.freedesktop.org
 Betreff: Re: [systemd-devel] [PATCH 2/2] fsck: Add support for EFI variable 
 based fsck indication

 On Sun, Mar 15, 2015 at 7:48 PM, Zbigniew Jędrzejewski-Szmek
 zbys...@in.waw.pl wrote:
  On Sun, Mar 15, 2015 at 06:48:24PM +0100, Kay Sievers wrote:
 
  It is legacy and does not need new features. It worked in the past and
  will continue to work in the future, but it does not need new
  questionable and possibly unreliable or dangerous features. The recent
  merging of fsckd was already the wrong thing to do.
  Calling it legacy does not make it go away. If we had a stable 
  non-fsck-using
  filesystem available, we could start discussing removing fsck support.
  But we don't. It's one thing to remove stuff once we have something
  better, and completely different to remove support for widely used
  things.
 
 Nobody talks about things going away, we just should not add more
 non-trivial legacy support, that is all.
 
   the kernel command line should be sufficient enough.
   The kernel command line is not a good fit for a few reasons.
 
  The kernel commandline woked fine in the past and will be fine today,
  especially for such a legacy feature.
  Support for /forcefsck (or whatever it was called) was removed with the
  promise to provide a replacement which does not require touching the fs.
  Kernel commandline is just too unwieldy for users.
 
 Writing to the file system content to request a check, which would
 happen when things are already inconsistent, is a really stupid idea.
 
 If the filesytem is too dumb to have that info in the superblock flags
 to store, to request a forced fsck, it is the problem of the file
 system to fix and nothing we need to solve in systemd.
 
  No, they are absolutely not. Changing the EFI flash comes with
  unpredictable risks, the flash is not meant to or designed for be
  written to during any normal operation.
  Requesting fsck is not a normal operation.
 
 It is just a normal system operation. It needs to be fixed properly if
 needed, not with dirty work-arounds like this.
 
  If the flash is suitable
  to be written whenever the kernel is updated, it should be also OK
  to request a fsck through it. For users of many distributions (and
  kernel developers certainly), requesting fsck is a much rarer operation.
 
 Nobody would write to the flash on kernel updates, we only possibly
 write to the ESP filesystem. The flash is not meant for such use
 cases, it is known to brick all sorts of machines, and not to be
 mis-used for such features.

As far as I remember, the bricking mainly happened because the kernel was
writing kilobytes (maybe megabytes) worth of crashdumbs. This feature only
touches a couple of bytes.

  To avoid any possible misunderstanding here:
 
  Systemd will not use the fragile EFI flash store to configure services
  or request system operation modes. The kernel command line is good
  enough here.
 
  You will not apply this patch.
  I'd prefer to have a discussion and reach conclusions, not the other
  way around.
 
 Sorry, there is nothing to discuss, systemd will not mis-use the
 fragile firmware flash for normal operations, and especially not to
 support legacy features.
 
 Kay

Though, I do see the other reservations against this. Though, someone might
wanna close https://bugs.freedesktop.org/show_bug.cgi?id=88330 then.

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


Re: [systemd-devel] [PATCH 1/2] systemctl: Add reboot to firmware support

2015-03-17 Thread Jan Janssen
I certainly see the point of not adding fsck mode indication, but I'd still 
like to see
this one go in. If your firmware and/or bootloader won't give you a chance to, 
the os is
your only chance should you still be able to boot to it. And it's quite hard to 
even find
out how to reboot to firmware unless you know that it's called os indication. 
There isn't
even any convenient tool out there that allows you to do so, the best thing is 
fiddling
with the variable yourself using the shell[1].

Jan

[1] 
http://unix.stackexchange.com/questions/152144/how-to-write-edit-update-the-osindications-efi-variable-from-command-line

 Gesendet: Sonntag, 15. März 2015 um 11:56 Uhr
 Von: Jan Janssen medhe...@web.de
 An: systemd-devel@lists.freedesktop.org
 Cc: Jan Janssen medhe...@web.de
 Betreff: [PATCH 1/2] systemctl: Add reboot to firmware support

 ---
  man/systemctl.xml  | 10 
  shell-completion/bash/systemctl.in |  2 +-
  shell-completion/zsh/_systemctl.in |  1 +
  src/shared/efivars.h   |  7 +++---
  src/systemctl/systemctl.c  | 48 
 ++
  5 files changed, 60 insertions(+), 8 deletions(-)
 
 diff --git a/man/systemctl.xml b/man/systemctl.xml
 index 50e6bc9..3e2bcde 100644
 --- a/man/systemctl.xml
 +++ b/man/systemctl.xml
 @@ -456,6 +456,16 @@
/varlistentry
  
varlistentry
 +termoption--firmware/option/term
 +
 +listitem
 +  paraIndicate to the firmware to boot into EFI setup on machines
 +  that support it if commandreboot/command is used. Note that
 +  this is only supported if the machine was booted in EFI 
 mode./para
 +/listitem
 +  /varlistentry
 +
 +  varlistentry
  termoption--root=/option/term
  
  listitem
 diff --git a/shell-completion/bash/systemctl.in 
 b/shell-completion/bash/systemctl.in
 index 8063316..f14fe7a 100644
 --- a/shell-completion/bash/systemctl.in
 +++ b/shell-completion/bash/systemctl.in
 @@ -92,7 +92,7 @@ _systemctl () {
  local -A OPTS=(
 [STANDALONE]='--all -a --reverse --after --before --defaults 
 --fail --ignore-dependencies --failed --force -f --full -l --global
   --help -h --no-ask-password --no-block 
 --no-legend --no-pager --no-reload --no-wall
 - --quiet -q --privileged -P --system --user 
 --version --runtime --recursive -r'
 + --quiet -q --privileged -P --system --user 
 --version --runtime --recursive -r --firmware'
[ARG]='--host -H --kill-who --property -p --signal -s 
 --type -t --state --root'
  )
  
 diff --git a/shell-completion/zsh/_systemctl.in 
 b/shell-completion/zsh/_systemctl.in
 index 7f2d5ac..1caf9a4 100644
 --- a/shell-completion/zsh/_systemctl.in
 +++ b/shell-completion/zsh/_systemctl.in
 @@ -375,6 +375,7 @@ _arguments -s \
  '--global[Enable/disable unit files globally]' \
  --no-reload[When enabling/disabling unit files, don't reload daemon 
 configuration] \
  '--no-ask-password[Do not ask for system passwords]' \
 +'--firmware[Reboot to EFI setup on machines that support it]' \
  '--kill-who=[Who to send signal to]:killwho:(main control all)' \
  {-s+,--signal=}'[Which signal to send]:signal:_signals' \
  {-f,--force}'[When enabling unit files, override existing symlinks. When 
 shutting down, execute action immediately]' \
 diff --git a/src/shared/efivars.h b/src/shared/efivars.h
 index 2492893..7bdfb74 100644
 --- a/src/shared/efivars.h
 +++ b/src/shared/efivars.h
 @@ -28,9 +28,10 @@
  
  #define EFI_VENDOR_LOADER 
 SD_ID128_MAKE(4a,67,b0,82,0a,4c,41,cf,b6,c7,44,0b,29,bb,8c,4f)
  #define EFI_VENDOR_GLOBAL 
 SD_ID128_MAKE(8b,e4,df,61,93,ca,11,d2,aa,0d,00,e0,98,03,2b,8c)
 -#define EFI_VARIABLE_NON_VOLATILE   0x0001
 -#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0002
 -#define EFI_VARIABLE_RUNTIME_ACCESS 0x0004
 +#define EFI_VARIABLE_NON_VOLATILE0x0001
 +#define EFI_VARIABLE_BOOTSERVICE_ACCESS  0x0002
 +#define EFI_VARIABLE_RUNTIME_ACCESS  0x0004
 +#define EFI_OS_INDICATIONS_BOOT_TO_FW_UI 0x0001
  
  bool is_efi_boot(void);
  int is_efi_secure_boot(void);
 diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
 index 3158a38..8aee3c4 100644
 --- a/src/systemctl/systemctl.c
 +++ b/src/systemctl/systemctl.c
 @@ -68,6 +68,8 @@
  #include bus-common-errors.h
  #include mkdir.h
  #include dropin.h
 +#include virt.h
 +#include efivars.h
  
  static char **arg_types = NULL;
  static char **arg_states = NULL;
 @@ -132,7 +134,7 @@ static char *arg_host = NULL;
  static unsigned arg_lines = 10;
  static OutputMode arg_output = OUTPUT_SHORT;
  static bool arg_plain = false;
 -
 +static bool arg_firmware = false;
  static bool original_stdout_is_tty;
  
  static int daemon_reload(sd_bus *bus, char **args);
 @@ -2923,9

Re: [systemd-devel] [PATCH 1/2] systemctl: Add reboot to firmware support

2015-03-17 Thread Jan Janssen
Dimitri John Ledkov dimitri.j.ledkov at intel.com writes:

 Both gummyboot and grub-efi have a menu option to reboot into
 firmware, is that not enough? Why do we need to have it from userspace
 / the booted system?
 

There can be plenty of reasons why the firmware won't provide you with an
option. One of them being a FastBoot implementation that doesn't initialize
USB input devices. And also, if one were to directly boot from the efi stub
without boot loader (and not getting 5000€ in the process).

But this is primarily a reason of convenience. If your bootloader doesn't
give you a boot to firmware option, or your bootloader is being annoying and
boots to your OS faster than you can interface with it, you're currently out
of luck. I'm not too sure, but grub-efi probably even requires you to
actually specifically create the entry in the configuration; and touching
the grub config is just plain annoying. Especially if you just want that
entry for the one time EFI setup every once in a blue moon.

Also, the fact that there have been people asking questions about how to get
to the EFI/BIOS has always been there. With this you can just tell them to
systemctl --firmware reboot on any modern computer and be done with it.

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


Re: [systemd-devel] [PATCH 1/2] systemctl: Add reboot to firmware support

2015-03-17 Thread Jan Janssen


 Gesendet: Dienstag, 17. März 2015 um 13:41 Uhr
 Von: Dimitri John Ledkov dimitri.j.led...@intel.com
 An: Jan Janssen medhe...@web.de
 Cc: systemd Mailing List systemd-devel@lists.freedesktop.org
 Betreff: Re: [systemd-devel] [PATCH 1/2] systemctl: Add reboot to firmware 
 support

 On 17 March 2015 at 12:12, Jan Janssen medhe...@web.de wrote:
  Dimitri John Ledkov dimitri.j.ledkov at intel.com writes:
 
  Both gummyboot and grub-efi have a menu option to reboot into
  firmware, is that not enough? Why do we need to have it from userspace
  / the booted system?
 
 
  There can be plenty of reasons why the firmware won't provide you with an
  option. One of them being a FastBoot implementation that doesn't initialize
  USB input devices. And also, if one were to directly boot from the efi stub
  without boot loader (and not getting 5000€ in the process).
 
  But this is primarily a reason of convenience. If your bootloader doesn't
  give you a boot to firmware option, or your bootloader is being annoying and
  boots to your OS faster than you can interface with it, you're currently out
  of luck. I'm not too sure, but grub-efi probably even requires you to
  actually specifically create the entry in the configuration; and touching
  the grub config is just plain annoying. Especially if you just want that
  entry for the one time EFI setup every once in a blue moon.
 
  Also, the fact that there have been people asking questions about how to get
  to the EFI/BIOS has always been there. With this you can just tell them to
  systemctl --firmware reboot on any modern computer and be done with it.
 
 Then wouldn't we want to support it generically in src/core/shutdown.c
 / systemctl halt_now and expose it via logind API somehow as well?

Someone already did something like that a year ago, with no real response:
http://lists.freedesktop.org/archives/systemd-devel/2013-January/008216.html

 In some ways it is similar to REBOOT_PARAM_FILE handling for the
 SYS_reboot syscall, e.g. on Nexus devices $ reboot bootloader -
 reboots one into firmware (there is also usually recovery reboot
 argument support).

When looking at the code I did consider consuming the reboot param, but since I 
don't
know anything about I, I wouldn't know if that would break any existing use 
cases.

 This efi reboot is useful functionality, but if it's only hidden
 inside systemctl invocation, it would hard to integrate via e.g. DBus
 api calls from GUI application.

I feel like doing it that way is just overcomplicating things. Exposing it so 
easily to GUI
applications is mostly a waste of time for the rare occasion that it would get 
used.

 Can this be piggybacked on to reboot command arg?
 
 $ systemctl reboot efi-firmware
 
 same way that $ systemctl reboot bootloader is already supported (on
 platforms that support that arg)

That's an option, but is there any EFI system out there that already consumes 
the
parameter itself? I don't know, but is so, we can't consume it ourselves.

 Looking at Logind1 Api Reboot() it does not accept string argument
 there. RebootWithArg() or SetRebootParam() calls would be nice as
 well.
 

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


[systemd-devel] [PATCH 2/2] fsck: Add support for EFI variable based fsck indication

2015-03-15 Thread Jan Janssen
---
 man/systemctl.xml  | 26 
 shell-completion/bash/systemctl.in |  8 -
 shell-completion/zsh/_systemctl.in |  2 ++
 src/fsck/fsck.c| 63 +
 src/shared/efivars.h   | 21 +++--
 src/systemctl/systemctl.c  | 64 +-
 6 files changed, 173 insertions(+), 11 deletions(-)

diff --git a/man/systemctl.xml b/man/systemctl.xml
index 3e2bcde..8449d83 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -466,6 +466,32 @@
   /varlistentry
 
   varlistentry
+termoption--fsck-mode=/option/term
+
+listitem
+  paraControl file system check behavior for next boot on EFI 
systems./para
+
+  paraOne of literalauto/literal, literalforce/literal and
+  literalskip/literal. See 
citerefentryrefentrytitlesystemd-fsck/refentrytitlemanvolnum8/manvolnum/citerefentry
+  for details. Note that this requires the system to be booted in EFI 
mode and
+  that kernel command line parameters take precedence./para
+/listitem
+  /varlistentry
+
+  varlistentry
+termoption--fsck-repair=/option/term
+
+listitem
+  paraControl file system check repair behavior for next boot on EFI 
systems./para
+
+  paraOne of literalpreen/literal, literalyes/literal and
+  literalno/literal. See 
citerefentryrefentrytitlesystemd-fsck/refentrytitlemanvolnum8/manvolnum/citerefentry
+  for details. Note that this requires the system to be booted in EFI 
mode and
+  that kernel command line parameters take precedence./para
+/listitem
+  /varlistentry
+
+  varlistentry
 termoption--root=/option/term
 
 listitem
diff --git a/shell-completion/bash/systemctl.in 
b/shell-completion/bash/systemctl.in
index f14fe7a..cea28cd 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -93,7 +93,7 @@ _systemctl () {
[STANDALONE]='--all -a --reverse --after --before --defaults 
--fail --ignore-dependencies --failed --force -f --full -l --global
  --help -h --no-ask-password --no-block 
--no-legend --no-pager --no-reload --no-wall
  --quiet -q --privileged -P --system --user 
--version --runtime --recursive -r --firmware'
-  [ARG]='--host -H --kill-who --property -p --signal -s 
--type -t --state --root'
+  [ARG]='--host -H --kill-who --property -p --signal -s 
--type -t --state --root --fsck-mode --fsck-repair'
 )
 
 if __contains_word --user ${COMP_WORDS[*]}; then
@@ -118,6 +118,12 @@ _systemctl () {
 --kill-who)
 comps='all control main'
 ;;
+--fsck-mode)
+comps='auto force skip'
+;;
+--fsck-repair)
+comps='preen yes no'
+;;
 --root)
 comps=$(compgen -A directory -- $cur )
 compopt -o filenames
diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index 1caf9a4..b8c82cc 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -377,6 +377,8 @@ _arguments -s \
 '--no-ask-password[Do not ask for system passwords]' \
 '--firmware[Reboot to EFI setup on machines that support it]' \
 '--kill-who=[Who to send signal to]:killwho:(main control all)' \
+'--fsck-mode=[Control filesystem check mode next boot on EFI 
systems]:fsckmode:(auto force skip)' \
+'--fsck-repair=[Mode of operation to use with filesystem 
check]:fsckrepair:(preen yes no)' \
 {-s+,--signal=}'[Which signal to send]:signal:_signals' \
 {-f,--force}'[When enabling unit files, override existing symlinks. When 
shutting down, execute action immediately]' \
 '--root=[Enable unit files in the specified root 
directory]:directory:_directories' \
diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c
index 6e46633..ef56bb0 100644
--- a/src/fsck/fsck.c
+++ b/src/fsck/fsck.c
@@ -40,6 +40,7 @@
 #include path-util.h
 #include socket-util.h
 #include fsckd/fsckd.h
+#include efivars.h
 
 static bool arg_skip = false;
 static bool arg_force = false;
@@ -130,6 +131,67 @@ static void test_files(void) {
 
 }
 
+static void parse_efi_vars(void) {
+int r;
+size_t s;
+_cleanup_free_ void *v = NULL;
+
+if (!is_efi_boot())
+return;
+
+r = efi_get_variable(EFI_VENDOR_SYSTEMD, FsckModeOneShot, NULL, v, 
s);
+if (r  0 || s != sizeof(EfiSystemdFsckMode))
+log_warning(Failed to read FsckModeOneShot EFI variable.);
+else {
+EfiSystemdFsckMode value = 

[systemd-devel] [PATCH 1/2] systemctl: Add reboot to firmware support

2015-03-15 Thread Jan Janssen
---
 man/systemctl.xml  | 10 
 shell-completion/bash/systemctl.in |  2 +-
 shell-completion/zsh/_systemctl.in |  1 +
 src/shared/efivars.h   |  7 +++---
 src/systemctl/systemctl.c  | 48 ++
 5 files changed, 60 insertions(+), 8 deletions(-)

diff --git a/man/systemctl.xml b/man/systemctl.xml
index 50e6bc9..3e2bcde 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -456,6 +456,16 @@
   /varlistentry
 
   varlistentry
+termoption--firmware/option/term
+
+listitem
+  paraIndicate to the firmware to boot into EFI setup on machines
+  that support it if commandreboot/command is used. Note that
+  this is only supported if the machine was booted in EFI mode./para
+/listitem
+  /varlistentry
+
+  varlistentry
 termoption--root=/option/term
 
 listitem
diff --git a/shell-completion/bash/systemctl.in 
b/shell-completion/bash/systemctl.in
index 8063316..f14fe7a 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -92,7 +92,7 @@ _systemctl () {
 local -A OPTS=(
[STANDALONE]='--all -a --reverse --after --before --defaults 
--fail --ignore-dependencies --failed --force -f --full -l --global
  --help -h --no-ask-password --no-block 
--no-legend --no-pager --no-reload --no-wall
- --quiet -q --privileged -P --system --user 
--version --runtime --recursive -r'
+ --quiet -q --privileged -P --system --user 
--version --runtime --recursive -r --firmware'
   [ARG]='--host -H --kill-who --property -p --signal -s 
--type -t --state --root'
 )
 
diff --git a/shell-completion/zsh/_systemctl.in 
b/shell-completion/zsh/_systemctl.in
index 7f2d5ac..1caf9a4 100644
--- a/shell-completion/zsh/_systemctl.in
+++ b/shell-completion/zsh/_systemctl.in
@@ -375,6 +375,7 @@ _arguments -s \
 '--global[Enable/disable unit files globally]' \
 --no-reload[When enabling/disabling unit files, don't reload daemon 
configuration] \
 '--no-ask-password[Do not ask for system passwords]' \
+'--firmware[Reboot to EFI setup on machines that support it]' \
 '--kill-who=[Who to send signal to]:killwho:(main control all)' \
 {-s+,--signal=}'[Which signal to send]:signal:_signals' \
 {-f,--force}'[When enabling unit files, override existing symlinks. When 
shutting down, execute action immediately]' \
diff --git a/src/shared/efivars.h b/src/shared/efivars.h
index 2492893..7bdfb74 100644
--- a/src/shared/efivars.h
+++ b/src/shared/efivars.h
@@ -28,9 +28,10 @@
 
 #define EFI_VENDOR_LOADER 
SD_ID128_MAKE(4a,67,b0,82,0a,4c,41,cf,b6,c7,44,0b,29,bb,8c,4f)
 #define EFI_VENDOR_GLOBAL 
SD_ID128_MAKE(8b,e4,df,61,93,ca,11,d2,aa,0d,00,e0,98,03,2b,8c)
-#define EFI_VARIABLE_NON_VOLATILE   0x0001
-#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0002
-#define EFI_VARIABLE_RUNTIME_ACCESS 0x0004
+#define EFI_VARIABLE_NON_VOLATILE0x0001
+#define EFI_VARIABLE_BOOTSERVICE_ACCESS  0x0002
+#define EFI_VARIABLE_RUNTIME_ACCESS  0x0004
+#define EFI_OS_INDICATIONS_BOOT_TO_FW_UI 0x0001
 
 bool is_efi_boot(void);
 int is_efi_secure_boot(void);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 3158a38..8aee3c4 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -68,6 +68,8 @@
 #include bus-common-errors.h
 #include mkdir.h
 #include dropin.h
+#include virt.h
+#include efivars.h
 
 static char **arg_types = NULL;
 static char **arg_states = NULL;
@@ -132,7 +134,7 @@ static char *arg_host = NULL;
 static unsigned arg_lines = 10;
 static OutputMode arg_output = OUTPUT_SHORT;
 static bool arg_plain = false;
-
+static bool arg_firmware = false;
 static bool original_stdout_is_tty;
 
 static int daemon_reload(sd_bus *bus, char **args);
@@ -2923,9 +2925,40 @@ static int start_special(sd_bus *bus, char **args) {
 if (r  0)
 return r;
 
-if (arg_force = 2  geteuid() != 0) {
-log_error(Must be root.);
-return -EPERM;
+if ((arg_firmware || arg_force = 2)  geteuid() != 0)
+return log_error_errno(EPERM, Must be root.);
+
+if (arg_firmware) {
+size_t s;
+uint64_t b;
+_cleanup_free_ void *v = NULL;
+
+if (a != ACTION_REBOOT)
+return log_error_errno(EINVAL, Must use reboot 
command to reboot to firmware.);
+else if (detect_container(NULL)  0)
+return log_error_errno(ENOTSUP, Cannot reboot to 
firmware from within a container.);
+else if (!is_efi_boot())
+return log_error_errno(ENOTSUP, Reboot to firmware 
requires the system to be booted in EFI 

[systemd-devel] [PATCH] networkd: Make DHCP client ID creation configurable

2015-03-03 Thread Jan Janssen
---
 man/systemd.network.xml  |  8 
 src/network/networkd-dhcp4.c | 16 
 src/network/networkd-network-gperf.gperf |  1 +
 src/network/networkd-network.c   |  9 +
 src/network/networkd.h   | 11 +++
 5 files changed, 45 insertions(+)

diff --git a/man/systemd.network.xml b/man/systemd.network.xml
index 60252e5..3522551 100644
--- a/man/systemd.network.xml
+++ b/man/systemd.network.xml
@@ -564,6 +564,14 @@
   /listitem
 /varlistentry
 varlistentry
+  termvarnameClientIdentifier=/varname/term
+  listitem
+paraDHCP client identifier to use. Either literalmac/literal
+to use the MAC address of the link or literalduid/literal
+(the default) to use a RFC4361-complient Client ID./para
+  /listitem
+/varlistentry
+varlistentry
   termvarnameVendorClassIdentifier=/varname/term
   listitem
 paraThe vendor class identifier used to identify vendor
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index c3d0e3d..3832190 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -661,5 +661,21 @@ int dhcp4_configure(Link *link) {
 return r;
 }
 
+switch (link-network-dhcp_client_identifier) {
+case DHCP_CLIENT_ID_DUID:
+/* Library defaults to this. */
+break;
+case DHCP_CLIENT_ID_MAC:
+r = sd_dhcp_client_set_client_id(link-dhcp_client,
+ ARPHRD_ETHER,
+ (const uint8_t *) link-mac,
+ sizeof (link-mac));
+if (r  0)
+return r;
+break;
+default:
+assert_not_reached(Unknown client identifier type.);
+}
+
 return 0;
 }
diff --git a/src/network/networkd-network-gperf.gperf 
b/src/network/networkd-network-gperf.gperf
index b0c23a7..93df83a 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -58,6 +58,7 @@ Route.Destination,   config_parse_destination,
   0,
 Route.Source,config_parse_destination,   0,
 0
 Route.Metric,config_parse_route_priority,0,
 0
 Route.Scope, config_parse_route_scope,   0,
 0
+DHCP.ClientIdentifier,   config_parse_dhcp_client_identifier,0,
 offsetof(Network, dhcp_client_identifier)
 DHCP.UseDNS, config_parse_bool,  0,
 offsetof(Network, dhcp_dns)
 DHCP.UseMTU, config_parse_bool,  0,
 offsetof(Network, dhcp_mtu)
 DHCP.UseHostname,config_parse_bool,  0,
 offsetof(Network, dhcp_hostname)
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 0ba0c75..f7f6eaf 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -103,6 +103,7 @@ static int network_load_one(Manager *manager, const char 
*filename) {
 network-dhcp_routes = true;
 network-dhcp_sendhost = true;
 network-dhcp_route_metric = DHCP_ROUTE_METRIC;
+network-dhcp_client_identifier = DHCP_CLIENT_ID_DUID;
 
 network-llmnr = LLMNR_SUPPORT_YES;
 
@@ -600,6 +601,14 @@ int config_parse_dhcp(
 return 0;
 }
 
+static const char* const dhcp_client_identifier_table[_DHCP_CLIENT_ID_MAX] = {
+[DHCP_CLIENT_ID_MAC] = mac,
+[DHCP_CLIENT_ID_DUID] = duid
+};
+
+DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_client_identifier, 
DCHPClientIdentifier);
+DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_client_identifier, 
dhcp_client_identifier, DCHPClientIdentifier, Failed to parse client 
identifier type);
+
 static const char* const llmnr_support_table[_LLMNR_SUPPORT_MAX] = {
 [LLMNR_SUPPORT_NO] = no,
 [LLMNR_SUPPORT_YES] = yes,
diff --git a/src/network/networkd.h b/src/network/networkd.h
index e75746f..8bdc2be 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -83,6 +83,13 @@ typedef enum LinkOperationalState {
 _LINK_OPERSTATE_INVALID = -1
 } LinkOperationalState;
 
+typedef enum DCHPClientIdentifier {
+DHCP_CLIENT_ID_MAC,
+DHCP_CLIENT_ID_DUID,
+_DHCP_CLIENT_ID_MAX,
+_DHCP_CLIENT_ID_INVALID = -1,
+} DCHPClientIdentifier;
+
 struct FdbEntry {
 Network *network;
 unsigned section;
@@ -115,6 +122,7 @@ struct Network {
 NetDev *bond;
 Hashmap *stacked_netdevs;
 AddressFamilyBoolean dhcp;
+DCHPClientIdentifier 

Re: [systemd-devel] [v1] shutdown: add kexec loading, avoid calling `kexec` binary unnessecarily

2015-02-28 Thread Jan Janssen

On 2015-02-28 02:02, Shawn Landden wrote:

On Thu, Feb 26, 2015 at 12:04 AM, Jan Janssen medhe...@web.de
mailto:medhe...@web.de wrote:

Shawn Landden shawn at churchofgit.com http://churchofgit.com
writes:

  void strv_free(char **l) {
 -strv_clear(l);
 +char **k;
 +
 +if (!l)
 +return;
 +
 +for (k = l; *k; k++)
 +free(*k);
 +
  free(l);
  }
What are you trying to achieve here? I see no point in optimizing
out the *l
= NULL from strv_clear.

 +entry-linux_loc  = l + strspn(l,
WHITESPACE);
 +else if ((l = startswith(m, initrd )))
 +entry-initrd = l + strspn(l,
WHITESPACE);
You need to support more than one initrd per kernel, see
https://wiki.archlinux.org/index.php/Microcode for why. Also, I am
pretty
sure you can have a initrd=/path/to/initrd in the kernel options entry.
Since the efi bootloader just appends each given initrd to the kernel
command line.

I can't support more than one initrd per kernel with the
kexec_file_load() syscall, and if initrd on the commandline works, then
it will still work with this patch, so i don't need to change anything.
I doubt that it works. Afaik, the initrd is handled by the EFI stub (if 
that is used. Grub only uses it if linuxefi command is used). And I 
would assume that kexec doesn't use the stub. You should ask the kernel 
people how this API should be used with more than one initrd. My best 
guess is that you can just cat them into a tmp file and use that as target.




All in all I am wondering why you need a rbtree for all this in the
first
place? A simple hashmap should do just fine.

Also, you're not taking multi-boot into account (the machine-id field).
You're just discriminating based on the kernel version, but different
installations could have the same version field.

fixed by testing that the machine-id is the same (I forgot this part of
the spec thanks). Is there anyway I should save defaults? Is there
anything in the spec that is missing? Perhaps it should specify how to
save last-boot.


I think that's it. I'll shout when I see something missing, though :P

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


[systemd-devel] Cannot acquire DHCP lease

2015-02-26 Thread Jan Janssen

Hi,
since commit commit 5bac5235934fabe5a3e6a9d47f4812f81034c427, networkd 
cannot acquire DHCP leases on my router if I dual boot with windows.


It seems to be that my router is borked since I do get leases after 
resetting it to factory defaults, but once booting into the other OS, 
DHCP doesn't work anymore (whichever OS acquired the lease first wins 
and can still get leases after reboots).
I never used to have this issue until I switched to a new computer with 
a different network card (RTL-8110SC/8169SC). dhclient/dhcpcd also have 
this issue for me, but afaik they can change the clientid method to be 
used, though I never got to use it myself because networkd's 
implementation just worked for me, until it broke :(


The debug logs don't show anything interesting; it's just stuck in an 
DHCP discover loop.


Jan



5bac5235934fabe5a3e6a9d47f4812f81034c427 is the first bad commit
commit 5bac5235934fabe5a3e6a9d47f4812f81034c427
Author: Tom Gundersen t...@jklm.no
Date:   Thu Jan 22 00:53:16 2015 +0100

sd-dhcp-client: use RFC4361-complient ClientID by default

In addition to the benefits listed in the RFC, this allows DHCP to 
work also in
case several interfaces share the same MAC address on the same link 
(IPVLAN).


Note that this will make the ClientID (so probably the assigned IP 
address)
change on upgrades. If it is desired to avoid that we would have to 
remember and
write back the ID (which the library supports, but networkd 
currently does not).


:04 04 0f27d5041b1050e580a329c8c23fd12e1e2c552b 
f1cf96e838f0f4d91c774c3d82346b2ad94465ac M  src

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


Re: [systemd-devel] [v1] shutdown: add kexec loading, avoid calling `kexec` binary unnessecarily

2015-02-26 Thread Jan Janssen
Shawn Landden shawn at churchofgit.com writes:

  void strv_free(char **l) {
 -strv_clear(l);
 +char **k;
 +
 +if (!l)
 +return;
 +
 +for (k = l; *k; k++)
 +free(*k);
 +
  free(l);
  }
What are you trying to achieve here? I see no point in optimizing out the *l
= NULL from strv_clear.

 +entry-linux_loc  = l + strspn(l,
WHITESPACE);
 +else if ((l = startswith(m, initrd )))
 +entry-initrd = l + strspn(l,
WHITESPACE);
You need to support more than one initrd per kernel, see
https://wiki.archlinux.org/index.php/Microcode for why. Also, I am pretty
sure you can have a initrd=/path/to/initrd in the kernel options entry.
Since the efi bootloader just appends each given initrd to the kernel
command line.


All in all I am wondering why you need a rbtree for all this in the first
place? A simple hashmap should do just fine.

Also, you're not taking multi-boot into account (the machine-id field).
You're just discriminating based on the kernel version, but different
installations could have the same version field.

Jan

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


Re: [systemd-devel] [RFC PATCH 2/2] localed: add LANGUAGE= fallback when LANG= is specified

2015-02-01 Thread Jan Janssen
Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl writes:

 I think the implementation is fine, since it is rather trivial, but I'm
 less certain about the implications of setting LANGUAGE in addtion to
 LANG.
 
 Zbyszek

Isn't this something that should be in glibc's lang/locale handling code?
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] What's the correct way to configure encrypted volume and mount point?

2015-01-30 Thread Jan Janssen
John Lane systemd at jelmail.com writes:
 $ mount /home/myuser/data
 mount: special device /dev/mapper/keyring does not exist
Your crypttab entry uses noauto as an option. This means that it won't get
activated and no plain text device is created. Hence your manual mount can
only fail.

 I'm guessing that mount doesn't effect systemd and, therefore, the
 dependency isn't actioned. But the docs for systemd.mount state that
 configuring mount points through /etc/fstab
 is the preferred approach so I'm wondering if there's something I
 missed from my crypttab or fstab entries?
 Thanks.

But really: why not use automounting logic in fstab?:
/dev/mapper/data /home/myuser/data ext4 noauto,x-systemd.automount 0 0

No need to manually trigger a mount. And you can even use noauto in
crypttab so that the encrypted device is only opened once the mount point is
accessed the first time.

Jan

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


[systemd-devel] [PATCH rebased 2/3] cryptsetup-generator: Add support for UUID-specific key files on kernel command line

2014-12-02 Thread Jan Janssen
---
 man/systemd-cryptsetup-generator.xml  | 11 ---
 src/cryptsetup/cryptsetup-generator.c | 17 ++---
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/man/systemd-cryptsetup-generator.xml 
b/man/systemd-cryptsetup-generator.xml
index ff94e88..d4a9cc7 100644
--- a/man/systemd-cryptsetup-generator.xml
+++ b/man/systemd-cryptsetup-generator.xml
@@ -165,11 +165,16 @@
 termvarnameluks.key=/varname/term
 termvarnamerd.luks.key=/varname/term
 
-listitemparaTakes a password file as 
argument./para
+listitemparaTakes a password file name as 
argument or
+a LUKS super block UUID followed by a '=' and 
a password
+file name./para
+
 paraFor those entries specified with
 varnamerd.luks.uuid=/varname or 
varnameluks.uuid=/varname,
-the password file will be set to the password 
file specified by
-varnamerd.luks.key=/varname or 
varnameluks.key/varname/para
+the password file will be set to the one 
specified by
+varnamerd.luks.key=/varname or 
varnameluks.key=/varname
+of the corresponding UUID, or the password 
file that was specified
+without a UUID./para
 paravarnamerd.luks.key=/varname
 is honored only by initial RAM disk
 (initrd) while
diff --git a/src/cryptsetup/cryptsetup-generator.c 
b/src/cryptsetup/cryptsetup-generator.c
index c1581ef..efbcb3a 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -36,6 +36,7 @@
 
 typedef struct crypto_device {
 char *uuid;
+char *keyfile;
 char *options;
 bool create;
 } crypto_device;
@@ -264,6 +265,7 @@ static void free_arg_disks(void) {
 
 while ((d = hashmap_steal_first(arg_disks))) {
 free(d-uuid);
+free(d-keyfile);
 free(d-options);
 free(d);
 }
@@ -284,7 +286,7 @@ static crypto_device *get_crypto_device(const char *uuid) {
 return NULL;
 
 d-create = false;
-d-options = NULL;
+d-keyfile = d-options = NULL;
 
 d-uuid = strdup(uuid);
 if (!d-uuid) {
@@ -348,7 +350,16 @@ static int parse_proc_cmdline_item(const char *key, const 
char *value) {
 
 } else if (STR_IN_SET(key, luks.key, rd.luks.key)  value) {
 
-if (free_and_strdup(arg_default_keyfile, value))
+r = sscanf(value, %m[0-9a-fA-F-]=%ms, uuid, uuid_value);
+if (r == 2) {
+d = get_crypto_device(uuid);
+if (!d)
+return log_oom();
+
+free(d-keyfile);
+d-keyfile = uuid_value;
+uuid_value = NULL;
+} else if (free_and_strdup(arg_default_keyfile, value))
 return log_oom();
 
 }
@@ -455,7 +466,7 @@ static int add_proc_cmdline_devices(void) {
 else
 options = timeout=0;
 
-r = create_disk(name, device, arg_default_keyfile, options);
+r = create_disk(name, device, d-keyfile ?: 
arg_default_keyfile, options);
 if (r  0)
 return r;
 }
-- 
2.1.3

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


[systemd-devel] [PATCH rebased 1/3] cryptsetup-generator: Split main() into more functions and use hasmaps

2014-12-02 Thread Jan Janssen
---
 man/systemd-cryptsetup-generator.xml  |   9 +-
 src/cryptsetup/cryptsetup-generator.c | 380 +-
 2 files changed, 199 insertions(+), 190 deletions(-)

diff --git a/man/systemd-cryptsetup-generator.xml 
b/man/systemd-cryptsetup-generator.xml
index 3abb39d..ff94e88 100644
--- a/man/systemd-cryptsetup-generator.xml
+++ b/man/systemd-cryptsetup-generator.xml
@@ -120,7 +120,7 @@
 activate the specified device as part
 of the boot process as if it was
 listed in
-filename/etc/fstab/filename. This
+filename/etc/crypttab/filename. This
 option may be specified more than once
 in order to set up multiple
 devices. varnamerd.luks.uuid=/varname
@@ -130,9 +130,10 @@
 honored by both the main system and
 the initrd./para
 paraIf /etc/crypttab contains entries with
-the same UUID, then the options for this entry
-will be used./para
-paraIf /etc/crypttab exists, only those UUID
+the same UUID, then the name, keyfile and 
options
+specified there will be used. Otherwise the 
device
+will have the name 
literalluks-UUID/literal./para
+paraIf /etc/crypttab exists, only those UUIDs
 specified on the kernel command line
 will be activated in the initrd or the real 
root./para
 /listitem
diff --git a/src/cryptsetup/cryptsetup-generator.c 
b/src/cryptsetup/cryptsetup-generator.c
index 45c23bb..c1581ef 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -19,26 +19,34 @@
   along with systemd; If not, see http://www.gnu.org/licenses/.
 ***/
 
-#include string.h
 #include errno.h
+#include string.h
 #include unistd.h
 
+#include dropin.h
+#include fileio.h
+#include generator.h
+#include hashmap.h
 #include log.h
-#include util.h
-#include unit-name.h
 #include mkdir.h
-#include strv.h
-#include fileio.h
 #include path-util.h
-#include dropin.h
-#include generator.h
+#include strv.h
+#include unit-name.h
+#include util.h
+
+typedef struct crypto_device {
+char *uuid;
+char *options;
+bool create;
+} crypto_device;
 
 static const char *arg_dest = /tmp;
 static bool arg_enabled = true;
 static bool arg_read_crypttab = true;
-static char **arg_disks = NULL;
-static char **arg_options = NULL;
-static char *arg_keyfile = NULL;
+static bool arg_whitelist = false;
+static Hashmap *arg_disks = NULL;
+static char *arg_default_options = NULL;
+static char *arg_default_keyfile = NULL;
 
 static bool has_option(const char *haystack, const char *needle) {
 const char *f = haystack;
@@ -251,8 +259,54 @@ static int create_disk(
 return 0;
 }
 
+static void free_arg_disks(void) {
+crypto_device *d;
+
+while ((d = hashmap_steal_first(arg_disks))) {
+free(d-uuid);
+free(d-options);
+free(d);
+}
+
+hashmap_free(arg_disks);
+}
+
+static crypto_device *get_crypto_device(const char *uuid) {
+int r;
+crypto_device *d;
+
+assert(uuid);
+
+d = hashmap_get(arg_disks, uuid);
+if (!d) {
+d = new0(struct crypto_device, 1);
+if (!d)
+return NULL;
+
+d-create = false;
+d-options = NULL;
+
+d-uuid = strdup(uuid);
+if (!d-uuid) {
+free(d);
+return NULL;
+}
+
+r = hashmap_put(arg_disks, d-uuid, d);
+if (r  0) {
+free(d-uuid);
+free(d);
+return NULL;
+}
+}
+
+return d;
+}
+
 static int parse_proc_cmdline_item(const char *key, const char *value) {
 int r;
+crypto_device *d;
+_cleanup_free_ char *uuid = NULL, *uuid_value = NULL;
 
 if (STR_IN_SET(key, luks, rd.luks)  value) {
 
@@ -272,19 +326,29 @@ static int parse_proc_cmdline_item(const char *key, const 
char *value) {
 
 } else if (STR_IN_SET(key, luks.uuid, rd.luks.uuid)  value) {
 
-if (strv_extend(arg_disks, value)  0)
+d = get_crypto_device(startswith(value, luks-) ? value+5 : 
value);
+if (!d)
 return log_oom();
 
+d-create = arg_whitelist = true;
+
 } else if 

[systemd-devel] [PATCH rebased 3/3] cryptsetup-generator: Add support for naming luks devices on kernel cmdline

2014-12-02 Thread Jan Janssen
---
 man/kernel-command-line.xml   |  2 ++
 man/systemd-cryptsetup-generator.xml  | 19 +++
 src/cryptsetup/cryptsetup-generator.c | 32 ++--
 3 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/man/kernel-command-line.xml b/man/kernel-command-line.xml
index 68460ac..e32ed19 100644
--- a/man/kernel-command-line.xml
+++ b/man/kernel-command-line.xml
@@ -283,6 +283,8 @@
 termvarnamerd.luks=/varname/term
 termvarnameluks.crypttab=/varname/term
 
termvarnamerd.luks.crypttab=/varname/term
+termvarnameluks.name=/varname/term
+termvarnamerd.luks.name=/varname/term
 termvarnameluks.uuid=/varname/term
 termvarnamerd.luks.uuid=/varname/term
 termvarnameluks.options=/varname/term
diff --git a/man/systemd-cryptsetup-generator.xml 
b/man/systemd-cryptsetup-generator.xml
index d4a9cc7..c8753ce 100644
--- a/man/systemd-cryptsetup-generator.xml
+++ b/man/systemd-cryptsetup-generator.xml
@@ -140,6 +140,25 @@
 /varlistentry
 
 varlistentry
+termvarnameluks.name=/varname/term
+termvarnamerd.luks.name=/varname/term
+
+listitemparaTakes a LUKS super
+block UUID followed by an '=' and a name. This 
implies
+varnamerd.luks.uuid=/varname or 
varnameluks.uuid=/varname
+and will additionally make the LUKS device 
given by
+the UUID appear under the provided name./para
+
+paravarnamerd.luks.name=/varname
+is honored only by initial RAM disk
+(initrd) while
+varnameluks.name=/varname is
+honored by both the main system and
+the initrd./para
+/listitem
+/varlistentry
+
+varlistentry
 termvarnameluks.options=/varname/term
 
termvarnamerd.luks.options=/varname/term
 
diff --git a/src/cryptsetup/cryptsetup-generator.c 
b/src/cryptsetup/cryptsetup-generator.c
index efbcb3a..3a866f3 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -37,6 +37,7 @@
 typedef struct crypto_device {
 char *uuid;
 char *keyfile;
+char *name;
 char *options;
 bool create;
 } crypto_device;
@@ -266,6 +267,7 @@ static void free_arg_disks(void) {
 while ((d = hashmap_steal_first(arg_disks))) {
 free(d-uuid);
 free(d-keyfile);
+free(d-name);
 free(d-options);
 free(d);
 }
@@ -286,7 +288,7 @@ static crypto_device *get_crypto_device(const char *uuid) {
 return NULL;
 
 d-create = false;
-d-keyfile = d-options = NULL;
+d-keyfile = d-options = d-name = NULL;
 
 d-uuid = strdup(uuid);
 if (!d-uuid) {
@@ -362,6 +364,22 @@ static int parse_proc_cmdline_item(const char *key, const 
char *value) {
 } else if (free_and_strdup(arg_default_keyfile, value))
 return log_oom();
 
+} else if (STR_IN_SET(key, luks.name, rd.luks.name)  value) {
+
+r = sscanf(value, %m[0-9a-fA-F-]=%ms, uuid, uuid_value);
+if (r == 2) {
+d = get_crypto_device(uuid);
+if (!d)
+return log_oom();
+
+d-create = arg_whitelist = true;
+
+free(d-name);
+d-name = uuid_value;
+uuid_value = NULL;
+} else
+log_warning(Failed to parse luks name switch %s. 
Ignoring., value);
+
 }
 
 return 0;
@@ -446,14 +464,16 @@ static int add_proc_cmdline_devices(void) {
 
 HASHMAP_FOREACH(d, arg_disks, i) {
 const char *options;
-_cleanup_free_ char *name = NULL, *device = NULL;
+_cleanup_free_ char *device = NULL;
 
 if (!d-create)
 continue;
 
-name = strappend(luks-, d-uuid);
-if (!name)
-return log_oom();
+if (!d-name) {
+d-name = strappend(luks-, d-uuid);
+if (!d-name)
+return 

[systemd-devel] Cannot use systemctl after heavy swapping

2014-11-14 Thread Jan Janssen

Hi,

I think there might be something wrong with how the rate limiting works 
in manager.c. Just recently, firefox went nuts and got the whole system 
swapping like crazy. After manual OOM killing, the system is back to 
normal, but I can't seem to do any service management with systemctl 
afterwards.


A simple sudo systemctl start systemd-timedated.service will hang 
forever. While the journal keeps getting this message about every second:

systemd[1]: Looping too fast. Throttling execution a little.
while other systemctl actions tend to time out (status, for example).

Interestingly, if I don't use sudo (and instead rely on polkit), 
everything seems to work as expected and I can get things started.


This is all on systemd 217 on up-to-date Arch.

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


Re: [systemd-devel] Cannot use systemctl after heavy swapping

2014-11-14 Thread Jan Janssen



On 2014-11-14 16:06, Michal Schmidt wrote:

On 11/14/2014 03:20 PM, Jan Janssen wrote:

I think there might be something wrong with how the rate limiting
works in manager.c. Just recently, firefox went nuts and got the
whole system swapping like crazy. After manual OOM killing, the
system is back to normal, but I can't seem to do any service
management with systemctl afterwards.

A simple sudo systemctl start systemd-timedated.service will hang
forever. While the journal keeps getting this message about every
second: systemd[1]: Looping too fast. Throttling execution a little.
while other systemctl actions tend to time out (status, for
example).


Hi,
are you able to trigger the problem again at will? I'd love to have
a reproducer for this. There've been occasional reports of seeing the
Looping too fast message before.


Interestingly, if I don't use sudo (and instead rely on polkit),
everything seems to work as expected and I can get things started.


This suggests that PID1's confusion is affecting the private DBus
socket (/run/systemd/private), but its connection to the system bus
is still working.


This is all on systemd 217 on up-to-date Arch.


Regards,
Michal



Well, I can try tomorrow, but I'll need something that will get the 
system into a swapping frenzy that pretty much freezes the system.


I've just noticed that sometimes the systemctl start does also time 
out. But if it does hang forever and I kill it, systemd decides to 
actually do start the service.


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


[systemd-devel] [PATCH 1/3] cryptsetup-generator: Split main() into more functions and use hasmaps

2014-11-07 Thread Jan Janssen
---
 man/systemd-cryptsetup-generator.xml  |   9 +-
 src/cryptsetup/cryptsetup-generator.c | 380 +-
 2 files changed, 199 insertions(+), 190 deletions(-)

diff --git a/man/systemd-cryptsetup-generator.xml 
b/man/systemd-cryptsetup-generator.xml
index 3abb39d..ff94e88 100644
--- a/man/systemd-cryptsetup-generator.xml
+++ b/man/systemd-cryptsetup-generator.xml
@@ -120,7 +120,7 @@
 activate the specified device as part
 of the boot process as if it was
 listed in
-filename/etc/fstab/filename. This
+filename/etc/crypttab/filename. This
 option may be specified more than once
 in order to set up multiple
 devices. varnamerd.luks.uuid=/varname
@@ -130,9 +130,10 @@
 honored by both the main system and
 the initrd./para
 paraIf /etc/crypttab contains entries with
-the same UUID, then the options for this entry
-will be used./para
-paraIf /etc/crypttab exists, only those UUID
+the same UUID, then the name, keyfile and 
options
+specified there will be used. Otherwise the 
device
+will have the name 
literalluks-UUID/literal./para
+paraIf /etc/crypttab exists, only those UUIDs
 specified on the kernel command line
 will be activated in the initrd or the real 
root./para
 /listitem
diff --git a/src/cryptsetup/cryptsetup-generator.c 
b/src/cryptsetup/cryptsetup-generator.c
index 7c79ca3..185c03c 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -19,26 +19,34 @@
   along with systemd; If not, see http://www.gnu.org/licenses/.
 ***/
 
-#include string.h
 #include errno.h
+#include string.h
 #include unistd.h
 
+#include dropin.h
+#include fileio.h
+#include generator.h
+#include hashmap.h
 #include log.h
-#include util.h
-#include unit-name.h
 #include mkdir.h
-#include strv.h
-#include fileio.h
 #include path-util.h
-#include dropin.h
-#include generator.h
+#include strv.h
+#include unit-name.h
+#include util.h
+
+typedef struct crypto_device {
+char *uuid;
+char *options;
+bool create;
+} crypto_device;
 
 static const char *arg_dest = /tmp;
 static bool arg_enabled = true;
 static bool arg_read_crypttab = true;
-static char **arg_disks = NULL;
-static char **arg_options = NULL;
-static char *arg_keyfile = NULL;
+static bool arg_whitelist = false;
+static Hashmap *arg_disks = NULL;
+static char *arg_default_options = NULL;
+static char *arg_default_keyfile = NULL;
 
 static bool has_option(const char *haystack, const char *needle) {
 const char *f = haystack;
@@ -263,8 +271,54 @@ static int create_disk(
 return 0;
 }
 
+static void free_arg_disks(void) {
+crypto_device *d;
+
+while ((d = hashmap_steal_first(arg_disks))) {
+free(d-uuid);
+free(d-options);
+free(d);
+}
+
+hashmap_free(arg_disks);
+}
+
+static crypto_device *get_crypto_device(const char *uuid) {
+int r;
+crypto_device *d;
+
+assert(uuid);
+
+d = hashmap_get(arg_disks, uuid);
+if (!d) {
+d = new0(struct crypto_device, 1);
+if (!d)
+return NULL;
+
+d-create = false;
+d-options = NULL;
+
+d-uuid = strdup(uuid);
+if (!d-uuid) {
+free(d);
+return NULL;
+}
+
+r = hashmap_put(arg_disks, d-uuid, d);
+if (r  0) {
+free(d-uuid);
+free(d);
+return NULL;
+}
+}
+
+return d;
+}
+
 static int parse_proc_cmdline_item(const char *key, const char *value) {
 int r;
+crypto_device *d;
+_cleanup_free_ char *uuid = NULL, *uuid_value = NULL;
 
 if (STR_IN_SET(key, luks, rd.luks)  value) {
 
@@ -284,19 +338,29 @@ static int parse_proc_cmdline_item(const char *key, const 
char *value) {
 
 } else if (STR_IN_SET(key, luks.uuid, rd.luks.uuid)  value) {
 
-if (strv_extend(arg_disks, value)  0)
+d = get_crypto_device(startswith(value, luks-) ? value+5 : 
value);
+if (!d)
 return log_oom();
 
+d-create = arg_whitelist = true;
+
 } else if 

[systemd-devel] [PATCH 3/3] cryptsetup-generator: Add support for naming luks devices on kernel cmdline

2014-11-07 Thread Jan Janssen
---
 man/kernel-command-line.xml   |  2 ++
 man/systemd-cryptsetup-generator.xml  | 19 +++
 src/cryptsetup/cryptsetup-generator.c | 32 ++--
 3 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/man/kernel-command-line.xml b/man/kernel-command-line.xml
index 68460ac..e32ed19 100644
--- a/man/kernel-command-line.xml
+++ b/man/kernel-command-line.xml
@@ -283,6 +283,8 @@
 termvarnamerd.luks=/varname/term
 termvarnameluks.crypttab=/varname/term
 
termvarnamerd.luks.crypttab=/varname/term
+termvarnameluks.name=/varname/term
+termvarnamerd.luks.name=/varname/term
 termvarnameluks.uuid=/varname/term
 termvarnamerd.luks.uuid=/varname/term
 termvarnameluks.options=/varname/term
diff --git a/man/systemd-cryptsetup-generator.xml 
b/man/systemd-cryptsetup-generator.xml
index d4a9cc7..c8753ce 100644
--- a/man/systemd-cryptsetup-generator.xml
+++ b/man/systemd-cryptsetup-generator.xml
@@ -140,6 +140,25 @@
 /varlistentry
 
 varlistentry
+termvarnameluks.name=/varname/term
+termvarnamerd.luks.name=/varname/term
+
+listitemparaTakes a LUKS super
+block UUID followed by an '=' and a name. This 
implies
+varnamerd.luks.uuid=/varname or 
varnameluks.uuid=/varname
+and will additionally make the LUKS device 
given by
+the UUID appear under the provided name./para
+
+paravarnamerd.luks.name=/varname
+is honored only by initial RAM disk
+(initrd) while
+varnameluks.name=/varname is
+honored by both the main system and
+the initrd./para
+/listitem
+/varlistentry
+
+varlistentry
 termvarnameluks.options=/varname/term
 
termvarnamerd.luks.options=/varname/term
 
diff --git a/src/cryptsetup/cryptsetup-generator.c 
b/src/cryptsetup/cryptsetup-generator.c
index 09374c2..faf6caf 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -37,6 +37,7 @@
 typedef struct crypto_device {
 char *uuid;
 char *keyfile;
+char *name;
 char *options;
 bool create;
 } crypto_device;
@@ -278,6 +279,7 @@ static void free_arg_disks(void) {
 while ((d = hashmap_steal_first(arg_disks))) {
 free(d-uuid);
 free(d-keyfile);
+free(d-name);
 free(d-options);
 free(d);
 }
@@ -298,7 +300,7 @@ static crypto_device *get_crypto_device(const char *uuid) {
 return NULL;
 
 d-create = false;
-d-keyfile = d-options = NULL;
+d-keyfile = d-options = d-name = NULL;
 
 d-uuid = strdup(uuid);
 if (!d-uuid) {
@@ -374,6 +376,22 @@ static int parse_proc_cmdline_item(const char *key, const 
char *value) {
 } else if (free_and_strdup(arg_default_keyfile, value))
 return log_oom();
 
+} else if (STR_IN_SET(key, luks.name, rd.luks.name)  value) {
+
+r = sscanf(value, %m[0-9a-fA-F-]=%ms, uuid, uuid_value);
+if (r == 2) {
+d = get_crypto_device(uuid);
+if (!d)
+return log_oom();
+
+d-create = arg_whitelist = true;
+
+free(d-name);
+d-name = uuid_value;
+uuid_value = NULL;
+} else
+log_warning(Failed to parse luks name switch %s. 
Ignoring., value);
+
 }
 
 return 0;
@@ -458,14 +476,16 @@ static int add_proc_cmdline_devices(void) {
 
 HASHMAP_FOREACH(d, arg_disks, i) {
 const char *options;
-_cleanup_free_ char *name = NULL, *device = NULL;
+_cleanup_free_ char *device = NULL;
 
 if (!d-create)
 continue;
 
-name = strappend(luks-, d-uuid);
-if (!name)
-return log_oom();
+if (!d-name) {
+d-name = strappend(luks-, d-uuid);
+if (!d-name)
+return 

[systemd-devel] [PATCH 2/3] cryptsetup-generator: Add support for UUID-specific key files on kernel command line

2014-11-07 Thread Jan Janssen
---
 man/systemd-cryptsetup-generator.xml  | 11 ---
 src/cryptsetup/cryptsetup-generator.c | 17 ++---
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/man/systemd-cryptsetup-generator.xml 
b/man/systemd-cryptsetup-generator.xml
index ff94e88..d4a9cc7 100644
--- a/man/systemd-cryptsetup-generator.xml
+++ b/man/systemd-cryptsetup-generator.xml
@@ -165,11 +165,16 @@
 termvarnameluks.key=/varname/term
 termvarnamerd.luks.key=/varname/term
 
-listitemparaTakes a password file as 
argument./para
+listitemparaTakes a password file name as 
argument or
+a LUKS super block UUID followed by a '=' and 
a password
+file name./para
+
 paraFor those entries specified with
 varnamerd.luks.uuid=/varname or 
varnameluks.uuid=/varname,
-the password file will be set to the password 
file specified by
-varnamerd.luks.key=/varname or 
varnameluks.key/varname/para
+the password file will be set to the one 
specified by
+varnamerd.luks.key=/varname or 
varnameluks.key=/varname
+of the corresponding UUID, or the password 
file that was specified
+without a UUID./para
 paravarnamerd.luks.key=/varname
 is honored only by initial RAM disk
 (initrd) while
diff --git a/src/cryptsetup/cryptsetup-generator.c 
b/src/cryptsetup/cryptsetup-generator.c
index 185c03c..09374c2 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -36,6 +36,7 @@
 
 typedef struct crypto_device {
 char *uuid;
+char *keyfile;
 char *options;
 bool create;
 } crypto_device;
@@ -276,6 +277,7 @@ static void free_arg_disks(void) {
 
 while ((d = hashmap_steal_first(arg_disks))) {
 free(d-uuid);
+free(d-keyfile);
 free(d-options);
 free(d);
 }
@@ -296,7 +298,7 @@ static crypto_device *get_crypto_device(const char *uuid) {
 return NULL;
 
 d-create = false;
-d-options = NULL;
+d-keyfile = d-options = NULL;
 
 d-uuid = strdup(uuid);
 if (!d-uuid) {
@@ -360,7 +362,16 @@ static int parse_proc_cmdline_item(const char *key, const 
char *value) {
 
 } else if (STR_IN_SET(key, luks.key, rd.luks.key)  value) {
 
-if (free_and_strdup(arg_default_keyfile, value))
+r = sscanf(value, %m[0-9a-fA-F-]=%ms, uuid, uuid_value);
+if (r == 2) {
+d = get_crypto_device(uuid);
+if (!d)
+return log_oom();
+
+free(d-keyfile);
+d-keyfile = uuid_value;
+uuid_value = NULL;
+} else if (free_and_strdup(arg_default_keyfile, value))
 return log_oom();
 
 }
@@ -467,7 +478,7 @@ static int add_proc_cmdline_devices(void) {
 else
 options = timeout=0;
 
-r = create_disk(name, device, arg_default_keyfile, options);
+r = create_disk(name, device, d-keyfile ?: 
arg_default_keyfile, options);
 if (r  0)
 return r;
 }
-- 
2.1.3

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


[systemd-devel] Leak mempool/hashmap

2014-11-06 Thread Jan Janssen

Hi,

I just noticed that mempool/hashmap leaks memory. It's as simple as this 
to trigger:


#include hashmap.h
int main(int argc, const char *argv[]) {
Hashmap *m = hashmap_new(string_hash_ops);
hashmap_free(m);
}
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Leak mempool/hashmap

2014-11-06 Thread Jan Janssen



On 2014-11-06 19:05, Lennart Poettering wrote:

On Thu, 06.11.14 18:36, Jan Janssen (medhe...@web.de) wrote:


Hi,

I just noticed that mempool/hashmap leaks memory. It's as simple as this to
trigger:

#include hashmap.h
int main(int argc, const char *argv[]) {
 Hashmap *m = hashmap_new(string_hash_ops);
 hashmap_free(m);
}


How did you determine the leak?

Note that the hashmap uses an allocation cache. It's not freed on
shutdown, but it's not leaked either...

Lennart



I've noticed while testing my cryptsetup-generator rewrite with 
valgrind. It's still reachable according to valgrind, but a silent 
output would be nice to have.


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


[systemd-devel] [PATCH v2] journalctl: Unify boot id lookup into common function get_boots

2014-10-23 Thread Jan Janssen
---
Changes in v2:
 - Properly initialize count to zero

 src/journal/journalctl.c | 134 +--
 1 file changed, 59 insertions(+), 75 deletions(-)

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index dfde0a9..7ce5ff6 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -844,28 +844,32 @@ static int boot_id_cmp(const void *a, const void *b) {
 return _a  _b ? -1 : (_a  _b ? 1 : 0);
 }
 
-static int list_boots(sd_journal *j) {
+static int get_boots(sd_journal *j,
+ boot_id_t **boots,
+ unsigned int *count,
+ boot_id_t *query_ref_boot) {
 int r;
 const void *data;
-unsigned int count = 0;
-int w, i;
 size_t length, allocated = 0;
-boot_id_t *id;
-_cleanup_free_ boot_id_t *all_ids = NULL;
+
+assert(j);
+assert(boots);
+assert(count);
 
 r = sd_journal_query_unique(j, _BOOT_ID);
 if (r  0)
 return r;
 
-pager_open_if_enabled();
-
+*count = 0;
 SD_JOURNAL_FOREACH_UNIQUE(j, data, length) {
+boot_id_t *id;
+
 assert(startswith(data, _BOOT_ID=));
 
-if (!GREEDY_REALLOC(all_ids, allocated, count + 1))
+if (!GREEDY_REALLOC(*boots, allocated, *count + 1))
 return log_oom();
 
-id = all_ids[count];
+id = *boots + *count;
 
 r = sd_id128_from_string(((const char *)data) + 
strlen(_BOOT_ID=), id-id);
 if (r  0)
@@ -889,26 +893,48 @@ static int list_boots(sd_journal *j) {
 if (r  0)
 return r;
 
-r = sd_journal_seek_tail(j);
-if (r  0)
-return r;
+if (query_ref_boot) {
+id-last = 0;
+if (sd_id128_equal(id-id, query_ref_boot-id))
+*query_ref_boot = *id;
+} else {
+r = sd_journal_seek_tail(j);
+if (r  0)
+return r;
 
-r = sd_journal_previous(j);
-if (r  0)
-return r;
-else if (r == 0)
-goto flush;
+r = sd_journal_previous(j);
+if (r  0)
+return r;
+else if (r == 0)
+goto flush;
 
-r = sd_journal_get_realtime_usec(j, id-last);
-if (r  0)
-return r;
+r = sd_journal_get_realtime_usec(j, id-last);
+if (r  0)
+return r;
+}
 
-count++;
+(*count)++;
 flush:
 sd_journal_flush_matches(j);
 }
 
-qsort_safe(all_ids, count, sizeof(boot_id_t), boot_id_cmp);
+qsort_safe(*boots, *count, sizeof(boot_id_t), boot_id_cmp);
+return 0;
+}
+
+static int list_boots(sd_journal *j) {
+int r, w, i;
+unsigned int count;
+boot_id_t *id;
+_cleanup_free_ boot_id_t *all_ids = NULL;
+
+assert(j);
+
+r = get_boots(j, all_ids, count, NULL);
+if (r  0)
+return r;
+
+pager_open_if_enabled();
 
 /* numbers are one less, but we need an extra char for the sign */
 w = DECIMAL_STR_WIDTH(count - 1) + 1;
@@ -926,76 +952,34 @@ static int list_boots(sd_journal *j) {
 return 0;
 }
 
-static int get_relative_boot_id(sd_journal *j, sd_id128_t *boot_id, int 
relative) {
+static int get_boot_id_by_offset(sd_journal *j, sd_id128_t *boot_id, int 
offset) {
 int r;
-const void *data;
-unsigned int count = 0;
-size_t length, allocated = 0;
-boot_id_t ref_boot_id = {SD_ID128_NULL}, *id;
+unsigned int count;
+boot_id_t ref_boot_id = {}, *id;
 _cleanup_free_ boot_id_t *all_ids = NULL;
 
 assert(j);
 assert(boot_id);
 
-r = sd_journal_query_unique(j, _BOOT_ID);
+ref_boot_id.id = *boot_id;
+r = get_boots(j, all_ids, count, ref_boot_id);
 if (r  0)
 return r;
 
-SD_JOURNAL_FOREACH_UNIQUE(j, data, length) {
-if (length  strlen(_BOOT_ID=))
-continue;
-
-if (!GREEDY_REALLOC(all_ids, allocated, count + 1))
-return log_oom();
-
-id = all_ids[count];
-
-r = sd_id128_from_string(((const char *)data) + 
strlen(_BOOT_ID=), id-id);
-if (r  0)
-continue;
-
-r = sd_journal_add_match(j, data, length);
-if 

Re: [systemd-devel] [PATCH] journal: Fix sd_journal_enumerate_unique skipping values

2014-10-08 Thread Jan Janssen


 Gesendet: Mittwoch, 08. Oktober 2014 um 01:40 Uhr
 Von: Zbigniew Jędrzejewski-Szmek zbys...@in.waw.pl
 An: Jan Janssen medhe...@web.de
 Cc: systemd-devel@lists.freedesktop.org
 Betreff: Re: [systemd-devel] [PATCH] journal: Fix sd_journal_enumerate_unique 
 skipping values

 On Mon, Oct 06, 2014 at 06:57:38PM +0200, Zbigniew Jędrzejewski-Szmek wrote:
  On Mon, Oct 06, 2014 at 06:36:34PM +0200, Jan Janssen wrote:
   *bump*
  Sorry, I'll look into this.
 
 Doesn't work. Both without or with your other patch
 sd_journal_enumerate_unique I get bogus results on my test case. It
 seems the issue is more complicated.
 

That's odd. Care to elaborate what bogus results means? Are you even affected 
by the
bug in question without the patch?

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


Re: [systemd-devel] [PATCH] journal: Fix sd_journal_enumerate_unique skipping values

2014-10-08 Thread Jan Janssen

On 2014-10-08 14:59, Zbigniew Jędrzejewski-Szmek wrote:

On Wed, Oct 08, 2014 at 08:24:49AM +0200, Jan Janssen wrote:




Gesendet: Mittwoch, 08. Oktober 2014 um 01:40 Uhr
Von: Zbigniew Jędrzejewski-Szmek zbys...@in.waw.pl
An: Jan Janssen medhe...@web.de
Cc: systemd-devel@lists.freedesktop.org
Betreff: Re: [systemd-devel] [PATCH] journal: Fix sd_journal_enumerate_unique 
skipping values

On Mon, Oct 06, 2014 at 06:57:38PM +0200, Zbigniew Jędrzejewski-Szmek wrote:

On Mon, Oct 06, 2014 at 06:36:34PM +0200, Jan Janssen wrote:

*bump*

Sorry, I'll look into this.


Doesn't work. Both without or with your other patch
sd_journal_enumerate_unique I get bogus results on my test case. It
seems the issue is more complicated.



That's odd. Care to elaborate what bogus results means? Are you even affected 
by the
bug in question without the patch?


Yes, I have a VM where I get a smaller number from -F _BOOT_ID than from 
--list-boots
(w/o your patches), and then the same smaller number with one or two of your 
patches.
So results become consistent, but equally bad.

Of course I can't know if this is exactly the same bug, but it certainly looks
like it.



Sounds like maybe one of those calls end up interleaving journals from 
different machines?


Also, does removing the call to journal_file_object_release() in 
sd_journal_enumerate_unique() improve things or not? How about moving it 
after the if(found) where it was before the patch?


I'd love to investigate this, but I sadly don't have any journals that 
triggers this :(


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


Re: [systemd-devel] [PATCH] journal: Fix sd_journal_enumerate_unique skipping values

2014-10-06 Thread Jan Janssen

*bump*

On 2014-09-06 10:36, Jan Janssen wrote:

sd_journal_enumerate_unique will lock its mmap window to prevent it
from being released by calling mmap_cache_get with keep_always=true.
This call may return windows that are wider, but compatible with the
parameters provided to it.

This can result in a mismatch where the window to be released cannot
properly be selected, because we have more than one window matching the
parameters of mmap_cache_release. Therefore, introduce a release_cookie
to be used when releasing the window.

https://bugs.freedesktop.org/show_bug.cgi?id=79380
---
  src/journal/journal-file.c|  2 +-
  src/journal/journal-file.h| 11 ---
  src/journal/journal-verify.c  |  2 +-
  src/journal/mmap-cache.c  | 32 +++-
  src/journal/mmap-cache.h  |  8 +++-
  src/journal/sd-journal.c  | 11 ++-
  src/journal/test-mmap-cache.c | 10 +-
  7 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 7286e14..0ed51ed 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -391,7 +391,7 @@ static int journal_file_move_to(JournalFile *f, int 
context, bool keep_always, u
  return -EADDRNOTAVAIL;
  }

-return mmap_cache_get(f-mmap, f-fd, f-prot, context, keep_always, offset, 
size, f-last_stat, ret);
+return mmap_cache_get(f-mmap, f-fd, f-prot, context, keep_always, offset, 
size, f-last_stat, ret, NULL);
  }

  static uint64_t minimum_header_size(Object *o) {
diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h
index da2ef3b..da1b793 100644
--- a/src/journal/journal-file.h
+++ b/src/journal/journal-file.h
@@ -212,17 +212,14 @@ static unsigned type_to_context(int type) {
  return type  0  type  _OBJECT_TYPE_MAX ? type : 0;
  }

-static inline int journal_file_object_keep(JournalFile *f, Object *o, uint64_t 
offset) {
+static inline int journal_file_object_keep(JournalFile *f, Object *o, uint64_t 
offset, void **release_cookie) {
  unsigned context = type_to_context(o-object.type);
  uint64_t s = le64toh(o-object.size);

  return mmap_cache_get(f-mmap, f-fd, f-prot, context, true,
-  offset, s, f-last_stat, NULL);
+  offset, s, f-last_stat, NULL, release_cookie);
  }

-static inline int journal_file_object_release(JournalFile *f, Object *o, 
uint64_t offset) {
-unsigned context = type_to_context(o-object.type);
-uint64_t s = le64toh(o-object.size);
-
-return mmap_cache_release(f-mmap, f-fd, f-prot, context, offset, s);
+static inline int journal_file_object_release(JournalFile *f, void 
*release_cookie) {
+return mmap_cache_release(f-mmap, f-fd, release_cookie);
  }
diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c
index 6c8ca8c..a1c34ac 100644
--- a/src/journal/journal-verify.c
+++ b/src/journal/journal-verify.c
@@ -368,7 +368,7 @@ static int contains_uint64(MMapCache *m, int fd, uint64_t 
n, uint64_t p) {

  c = (a + b) / 2;

-r = mmap_cache_get(m, fd, PROT_READ|PROT_WRITE, 0, false, c * 
sizeof(uint64_t), sizeof(uint64_t), NULL, (void **) z);
+r = mmap_cache_get(m, fd, PROT_READ|PROT_WRITE, 0, false, c * 
sizeof(uint64_t), sizeof(uint64_t), NULL, (void **) z, NULL);
  if (r  0)
  return r;

diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c
index 7dbbb5e..64bc8da 100644
--- a/src/journal/mmap-cache.c
+++ b/src/journal/mmap-cache.c
@@ -352,7 +352,8 @@ static int try_context(
  bool keep_always,
  uint64_t offset,
  size_t size,
-void **ret) {
+void **ret,
+void **release_cookie) {

  Context *c;

@@ -381,6 +382,8 @@ static int try_context(

  if (ret)
  *ret = (uint8_t*) c-window-ptr + (offset - 
c-window-offset);
+if (keep_always  release_cookie)
+*release_cookie = c-window;
  return 1;
  }

@@ -392,7 +395,8 @@ static int find_mmap(
  bool keep_always,
  uint64_t offset,
  size_t size,
-void **ret) {
+void **ret,
+void **release_cookie) {

  FileDescriptor *f;
  Window *w;
@@ -425,6 +429,8 @@ static int find_mmap(

  if (ret)
  *ret = (uint8_t*) w-ptr + (offset - w-offset);
+if (keep_always  release_cookie)
+*release_cookie = c-window;
  return 1;
  }

@@ -437,7 +443,8 @@ static int add_mmap(
  uint64_t offset,
  size_t size,
  struct stat *st,
-void **ret) {
+void **ret,
+void **release_cookie) {

  uint64_t

[systemd-devel] [PATCH] journal: Fix sd_journal_enumerate_unique skipping values

2014-09-06 Thread Jan Janssen
sd_journal_enumerate_unique will lock its mmap window to prevent it
from being released by calling mmap_cache_get with keep_always=true.
This call may return windows that are wider, but compatible with the
parameters provided to it.

This can result in a mismatch where the window to be released cannot
properly be selected, because we have more than one window matching the
parameters of mmap_cache_release. Therefore, introduce a release_cookie
to be used when releasing the window.

https://bugs.freedesktop.org/show_bug.cgi?id=79380
---
 src/journal/journal-file.c|  2 +-
 src/journal/journal-file.h| 11 ---
 src/journal/journal-verify.c  |  2 +-
 src/journal/mmap-cache.c  | 32 +++-
 src/journal/mmap-cache.h  |  8 +++-
 src/journal/sd-journal.c  | 11 ++-
 src/journal/test-mmap-cache.c | 10 +-
 7 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 7286e14..0ed51ed 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -391,7 +391,7 @@ static int journal_file_move_to(JournalFile *f, int 
context, bool keep_always, u
 return -EADDRNOTAVAIL;
 }
 
-return mmap_cache_get(f-mmap, f-fd, f-prot, context, keep_always, 
offset, size, f-last_stat, ret);
+return mmap_cache_get(f-mmap, f-fd, f-prot, context, keep_always, 
offset, size, f-last_stat, ret, NULL);
 }
 
 static uint64_t minimum_header_size(Object *o) {
diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h
index da2ef3b..da1b793 100644
--- a/src/journal/journal-file.h
+++ b/src/journal/journal-file.h
@@ -212,17 +212,14 @@ static unsigned type_to_context(int type) {
 return type  0  type  _OBJECT_TYPE_MAX ? type : 0;
 }
 
-static inline int journal_file_object_keep(JournalFile *f, Object *o, uint64_t 
offset) {
+static inline int journal_file_object_keep(JournalFile *f, Object *o, uint64_t 
offset, void **release_cookie) {
 unsigned context = type_to_context(o-object.type);
 uint64_t s = le64toh(o-object.size);
 
 return mmap_cache_get(f-mmap, f-fd, f-prot, context, true,
-  offset, s, f-last_stat, NULL);
+  offset, s, f-last_stat, NULL, release_cookie);
 }
 
-static inline int journal_file_object_release(JournalFile *f, Object *o, 
uint64_t offset) {
-unsigned context = type_to_context(o-object.type);
-uint64_t s = le64toh(o-object.size);
-
-return mmap_cache_release(f-mmap, f-fd, f-prot, context, offset, s);
+static inline int journal_file_object_release(JournalFile *f, void 
*release_cookie) {
+return mmap_cache_release(f-mmap, f-fd, release_cookie);
 }
diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c
index 6c8ca8c..a1c34ac 100644
--- a/src/journal/journal-verify.c
+++ b/src/journal/journal-verify.c
@@ -368,7 +368,7 @@ static int contains_uint64(MMapCache *m, int fd, uint64_t 
n, uint64_t p) {
 
 c = (a + b) / 2;
 
-r = mmap_cache_get(m, fd, PROT_READ|PROT_WRITE, 0, false, c * 
sizeof(uint64_t), sizeof(uint64_t), NULL, (void **) z);
+r = mmap_cache_get(m, fd, PROT_READ|PROT_WRITE, 0, false, c * 
sizeof(uint64_t), sizeof(uint64_t), NULL, (void **) z, NULL);
 if (r  0)
 return r;
 
diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c
index 7dbbb5e..64bc8da 100644
--- a/src/journal/mmap-cache.c
+++ b/src/journal/mmap-cache.c
@@ -352,7 +352,8 @@ static int try_context(
 bool keep_always,
 uint64_t offset,
 size_t size,
-void **ret) {
+void **ret,
+void **release_cookie) {
 
 Context *c;
 
@@ -381,6 +382,8 @@ static int try_context(
 
 if (ret)
 *ret = (uint8_t*) c-window-ptr + (offset - 
c-window-offset);
+if (keep_always  release_cookie)
+*release_cookie = c-window;
 return 1;
 }
 
@@ -392,7 +395,8 @@ static int find_mmap(
 bool keep_always,
 uint64_t offset,
 size_t size,
-void **ret) {
+void **ret,
+void **release_cookie) {
 
 FileDescriptor *f;
 Window *w;
@@ -425,6 +429,8 @@ static int find_mmap(
 
 if (ret)
 *ret = (uint8_t*) w-ptr + (offset - w-offset);
+if (keep_always  release_cookie)
+*release_cookie = c-window;
 return 1;
 }
 
@@ -437,7 +443,8 @@ static int add_mmap(
 uint64_t offset,
 size_t size,
 struct stat *st,
-void **ret) {
+void **ret,
+void **release_cookie) {
 
 uint64_t woffset, wsize;
 Context *c;
@@ -521,6 +528,8 @@ static int add_mmap(
 
   

Re: [systemd-devel] [PATCH] journalctl: Fix --list-boots and --boot

2014-08-31 Thread Jan Janssen



On 2014-08-30 23:46, Zbigniew Jędrzejewski-Szmek wrote:

On Fri, Aug 29, 2014 at 06:11:35PM +0200, Jan Janssen wrote:

For some reason, sd_journal_query_unique() and sd_journal_add_match() don't
work as they used to. There's a chance boots will be skipped; in my
case only 60 of 393 boots show up. Therefore, do sd_journal_query_unique() first
and then iterate over those to query their timespec.

We should fix the underlying problem, since query_unique and add_match weren't
supposed to change at all. Looking at the journal client code has been on my
TODO list for a long while...


You're probably right, but at the same time I wonder if interleaving 
query_unique and normal journal matching should be allowed/supported in 
the first place...





https://bugs.freedesktop.org/show_bug.cgi?id=79380

---
  src/journal/journalctl.c | 124 ---
  1 file changed, 53 insertions(+), 71 deletions(-)

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index f3680d1..0aec5fb 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -804,33 +804,45 @@ static int boot_id_cmp(const void *a, const void *b) {
  return _a  _b ? -1 : (_a  _b ? 1 : 0);
  }

-static int list_boots(sd_journal *j) {
+static int get_boots(sd_journal *j, boot_id_t **boot_ids, unsigned int *count, 
boot_id_t *query_ref_boot_id) {
  int r;
+boot_id_t *id;
  const void *data;
-unsigned int count = 0;
-int w, i;
  size_t length, allocated = 0;
-boot_id_t *id;
-_cleanup_free_ boot_id_t *all_ids = NULL;
+
+assert(j);
+assert(boot_ids);
+assert(count);

  r = sd_journal_query_unique(j, _BOOT_ID);
  if (r  0)
  return r;

+*count = 0;
  SD_JOURNAL_FOREACH_UNIQUE(j, data, length) {
  if (length  strlen(_BOOT_ID=))
  continue;

-if (!GREEDY_REALLOC(all_ids, allocated, count + 1))
+if (!GREEDY_REALLOC(*boot_ids, allocated, *count + 1))
  return log_oom();

-id = all_ids[count];
+id = *boot_ids + *count;

  r = sd_id128_from_string(((const char *)data) + strlen(_BOOT_ID=), 
id-id);
  if (r  0)
  continue;

-r = sd_journal_add_match(j, data, length);
+(*count)++;
+id-first = id-last = 0;
+}
+
+for (id = *boot_ids; id  *boot_ids + *count; id++) {
+char boot_id_str[9+32+1] = _BOOT_ID=;
+
+sd_journal_flush_matches(j);
+sd_id128_to_string(id-id, boot_id_str + 9);
+
+r = sd_journal_add_match(j, boot_id_str, strlen(boot_id_str));
  if (r  0)
  return r;

@@ -839,35 +851,47 @@ static int list_boots(sd_journal *j) {
  return r;

  r = sd_journal_next(j);
-if (r  0)
+if (r = 0)
  return r;
-else if (r == 0)
-goto flush;

  r = sd_journal_get_realtime_usec(j, id-first);
  if (r  0)
  return r;

+if (query_ref_boot_id) {
+if (sd_id128_equal(id-id, query_ref_boot_id-id))
+*query_ref_boot_id = *id;
+continue;
+}
+
  r = sd_journal_seek_tail(j);
  if (r  0)
  return r;

  r = sd_journal_previous(j);
-if (r  0)
+if (r = 0)
  return r;
-else if (r == 0)
-goto flush;

  r = sd_journal_get_realtime_usec(j, id-last);
  if (r  0)
  return r;
-
-count++;
-flush:
-sd_journal_flush_matches(j);
  }

-qsort_safe(all_ids, count, sizeof(boot_id_t), boot_id_cmp);
+sd_journal_flush_matches(j);
+qsort_safe(*boot_ids, *count, sizeof(boot_id_t), boot_id_cmp);
+
+return 0;
+}
+
+static int list_boots(sd_journal *j) {
+int r, w, i;
+unsigned int count = 0;
+boot_id_t *id;
+_cleanup_free_ boot_id_t *all_ids = NULL;
+
+r = get_boots(j, all_ids, count, NULL);
+if (r  0)
+return r;

  /* numbers are one less, but we need an extra char for the sign */
  w = DECIMAL_STR_WIDTH(count - 1) + 1;
@@ -885,76 +909,34 @@ static int list_boots(sd_journal *j) {
  return 0;
  }

-static int get_relative_boot_id(sd_journal *j, sd_id128_t *boot_id, int 
relative) {
+static int get_boot_id_by_offset(sd_journal *j, sd_id128_t *boot_id, int 
offset) {
  int r

[systemd-devel] [PATCH v2] journalctl: Allow to disable line cap with --lines=all

2014-08-31 Thread Jan Janssen
---
 man/journalctl.xml   | 13 +++--
 src/journal/journalctl.c | 42 +++---
 2 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/man/journalctl.xml b/man/journalctl.xml
index d4e0316..acd75a6 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -189,9 +189,9 @@
 that the pager will not buffer logs of
 unbounded size. This may be overridden
 with an explicit option-n/option
-with some other numeric value on the
-command line. Note that this option is
-only supported for the
+with some other numeric value while
+option-nall/option will disable this cap.
+Note that this option is only supported for the
 citerefentry 
project='man-pages'refentrytitleless/refentrytitlemanvolnum1/manvolnum/citerefentry
 pager./para/listitem
 /varlistentry
@@ -204,9 +204,10 @@
 journal events and limit the number of
 events shown. If
 option--follow/option is used,
-this option is implied. The argument,
-a positive integer, is optional, and
-defaults to 10. /para/listitem
+this option is implied. The argument is
+a positive integer or literalall/literal
+to disable line limiting. The default value is
+10 if no argument is given./para/listitem
 /varlistentry
 
 varlistentry
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index f3680d1..d00a815 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -68,7 +68,7 @@ static bool arg_follow = false;
 static bool arg_full = true;
 static bool arg_all = false;
 static bool arg_no_pager = false;
-static int arg_lines = -1;
+static int arg_lines = -2;
 static bool arg_no_tail = false;
 static bool arg_quiet = false;
 static bool arg_merge = false;
@@ -327,7 +327,7 @@ static int parse_argv(int argc, char *argv[]) {
 case 'e':
 arg_pager_end = true;
 
-if (arg_lines  0)
+if (arg_lines  -1)
 arg_lines = 1000;
 
 break;
@@ -366,29 +366,33 @@ static int parse_argv(int argc, char *argv[]) {
 
 case 'n':
 if (optarg) {
-r = safe_atoi(optarg, arg_lines);
-if (r  0 || arg_lines  0) {
-log_error(Failed to parse lines 
'%s', optarg);
-return -EINVAL;
+if (streq(optarg, all))
+arg_lines = -1;
+else {
+r = safe_atoi(optarg, arg_lines);
+if (r  0 || arg_lines  0) {
+log_error(Failed to parse 
lines '%s', optarg);
+return -EINVAL;
+}
 }
 } else {
-int n;
+arg_lines = 10;
 
 /* Hmm, no argument? Maybe the next
  * word on the command line is
  * supposed to be the argument? Let's
  * see if there is one, and is
- * parsable as a positive
- * integer... */
-
-if (optind  argc 
-safe_atoi(argv[optind], n) = 0 
-n = 0) {
-
-arg_lines = n;
-optind++;
-} else
-arg_lines = 10;
+ * parsable. */
+if (optind  argc) {
+int n;
+if (streq(argv[optind], all)) {
+arg_lines = -1;
+optind++;
+} else if 

Re: [systemd-devel] [PATCH] journalctl: Fix --list-boots and --boot

2014-08-31 Thread Jan Janssen


On 2014-08-31 15:32, Zbigniew Jędrzejewski-Szmek wrote:
 On Sun, Aug 31, 2014 at 10:47:25AM +0200, Jan Janssen wrote:


 On 2014-08-30 23:46, Zbigniew Jędrzejewski-Szmek wrote:
 On Fri, Aug 29, 2014 at 06:11:35PM +0200, Jan Janssen wrote:
 For some reason, sd_journal_query_unique() and sd_journal_add_match() 
don't
 work as they used to. There's a chance boots will be skipped; in my
 case only 60 of 393 boots show up. Therefore, do 
sd_journal_query_unique() first
 and then iterate over those to query their timespec.
 We should fix the underlying problem, since query_unique and add_match 
weren't
 supposed to change at all. Looking at the journal client code has been on 
my
 TODO list for a long while...

 You're probably right, but at the same time I wonder if interleaving
 query_unique and normal journal matching should be allowed/supported
 in the first place...
 Manual page says Note that these functions currently are not
 influenced by matches set with sd_journal_add_match() but this
 might change in a later version of this software. so it should
 do something meaningful.

 Zbyszek

Hence why I would argue to do these queries sequentially, like in this 
patch. It certainly doesn't add any extra complexity, but would future proof 
things if they are changed (intentionally).

But either way, I identified the offending commit:
ae97089d49d1795a35a443b7b830ee666028e733 is the first bad commit
commit ae97089d49d1795a35a443b7b830ee666028e733
Author: Zbigniew Jędrzejewski-Szmek zbys...@in.waw.pl
Date:   Sat Dec 28 19:33:23 2013 -0500

journal: fix access to munmapped memory in sd_journal_enumerate_unique

sd_j_e_u needs to keep a reference to an object while comparing it
with possibly duplicate objects in other files. Because the size of
mmap cache is limited, with enough files and object to compare to,
at some point the object being compared would be munmapped, resulting
in a segmentation fault.

Fix this issue by turning keep_always into a reference count that can
be increased and decreased. Other callers which set keep_always=true
are unmodified: their references are never released but are ignored
when the whole file is closed, which happens at some point. keep_always
is increased in sd_j_e_u and later on released.

:04 04 cd360868b7f8c20a484f7267f0be20983255bbfe 
136b75a43d8d0200c8f2bae955314b12701ccb55 M  src

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


[systemd-devel] test-ipv4ll never finishes

2014-08-30 Thread Jan Janssen
Hi,

on my system, test-ipv4ll waits forever on an epoll:

$ strace ./test-ipv4ll 
execve(./test-ipv4ll, [./test-ipv4ll], [/* 64 vars */]) = 0
brk(0)  = 0x7f387087e000
access(/etc/ld.so.preload, R_OK)  = -1 ENOENT (No such file or directory)
open(/etc/ld.so.cache, O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=231109, ...}) = 0
mmap(NULL, 231109, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f386f85e000
close(3)= 0
open(/usr/lib/librt.so.1, O_RDONLY|O_CLOEXEC) = 3
read(3, \177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0\0\1\0\0\0\360\\0\0\0\0\0\0..., 
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=31760, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f386f85d000
mmap(NULL, 2128912, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0x7f386f46f000
mprotect(0x7f386f476000, 2093056, PROT_NONE) = 0
mmap(0x7f386f675000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f386f675000
close(3)= 0
open(/usr/lib/libpthread.so.0, O_RDONLY|O_CLOEXEC) = 3
read(3, \177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0\0\1\0\0\`\0\0\0\0\0\0..., 
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=149301, ...}) = 0
mmap(NULL, 2217104, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0x7f386f251000
mprotect(0x7f386f269000, 2097152, PROT_NONE) = 0
mmap(0x7f386f469000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x18000) = 0x7f386f469000
mmap(0x7f386f46b000, 13456, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f386f46b000
close(3)= 0
open(/usr/lib/libc.so.6, O_RDONLY|O_CLOEXEC) = 3
read(3, \177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0\0\1\0\0\0\20\1\2\0\0\0\0\0..., 
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2047384, ...}) = 0
mmap(NULL, 3858192, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0x7f386eea3000
mprotect(0x7f386f047000, 2097152, PROT_NONE) = 0
mmap(0x7f386f247000, 24576, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1a4000) = 0x7f386f247000
mmap(0x7f386f24d000, 16144, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f386f24d000
close(3)= 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f386f85c000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7f386f85a000
arch_prctl(ARCH_SET_FS, 0x7f386f85a740) = 0
mprotect(0x7f386f247000, 16384, PROT_READ) = 0
mprotect(0x7f386f469000, 4096, PROT_READ) = 0
mprotect(0x7f386f675000, 4096, PROT_READ) = 0
mprotect(0x7f386f8ab000, 4096, PROT_READ) = 0
mprotect(0x7f386f897000, 4096, PROT_READ) = 0
munmap(0x7f386f85e000, 231109)  = 0
set_tid_address(0x7f386f85aa10) = 30468
set_robust_list(0x7f386f85aa20, 24) = 0
rt_sigaction(SIGRTMIN, {0x7f386f256b10, [], SA_RESTORER|SA_SIGINFO, 
0x7f386f2604b0}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0x7f386f256ba0, [], SA_RESTORER|SA_RESTART|SA_SIGINFO, 
0x7f386f2604b0}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
brk(0)  = 0x7f387087e000
brk(0x7f387089f000) = 0x7f387089f000
epoll_create1(EPOLL_CLOEXEC)= 3
socketpair(PF_LOCAL, SOCK_DGRAM|SOCK_NONBLOCK, 0, [4, 5]) = 0
epoll_ctl(3, EPOLL_CTL_ADD, 4, {EPOLLIN, {u32=1887953936, 
u64=139880382850064}}) = 0
epoll_ctl(3, EPOLL_CTL_DEL, 4, NULL)= 0
close(4)= 0
epoll_wait(3,
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] journalctl: Allow to disable line cap with --pager-end

2014-08-30 Thread Jan Janssen
--lines=0 hardly makes sense with --pager-end, so give it some
new meaning.
---
 man/journalctl.xml   |  6 +++---
 src/journal/journalctl.c | 12 
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/man/journalctl.xml b/man/journalctl.xml
index d4e0316..5c8d78c 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -189,9 +189,9 @@
 that the pager will not buffer logs of
 unbounded size. This may be overridden
 with an explicit option-n/option
-with some other numeric value on the
-command line. Note that this option is
-only supported for the
+with some other numeric value while
+option-n0/option will disable this cap.
+Note that this option is only supported for the
 citerefentry 
project='man-pages'refentrytitleless/refentrytitlemanvolnum1/manvolnum/citerefentry
 pager./para/listitem
 /varlistentry
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 0aec5fb..49a6c23 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -326,10 +326,6 @@ static int parse_argv(int argc, char *argv[]) {
 
 case 'e':
 arg_pager_end = true;
-
-if (arg_lines  0)
-arg_lines = 1000;
-
 break;
 
 case 'f':
@@ -642,6 +638,14 @@ static int parse_argv(int argc, char *argv[]) {
 assert_not_reached(Unhandled option);
 }
 
+
+if (arg_pager_end) {
+if (arg_lines  0)
+arg_lines = 1000;
+else if (arg_lines == 0)
+arg_lines = -1;
+}
+
 if (arg_follow  !arg_no_tail  arg_lines  0)
 arg_lines = 10;
 
-- 
2.1.0

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


Re: [systemd-devel] [PATCHv6 0/3] hibernate-resume: implement support for resuming from hibernation

2014-08-29 Thread Jan Janssen



On 2014-08-29 04:28, Andrei Borzenkov wrote:

В Thu, 28 Aug 2014 19:36:53 +0200
Jan Janssen medhe...@web.de пишет:


On Thursday 28 August 2014 11:33:44 Ivan Shapovalov wrote:

On Thursday 28 August 2014 at 06:25:51, Jan Janssen wrote:

Ivan Shapovalov intelfx100 at gmail.com writes:

On Wednesday 27 August 2014 at 03:16:10, Zbigniew Jędrzejewski-Szmek wrote:

On Tue, Aug 26, 2014 at 10:21:59PM +0200, Lennart Poettering wrote:

On Wed, 27.08.14 00:17, Ivan Shapovalov (intelfx100 at gmail.com) wrote:

This patchset allows systemd to parse resume= kernel command line


parameter


and initiate resume from the specified device.


What about swap files with the resume_offset= parameter? Are they
still
being used?


I don't know if somebody uses that, but for now it's missing
functionality.

After a cursory search, I could not find a mechanism to initiate a
resume with offset from userspace. In Arch, it was never implemented
even if possible.

I'm a heavy user of this myself. It's especially useful because you can
just have a single luks encrypted ext4 without a lvm in between for a
swap partition or (even more yuck) using a separate (encrypted) swap
partition.

Arch does support this, mostly because as far as I know, the
resume_offset=
is consumed by the kernel, while resume= has to refer to the (unencrypted)
filesystem (/dev/mapper/root in my case). So, as long as this solution
waits for the device to show up in /dev/ (and especially /dev/mapper/ for
my case), this should work out.

Here's information to set this up. Imho more people should be aware this
is
possible:
https://wiki.archlinux.org/index.php/Suspend#Hibernation_into_swap_file

Jan


Hmm, so is resume_offset= parsed independently of resume=? If that's the
case, and resume_offset= can be parsed by kernel while resume= is parsed
by userspace, then yes, I was wrong and this should work.

Actually, it should work _just like before_, sans tuxonice support.


I gave it a try and resume works for me with that sd-resume hook in arch. But 
I'm not too sure whether fsck is delayed properly:

systemd[1]: Started Cryptography Setup for 
luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
systemd[1]: Found device /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
systemd[1]: Starting File System Check on 
/dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78...


Hmm ... it is not systemd-fsck-root.service. Do you have
local-fs-pre.target installed in initrd? What units are there at all?


never mind, I failed to update the system-fsk@.service that had the new 
dependency.


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


[systemd-devel] [PATCH] cryptsetup-generator: Allow specifiying a name on the kernel command line

2014-08-29 Thread Jan Janssen
---
 man/systemd-cryptsetup-generator.xml  |  8 ++--
 src/cryptsetup/cryptsetup-generator.c | 32 +---
 2 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/man/systemd-cryptsetup-generator.xml 
b/man/systemd-cryptsetup-generator.xml
index 3abb39d..44c8658 100644
--- a/man/systemd-cryptsetup-generator.xml
+++ b/man/systemd-cryptsetup-generator.xml
@@ -120,8 +120,12 @@
 activate the specified device as part
 of the boot process as if it was
 listed in
-filename/etc/fstab/filename. This
-option may be specified more than once
+filename/etc/fstab/filename.
+If the UUID is followed with 
literal:name/literal,
+the plain test device will appear under that 
name
+in filename/dev/mapper//filename, otherwise
+it will be literalluks-UUID/literal./para
+paraThis option may be specified more than 
once
 in order to set up multiple
 devices. varnamerd.luks.uuid=/varname
 is honored only by initial RAM disk
diff --git a/src/cryptsetup/cryptsetup-generator.c 
b/src/cryptsetup/cryptsetup-generator.c
index 3233e15..dea2b1f 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -279,7 +279,7 @@ static int parse_proc_cmdline_item(const char *key, const 
char *value) {
 
 } else if (STR_IN_SET(key, luks.uuid, rd.luks.uuid)  value) {
 
-if (strv_extend(arg_disks, value)  0)
+if (strv_extend(arg_disks, startswith(value, luks-) ? 
value+5 : value)  0)
 return log_oom();
 
 } else if (STR_IN_SET(key, luks.options, rd.luks.options)  
value) {
@@ -401,13 +401,14 @@ int main(int argc, char *argv[]) {
 */
 STRV_FOREACH(i, arg_disks) {
 _cleanup_free_ char *proc_device = 
NULL, *proc_name = NULL;
-const char *p = *i;
+const char *p = NULL;
 
-if (startswith(p, luks-))
-p += 5;
-
-proc_name = strappend(luks-, p);
-proc_device = strappend(UUID=, p);
+p = strchrnul(*i, ':');
+proc_device = strnappend(UUID=, *i, 
p - *i);
+if (*p  !isempty(p + 1))
+proc_name = strdup(p + 1);
+else
+proc_name = 
strnappend(luks-, *i, p - *i);
 
 if (!proc_name || !proc_device) {
 log_oom();
@@ -418,7 +419,7 @@ int main(int argc, char *argv[]) {
 if (create_disk(name, device, 
password, options)  0)
 goto cleanup;
 
-if (strv_extend(disks_done, 
p)  0) {
+if (strv_extend(disks_done, 
*i)  0) {
 log_oom();
 goto cleanup;
 }
@@ -440,16 +441,17 @@ next:
 */
 
 _cleanup_free_ char *name = NULL, *device = NULL, *options = 
NULL;
-const char *p = *i;
-
-if (startswith(p, luks-))
-p += 5;
+const char *p = NULL;
 
-if (strv_contains(disks_done, p))
+if (strv_contains(disks_done, *i))
 continue;
 
-name = strappend(luks-, p);
-device = strappend(UUID=, p);
+p = strchrnul(*i, ':');
+device = strnappend(UUID=, *i, p - *i);
+if (*p  !isempty(p + 1))
+name = strdup(p + 1);
+else
+name = strnappend(luks-, *i, p - *i);
 
 if (!name || !device) {
 log_oom();
-- 
2.1.0

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


[systemd-devel] [PATCH] journalctl: Fix --list-boots and --boot

2014-08-29 Thread Jan Janssen
For some reason, sd_journal_query_unique() and sd_journal_add_match() don't
work as they used to. There's a chance boots will be skipped; in my
case only 60 of 393 boots show up. Therefore, do sd_journal_query_unique() first
and then iterate over those to query their timespec.

https://bugs.freedesktop.org/show_bug.cgi?id=79380
---
 src/journal/journalctl.c | 124 ---
 1 file changed, 53 insertions(+), 71 deletions(-)

diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index f3680d1..0aec5fb 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -804,33 +804,45 @@ static int boot_id_cmp(const void *a, const void *b) {
 return _a  _b ? -1 : (_a  _b ? 1 : 0);
 }
 
-static int list_boots(sd_journal *j) {
+static int get_boots(sd_journal *j, boot_id_t **boot_ids, unsigned int *count, 
boot_id_t *query_ref_boot_id) {
 int r;
+boot_id_t *id;
 const void *data;
-unsigned int count = 0;
-int w, i;
 size_t length, allocated = 0;
-boot_id_t *id;
-_cleanup_free_ boot_id_t *all_ids = NULL;
+
+assert(j);
+assert(boot_ids);
+assert(count);
 
 r = sd_journal_query_unique(j, _BOOT_ID);
 if (r  0)
 return r;
 
+*count = 0;
 SD_JOURNAL_FOREACH_UNIQUE(j, data, length) {
 if (length  strlen(_BOOT_ID=))
 continue;
 
-if (!GREEDY_REALLOC(all_ids, allocated, count + 1))
+if (!GREEDY_REALLOC(*boot_ids, allocated, *count + 1))
 return log_oom();
 
-id = all_ids[count];
+id = *boot_ids + *count;
 
 r = sd_id128_from_string(((const char *)data) + 
strlen(_BOOT_ID=), id-id);
 if (r  0)
 continue;
 
-r = sd_journal_add_match(j, data, length);
+(*count)++;
+id-first = id-last = 0;
+}
+
+for (id = *boot_ids; id  *boot_ids + *count; id++) {
+char boot_id_str[9+32+1] = _BOOT_ID=;
+
+sd_journal_flush_matches(j);
+sd_id128_to_string(id-id, boot_id_str + 9);
+
+r = sd_journal_add_match(j, boot_id_str, strlen(boot_id_str));
 if (r  0)
 return r;
 
@@ -839,35 +851,47 @@ static int list_boots(sd_journal *j) {
 return r;
 
 r = sd_journal_next(j);
-if (r  0)
+if (r = 0)
 return r;
-else if (r == 0)
-goto flush;
 
 r = sd_journal_get_realtime_usec(j, id-first);
 if (r  0)
 return r;
 
+if (query_ref_boot_id) {
+if (sd_id128_equal(id-id, query_ref_boot_id-id))
+*query_ref_boot_id = *id;
+continue;
+}
+
 r = sd_journal_seek_tail(j);
 if (r  0)
 return r;
 
 r = sd_journal_previous(j);
-if (r  0)
+if (r = 0)
 return r;
-else if (r == 0)
-goto flush;
 
 r = sd_journal_get_realtime_usec(j, id-last);
 if (r  0)
 return r;
-
-count++;
-flush:
-sd_journal_flush_matches(j);
 }
 
-qsort_safe(all_ids, count, sizeof(boot_id_t), boot_id_cmp);
+sd_journal_flush_matches(j);
+qsort_safe(*boot_ids, *count, sizeof(boot_id_t), boot_id_cmp);
+
+return 0;
+}
+
+static int list_boots(sd_journal *j) {
+int r, w, i;
+unsigned int count = 0;
+boot_id_t *id;
+_cleanup_free_ boot_id_t *all_ids = NULL;
+
+r = get_boots(j, all_ids, count, NULL);
+if (r  0)
+return r;
 
 /* numbers are one less, but we need an extra char for the sign */
 w = DECIMAL_STR_WIDTH(count - 1) + 1;
@@ -885,76 +909,34 @@ static int list_boots(sd_journal *j) {
 return 0;
 }
 
-static int get_relative_boot_id(sd_journal *j, sd_id128_t *boot_id, int 
relative) {
+static int get_boot_id_by_offset(sd_journal *j, sd_id128_t *boot_id, int 
offset) {
 int r;
-const void *data;
 unsigned int count = 0;
-size_t length, allocated = 0;
-boot_id_t ref_boot_id = {SD_ID128_NULL}, *id;
+boot_id_t ref_boot_id = {}, *id;
 _cleanup_free_ boot_id_t *all_ids = NULL;
 
 assert(j);
 assert(boot_id);
 
-r = sd_journal_query_unique(j, _BOOT_ID);
+ref_boot_id.id = *boot_id;
+r = get_boots(j, all_ids, count, ref_boot_id);
 if (r  0)
 return r;
 
-

Re: [systemd-devel] [PATCHv6 0/3] hibernate-resume: implement support for resuming from hibernation

2014-08-28 Thread Jan Janssen
Ivan Shapovalov intelfx100 at gmail.com writes:

 
 On Wednesday 27 August 2014 at 03:16:10, Zbigniew Jędrzejewski-Szmek wrote:   
  On Tue, Aug 26, 2014 at 10:21:59PM +0200, Lennart Poettering wrote:
   On Wed, 27.08.14 00:17, Ivan Shapovalov (intelfx100 at gmail.com) wrote:
This patchset allows systemd to parse resume= kernel command line
parameter
and initiate resume from the specified device.
  What about swap files with the resume_offset= parameter? Are they still
  being used?
 
 I don't know if somebody uses that, but for now it's missing functionality.
 
 After a cursory search, I could not find a mechanism to initiate a resume with
 offset from userspace. In Arch, it was never implemented even if possible.
 

I'm a heavy user of this myself. It's especially useful because you can just
have a single luks encrypted ext4 without a lvm in between for a swap
partition or (even more yuck) using a separate (encrypted) swap partition.

Arch does support this, mostly because as far as I know, the resume_offset=
is consumed by the kernel, while resume= has to refer to the (unencrypted)
filesystem (/dev/mapper/root in my case). So, as long as this solution waits
for the device to show up in /dev/ (and especially /dev/mapper/ for my
case), this should work out.

Here's information to set this up. Imho more people should be aware this is
possible:
https://wiki.archlinux.org/index.php/Suspend#Hibernation_into_swap_file

Jan

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


Re: [systemd-devel] [PATCHv6 0/3] hibernate-resume: implement support for resuming from hibernation

2014-08-28 Thread Jan Janssen
On Thursday 28 August 2014 11:33:44 Ivan Shapovalov wrote:
 On Thursday 28 August 2014 at 06:25:51, Jan Janssen wrote:
  Ivan Shapovalov intelfx100 at gmail.com writes:
   On Wednesday 27 August 2014 at 03:16:10, Zbigniew Jędrzejewski-Szmek 
   wrote:
On Tue, Aug 26, 2014 at 10:21:59PM +0200, Lennart Poettering wrote:
 On Wed, 27.08.14 00:17, Ivan Shapovalov (intelfx100 at gmail.com) 
 wrote:
  This patchset allows systemd to parse resume= kernel command line
  
  parameter
  
  and initiate resume from the specified device.

What about swap files with the resume_offset= parameter? Are they
still
being used?
   
   I don't know if somebody uses that, but for now it's missing
   functionality.
   
   After a cursory search, I could not find a mechanism to initiate a
   resume with offset from userspace. In Arch, it was never implemented
   even if possible. 
  I'm a heavy user of this myself. It's especially useful because you can
  just have a single luks encrypted ext4 without a lvm in between for a
  swap partition or (even more yuck) using a separate (encrypted) swap
  partition.
  
  Arch does support this, mostly because as far as I know, the
  resume_offset=
  is consumed by the kernel, while resume= has to refer to the (unencrypted)
  filesystem (/dev/mapper/root in my case). So, as long as this solution
  waits for the device to show up in /dev/ (and especially /dev/mapper/ for
  my case), this should work out.
  
  Here's information to set this up. Imho more people should be aware this
  is
  possible:
  https://wiki.archlinux.org/index.php/Suspend#Hibernation_into_swap_file
  
  Jan
 
 Hmm, so is resume_offset= parsed independently of resume=? If that's the
 case, and resume_offset= can be parsed by kernel while resume= is parsed
 by userspace, then yes, I was wrong and this should work.
 
 Actually, it should work _just like before_, sans tuxonice support.

I gave it a try and resume works for me with that sd-resume hook in arch. But 
I'm not too sure whether fsck is delayed properly:

systemd[1]: Started Cryptography Setup for 
luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
systemd[1]: Found device /dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
systemd[1]: Starting File System Check on 
/dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78...
systemd[1]: Starting Resume from hibernation using device 
/dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78...
systemd-fsck[135]: fsck.ext4 doesn't exist, not checking file system on 
/dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78
systemd[1]: Starting Encrypted Volumes.
systemd[1]: Reached target Encrypted Volumes.
systemd[1]: Starting System Initialization.
systemd[1]: Reached target System Initialization.
systemd[1]: Starting Basic System.
systemd[1]: Reached target Basic System.
systemd[1]: Started File System Check on 
/dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.
kernel: PM: Starting manual resume from disk
kernel: PM: Hibernation image partition 254:0 present
kernel: PM: Looking for hibernation image.
systemd-hibernate-resume[137]: Could not resume from 
'/dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78' (254:0).
systemd[1]: Started Resume from hibernation using device 
/dev/mapper/luks-ab8e32ef-3a85-4fee-8377-f41df2e0cb78.

If I read this correctly, the moment the plaintext device appears, the resume 
and fsck are racing each other. And in this case,
fsck won (good thing my fsck binaries are not in the systemd initrd for now).

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


[systemd-devel] Behavior regarding ReadWriteDirectories= and otheres

2014-06-15 Thread Jan Janssen

Hi,

while booting this morning I noticed that a service I wrote which had a 
very paranoid

PrivateTmp=yes
ReadOnlyDirectories=/
ReadWriteDirectories=/var/cache/something
which used to work quite nicely was failing to start. It seems that ever 
since the recent changes with the addition of ProtectSystem=, this 
particular service doesn't get access to its /tmp (or /var/tmp) because 
ReadOnlyDirectories is applied recursively. Even adding /tmp to the 
ReadWriteDirectories will not fix this.


I do know about ProtectSystem and ProtectHome, but I would argue that 
for a service that can handle it, a more paranoid setting like the above 
would be superior and should be available and supported. Is this 
intentionally not supported (any more)?


Jan


A simple service to test this:
[Unit]
Description=Testing access

[Service]
ExecStart=/usr/bin/touch /tmp/access-test
PrivateTmp=true
ReadOnlyDirectories=/
ReadWriteDirectories=/tmp # will not help here
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Networkd randomly doesn't configure network

2014-06-15 Thread Jan Janssen
I had a couple of boots with this patch applied and it seems to fix the 
issue, thanks.


Jan

On 2014-06-14 19:13, Tom Gundersen wrote:

On Sat, Jun 14, 2014 at 3:36 PM, Jan Janssen medhe...@web.de wrote:

systemd-networkd randomly refuses to set up my network card at boot.


Thanks for the report and the logs, that was very helpful.

I think I have solved the problem with
http://cgit.freedesktop.org/systemd/systemd/commit/?id=4f561e8e4364e36345940d4376a9750a829f382f,
but as I cannot reproduce, it would be
great if you could try it out.

Cheers,

Tom


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


[systemd-devel] Networkd randomly doesn't configure network

2014-06-14 Thread Jan Janssen
Hi,

systemd-networkd randomly refuses to set up my network card at boot.
It gets its proper persistent name but no IP address is assigned,
regardless of whether I use a static configuration or DCHP. A simple
systemctl restart systemd-networkd.service fixes it. I'm using a up to
date Arch Linux and systemd 214.

Jan


$ cat /etc/systemd/network/home.network 
[Match]
Name=enp1s4

[Network]
Description=Home Network
DHCP=false
Address=192.168.178.2/24
Gateway=192.168.178.1
DNS=192.168.178.1


A debug log of a boot without it setting up the card (it does also contain the 
log after the daemon restart):
Jun 14 15:14:13 systemd-networkd[212]: timestamp of '/etc/systemd/network' 
changed
Jun 14 15:14:13 systemd-networkd[212]: timestamp of '/usr/lib/systemd/network' 
changed
Jun 14 15:14:14 systemd-networkd[212]: sd-rtnl: discarding 20 bytes of incoming 
message
Jun 14 15:14:14 systemd-networkd[212]:   lo: link 1 added
Jun 14 15:14:14 systemd-networkd[212]:   lo: udev initializing 
link...
Jun 14 15:14:14 systemd-networkd[212]:   lo: flags change: 
+LOOPBACK +UP +LOWER_UP +RUNNING
Jun 14 15:14:14 systemd-networkd[212]:   lo: gained carrier
Jun 14 15:14:14 systemd-networkd[212]: Sent message type=method_call sender=n/a 
destination=org.freedesktop.DBus object=/org/freedesktop/DBus 
interface=org.freedesktop.DBus member=Hello cookie=1 reply_cookie=0 error=n/a
Jun 14 15:14:14 systemd-networkd[212]: sd-rtnl: discarding 20 bytes of incoming 
message
Jun 14 15:14:14 systemd-networkd[212]:   lo: added address: ::1/128
Jun 14 15:14:14 systemd-networkd[212]:   lo: added address: 
127.0.0.1/8
Jun 14 15:14:31 systemd-networkd[212]:   lo: udev initialized link
Jun 14 15:14:32 systemd-networkd[212]:   lo: unmanaged
Jun 14 15:14:32 systemd-networkd[212]: eth0: link 2 added
Jun 14 15:14:32 systemd-networkd[212]: eth0: udev initialized link
Jun 14 15:14:32 systemd-networkd[212]: eth0: unmanaged
Jun 14 15:14:32 systemd-networkd[212]: eth0: flags change: 
+MULTICAST +BROADCAST
Jun 14 15:14:32 systemd-networkd[212]: Got message type=signal 
sender=org.freedesktop.DBus destination=:1.2 object=/org/freedesktop/DBus 
interface=org.freedesktop.DBus member=NameAcquired cookie=2 reply_cookie=0 
error=n/a
Jun 14 15:14:32 systemd-networkd[212]: eth0: renamed to enp1s4
Jun 14 15:14:32 systemd-networkd[212]:wlan0: link 3 added
Jun 14 15:14:32 systemd-networkd[212]:wlan0: udev initialized link
Jun 14 15:14:32 systemd-networkd[212]:wlan0: unmanaged
Jun 14 15:14:32 systemd-networkd[212]:wlan0: flags change: 
+MULTICAST +BROADCAST
Jun 14 15:14:32 systemd-networkd[212]:wlan0: renamed to wlp1s10
Jun 14 15:14:32 systemd-networkd[212]: sd-rtnl: discarding 20 bytes of incoming 
message
Jun 14 15:14:32 systemd-networkd[212]: sd-rtnl: discarding 20 bytes of incoming 
message
Jun 14 15:14:33 systemd-networkd[212]: Got message type=method_return 
sender=org.freedesktop.DBus destination=:1.2 object=n/a interface=n/a 
member=n/a cookie=1 reply_cookie=1 error=n/a
Jun 14 15:15:05 systemd-networkd[212]: Received SIGTERM from PID 1 (systemd).
Jun 14 15:15:05 systemd-networkd[547]: timestamp of '/etc/systemd/network' 
changed
Jun 14 15:15:05 systemd-networkd[547]: timestamp of '/usr/lib/systemd/network' 
changed
Jun 14 15:15:05 systemd-networkd[547]: sd-rtnl: discarding 20 bytes of incoming 
message
Jun 14 15:15:05 systemd-networkd[547]:  wlp1s10: link 3 added
Jun 14 15:15:05 systemd-networkd[547]:  wlp1s10: udev initialized link
Jun 14 15:15:05 systemd-networkd[547]:  wlp1s10: unmanaged
Jun 14 15:15:05 systemd-networkd[547]:  wlp1s10: flags change: 
+MULTICAST +BROADCAST
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: link 2 added
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: udev initialized link
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: found matching network 
'/etc/systemd/network/home.network'
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: bringing link up
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: setting addresses
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: flags change: 
+MULTICAST +BROADCAST
Jun 14 15:15:05 systemd-networkd[547]:   lo: link 1 added
Jun 14 15:15:05 systemd-networkd[547]:   lo: udev initialized link
Jun 14 15:15:05 systemd-networkd[547]:   lo: unmanaged
Jun 14 15:15:05 systemd-networkd[547]:   lo: flags change: 
+LOOPBACK +UP +LOWER_UP +RUNNING
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: getting address 
failed: Device or resource busy
Jun 14 15:15:05 systemd-networkd[547]: Sent message type=method_call sender=n/a 
destination=org.freedesktop.DBus object=/org/freedesktop/DBus 
interface=org.freedesktop.DBus member=Hello cookie=1 reply_cookie=0 error=n/a
Jun 14 

Re: [systemd-devel] Networkd randomly doesn't configure network

2014-06-14 Thread Jan Janssen

It's in the original mail. But I'll attach it anyway.

On 2014-06-14 15:52, Tom Gundersen wrote:

Hi Jan,

Could you attach your home.network file (in particular the [Match] section)?

Cheers,

Tom

On Sat, Jun 14, 2014 at 3:36 PM, Jan Janssen medhe...@web.de wrote:

Hi,

systemd-networkd randomly refuses to set up my network card at boot.
It gets its proper persistent name but no IP address is assigned,
regardless of whether I use a static configuration or DCHP. A simple
systemctl restart systemd-networkd.service fixes it. I'm using a up to
date Arch Linux and systemd 214.

Jan


$ cat /etc/systemd/network/home.network
[Match]
Name=enp1s4

[Network]
Description=Home Network
DHCP=false
Address=192.168.178.2/24
Gateway=192.168.178.1
DNS=192.168.178.1


A debug log of a boot without it setting up the card (it does also contain the 
log after the daemon restart):
Jun 14 15:14:13 systemd-networkd[212]: timestamp of '/etc/systemd/network' 
changed
Jun 14 15:14:13 systemd-networkd[212]: timestamp of '/usr/lib/systemd/network' 
changed
Jun 14 15:14:14 systemd-networkd[212]: sd-rtnl: discarding 20 bytes of incoming 
message
Jun 14 15:14:14 systemd-networkd[212]:   lo: link 1 added
Jun 14 15:14:14 systemd-networkd[212]:   lo: udev initializing 
link...
Jun 14 15:14:14 systemd-networkd[212]:   lo: flags change: 
+LOOPBACK +UP +LOWER_UP +RUNNING
Jun 14 15:14:14 systemd-networkd[212]:   lo: gained carrier
Jun 14 15:14:14 systemd-networkd[212]: Sent message type=method_call sender=n/a 
destination=org.freedesktop.DBus object=/org/freedesktop/DBus 
interface=org.freedesktop.DBus member=Hello cookie=1 reply_cookie=0 error=n/a
Jun 14 15:14:14 systemd-networkd[212]: sd-rtnl: discarding 20 bytes of incoming 
message
Jun 14 15:14:14 systemd-networkd[212]:   lo: added address: ::1/128
Jun 14 15:14:14 systemd-networkd[212]:   lo: added address: 
127.0.0.1/8
Jun 14 15:14:31 systemd-networkd[212]:   lo: udev initialized link
Jun 14 15:14:32 systemd-networkd[212]:   lo: unmanaged
Jun 14 15:14:32 systemd-networkd[212]: eth0: link 2 added
Jun 14 15:14:32 systemd-networkd[212]: eth0: udev initialized link
Jun 14 15:14:32 systemd-networkd[212]: eth0: unmanaged
Jun 14 15:14:32 systemd-networkd[212]: eth0: flags change: 
+MULTICAST +BROADCAST
Jun 14 15:14:32 systemd-networkd[212]: Got message type=signal 
sender=org.freedesktop.DBus destination=:1.2 object=/org/freedesktop/DBus 
interface=org.freedesktop.DBus member=NameAcquired cookie=2 reply_cookie=0 
error=n/a
Jun 14 15:14:32 systemd-networkd[212]: eth0: renamed to enp1s4
Jun 14 15:14:32 systemd-networkd[212]:wlan0: link 3 added
Jun 14 15:14:32 systemd-networkd[212]:wlan0: udev initialized link
Jun 14 15:14:32 systemd-networkd[212]:wlan0: unmanaged
Jun 14 15:14:32 systemd-networkd[212]:wlan0: flags change: 
+MULTICAST +BROADCAST
Jun 14 15:14:32 systemd-networkd[212]:wlan0: renamed to wlp1s10
Jun 14 15:14:32 systemd-networkd[212]: sd-rtnl: discarding 20 bytes of incoming 
message
Jun 14 15:14:32 systemd-networkd[212]: sd-rtnl: discarding 20 bytes of incoming 
message
Jun 14 15:14:33 systemd-networkd[212]: Got message type=method_return 
sender=org.freedesktop.DBus destination=:1.2 object=n/a interface=n/a 
member=n/a cookie=1 reply_cookie=1 error=n/a
Jun 14 15:15:05 systemd-networkd[212]: Received SIGTERM from PID 1 (systemd).
Jun 14 15:15:05 systemd-networkd[547]: timestamp of '/etc/systemd/network' 
changed
Jun 14 15:15:05 systemd-networkd[547]: timestamp of '/usr/lib/systemd/network' 
changed
Jun 14 15:15:05 systemd-networkd[547]: sd-rtnl: discarding 20 bytes of incoming 
message
Jun 14 15:15:05 systemd-networkd[547]:  wlp1s10: link 3 added
Jun 14 15:15:05 systemd-networkd[547]:  wlp1s10: udev initialized link
Jun 14 15:15:05 systemd-networkd[547]:  wlp1s10: unmanaged
Jun 14 15:15:05 systemd-networkd[547]:  wlp1s10: flags change: 
+MULTICAST +BROADCAST
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: link 2 added
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: udev initialized link
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: found matching network 
'/etc/systemd/network/home.network'
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: bringing link up
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: setting addresses
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: flags change: 
+MULTICAST +BROADCAST
Jun 14 15:15:05 systemd-networkd[547]:   lo: link 1 added
Jun 14 15:15:05 systemd-networkd[547]:   lo: udev initialized link
Jun 14 15:15:05 systemd-networkd[547]:   lo: unmanaged
Jun 14 15:15:05 systemd-networkd[547]:   lo: flags change: 
+LOOPBACK +UP +LOWER_UP +RUNNING
Jun 14 15:15:05 systemd-networkd[547]:   enp1s4: getting

Re: [systemd-devel] [HEADS-UP] It's release time!

2014-02-22 Thread Jan Janssen



On 02/18/2014 01:33 PM, Tom Gundersen wrote:

On Tue, Feb 18, 2014 at 1:20 PM, Jan Janssen medhe...@web.de wrote:

the *.link files for networkd completely lack documentation.


They are documented in udev(8). Let me know if anything is unclear or lacking.


And in general,
I would say that networkd could benefit from a more detailed man page before
this gets released.


Anything in particular you feel is unclear or lacking (I'm going
through it now anyway, but more input is always better)?

Cheers,

Tom



Hi,

I now installed systemd 209 from arch testing and it lacks documentation 
about resolv.conf. It appears that you're supposed to create your own 
one or link the one created in /run. This really needs mentioning in the 
man page of networkd.


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


Re: [systemd-devel] [HEADS-UP] It's release time!

2014-02-18 Thread Jan Janssen
 Gesendet: Dienstag, 18. Februar 2014 um 13:33 Uhr
 Von: Tom Gundersen t...@jklm.no
 An: Jan Janssen medhe...@web.de
 Cc: systemd Mailing List systemd-devel@lists.freedesktop.org
 Betreff: Re: [systemd-devel] [HEADS-UP] It's release time!

 On Tue, Feb 18, 2014 at 1:20 PM, Jan Janssen medhe...@web.de wrote:
  the *.link files for networkd completely lack documentation.
 
 They are documented in udev(8). Let me know if anything is unclear or lacking.

Ah, thanks. This really needs a proper mention/link in systemd-networkd manpage
or put there instead, the inexpressive udev(7) reference at the end is not 
enough.
When poeple are reading up on networkd, they will not expect this information 
to be
in the udev manpage, even though the implementation of this is (rightfully) 
located
in udev.

  And in general,
  I would say that networkd could benefit from a more detailed man page before
  this gets released.
 
 Anything in particular you feel is unclear or lacking (I'm going
 through it now anyway, but more input is always better)?

Nothing in particular. From reading it - and now that I know out about the 
.link files -
I (and others in general) would be able to use it for my purposes right away. I 
was more
thinking on the lines of a condensed down version of your G+ posts on networkd 
in its
manpage. Mainly how it is supposed to work (the big picture), how it interacts 
with
NetworkManager et.al., and also what it currently does not provide/is lacking. 
And maybe
some examples on different set ups, since those are always nice in a manpage to 
know
that you're not doing it wrongly and give you a warm fuzzy feeling :D

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


[systemd-devel] [PATCH] man: cryptsetup-1.6.3 now allows partition device file in system mode

2014-02-07 Thread Jan Janssen
---
 man/crypttab.xml | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/man/crypttab.xml b/man/crypttab.xml
index 5f386e5..c563851 100644
--- a/man/crypttab.xml
+++ b/man/crypttab.xml
@@ -305,14 +305,7 @@
 
 listitemparaUse TrueCrypt in system
 encryption mode. This implies
-varnametcrypt/varname./para
-
-paraPlease note that when using this mode, 
the
-whole device needs to be given in the second
-field instead of the partition. For example: if
-literal/dev/sda2/literal is the system
-encrypted TrueCrypt patition, 
literal/dev/sda/literal
-has to be given./para/listitem
+   varnametcrypt/varname./para/listitem
 /varlistentry
 
 varlistentry
-- 
1.8.5.4

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


[systemd-devel] [PATCH] man: cryptsetup now allows partition device file in system mode

2014-02-06 Thread Jan Janssen
---
 man/crypttab.xml | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/man/crypttab.xml b/man/crypttab.xml
index 5f386e5..c563851 100644
--- a/man/crypttab.xml
+++ b/man/crypttab.xml
@@ -305,14 +305,7 @@
 
 listitemparaUse TrueCrypt in system
 encryption mode. This implies
-varnametcrypt/varname./para
-
-paraPlease note that when using this mode, 
the
-whole device needs to be given in the second
-field instead of the partition. For example: if
-literal/dev/sda2/literal is the system
-encrypted TrueCrypt patition, 
literal/dev/sda/literal
-has to be given./para/listitem
+   varnametcrypt/varname./para/listitem
 /varlistentry
 
 varlistentry
-- 
1.8.5.3

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


[systemd-devel] [PATCH] Make hibernation test work for swap files

2013-10-31 Thread Jan Janssen
Suspend to disk works for swap files too (even if it is located
on an ecrypted file system):
https://www.kernel.org/doc/Documentation/power/swsusp-and-swap-files.txt
---
 src/shared/sleep-config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
index d068bfc..2bb0493 100644
--- a/src/shared/sleep-config.c
+++ b/src/shared/sleep-config.c
@@ -206,7 +206,7 @@ static int hibernation_partition_size(size_t *size, size_t 
*used) {
 if (!d)
 return -ENOMEM;
 
-if (!streq(type, partition)) {
+if (!streq(type, partition)  !streq(type, file)) {
 log_debug(Partition %s has type %s, ignoring., d, 
type);
 continue;
 }
-- 
1.8.4.2

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


Re: [systemd-devel] removal of RD_TIMESTAMP support in initrd

2013-07-23 Thread Jan Janssen

On 07/23/2013 01:16 AM, Tom Gundersen wrote:

On Tue, Jul 23, 2013 at 12:44 AM, Lennart Poettering
lenn...@poettering.net wrote:

I do understand that you are currently not running systemd in the initrd
[1], so for you for now this is indeed a loss of functionality. I am
sorry for that, but please understand this as gentle push to maybe use
systemd in the initrd, or even better maybe just adopt dracut?


For the record, I too think it is a shame this functionality is lost,
but for a different reason: having the possibility to (easily) get
performance data to compare systemd (in the initramfs) and non-systemd
(in the initramfs) boots is the best way to push for the adoption of
systemd in the initramfs (which I think is the future).


[1] I remember Arch's Tom Gunderson working with Harald on improving the
mounting logic in darcut/systemd quite a bit at the last
hackfest. Because of Arch we now have much nicer mount code in
Dracut/systemd. It would be a pitty if that'd be lost to Arch itself,
where this came from...


Please note that there is no reason to keep systemd-timestamp in the
tree with this feature removed.

Jan

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


Re: [systemd-devel] [PATCH v5] journalctl: Add support for showing messages from a previous boot

2013-07-18 Thread Jan Janssen

On 07/18/2013 06:10 AM, Zbigniew Jędrzejewski-Szmek wrote:

On Tue, Jul 16, 2013 at 05:46:04PM +0200, Lennart Poettering wrote:

On Tue, 16.07.13 17:42, Zbigniew Jędrzejewski-Szmek (zbys...@in.waw.pl) wrote:



On Tue, Jul 16, 2013 at 05:39:54PM +0200, Lennart Poettering wrote:

On Fri, 28.06.13 17:26, Jan Janssen (medhe...@web.de) wrote:
Applied this one now. If people start complaining about its speed we can
reinvestigate and do find some way for optimization...

We need to think about negative matches. Looking for previous boots
with negative matches should work nicely.


The bisection tables make this less efficient but certainly possible.


I'd like to complain about the : in the syntax though.


Hmm, what would you propose? There's still time to fix it!

I went ahead, and removed : from the syntax. It feels OK in my testing.

And I also made one optimization, which is important imho: 'journactl -b'
will still use the boot id from sd_id128_get_boot() to avoid searching
through the tables, and 'journalctl -b BOOT_ID[+-0]' will just
use  BOOT_ID without searching through the tables. This should help
a lot when running with cold cache.

Zbyszek



I really don't like arguments to options that can start with -, it
can easily be confused with another option. Especially if one were ever
to introduce options like -0 to -9. Also, not accepting long UUIDs
is kind of restricting the user. But ultimately, this is
bike-shedding...

But more importantly, you've introduced a bug:

$ ./journalctl -b a709bdcbaa1b422f8338a25fd2d4d61d
Relative boot ID offset must start with a '+' or a '-', found ''

Also, for the challenged people (me), does this really guard the array 
access (count = INT_MAX comes to my mind)? And if so, how?


if (relative  (int) count || relative = -(int)count)

If you could silence this warning, it would be nice :P

src/journal/journalctl.c: In function ‘get_relative_boot_id’:
src/journal/journalctl.c:747:63: warning: comparison between signed and 
unsigned integer expressions [-Wsign-compare]

 (id - all_ids) + relative = count)

Anyway, gonna go sulk now for not having come up with such nice code
in the first place :(

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


Re: [systemd-devel] test-tables failure

2013-07-16 Thread Jan Janssen

On 07/16/2013 04:33 PM, Lennart Poettering wrote:

On Tue, 16.07.13 14:57, Jan Janssen (medhe...@web.de) wrote:


Hi,

test-tables fails on my system. The one it's failing on is:
 syscall: 222 → (null) → -1

syscall_max() tells me that I have 351 syscalls, so I guess
there is a logic error in the test case?

This is on a pretty old x86 machine.


Hmm, on your system do you have a syscall 222 defined anywhere in
sys/syscall.h (or any of the headers that pulls in)?

Lennart



Nope, unistd_x32.h nor unistd_32.h (whichever one is included from
syscall.h on my system) has syscall 222.

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


[systemd-devel] [PATCH 1/3 v2] cryptsetup: Move password query out of main

2013-07-13 Thread Jan Janssen
Also use _cleanup_free_ where possible.
---
 src/cryptsetup/cryptsetup.c | 153 +---
 1 file changed, 72 insertions(+), 81 deletions(-)

diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index 347394d..994a0e0 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -215,7 +215,8 @@ finish:
 }
 
 static char *disk_mount_point(const char *label) {
-char *mp = NULL, *device = NULL;
+char *mp = NULL;
+_cleanup_free_ char *device = NULL;
 FILE *f = NULL;
 struct mntent *m;
 
@@ -238,11 +239,68 @@ finish:
 if (f)
 endmntent(f);
 
-free(device);
-
 return mp;
 }
 
+static int get_password(const char *name, usec_t until, bool accept_cached, 
char ***passwords) {
+int r;
+char **p;
+_cleanup_free_ char *text = NULL;
+
+assert(name);
+assert(passwords);
+
+if (asprintf(text, Please enter passphrase for disk %s!, name)  0)
+return log_oom();
+
+r = ask_password_auto(text, drive-harddisk, until, accept_cached, 
passwords);
+if (r  0) {
+log_error(Failed to query password: %s, strerror(-r));
+return r;
+}
+
+if (opt_verify) {
+_cleanup_strv_free_ char **passwords2 = NULL;
+
+assert(strv_length(*passwords) == 1);
+
+if (asprintf(text, Please enter passphrase for disk %s! 
(verification), name)  0)
+return log_oom();
+
+r = ask_password_auto(text, drive-harddisk, until, false, 
passwords2);
+if (r  0) {
+log_error(Failed to query verification password: %s, 
strerror(-r));
+return r;
+}
+
+assert(strv_length(passwords2) == 1);
+
+if (!streq(*passwords[0], passwords2[0])) {
+log_warning(Passwords did not match, retrying.);
+return -EAGAIN;
+}
+}
+
+strv_uniq(*passwords);
+
+STRV_FOREACH(p, *passwords) {
+char *c;
+
+if (strlen(*p)+1 = opt_key_size)
+continue;
+
+/* Pad password if necessary */
+if (!(c = new(char, opt_key_size)))
+return log_oom();
+
+strncpy(c, *p, opt_key_size);
+free(*p);
+*p = c;
+}
+
+return 0;
+}
+
 static int help(void) {
 
 printf(%s attach VOLUME SOURCEDEVICE [PASSWORD] [OPTIONS]\n
@@ -257,9 +315,6 @@ static int help(void) {
 int main(int argc, char *argv[]) {
 int r = EXIT_FAILURE;
 struct crypt_device *cd = NULL;
-char **passwords = NULL, *truncated_cipher = NULL;
-const char *cipher = NULL, *cipher_mode = NULL, *hash = NULL, *name = 
NULL;
-char *description = NULL, *name_buffer = NULL, *mount_point = NULL;
 
 if (argc = 1) {
 help();
@@ -281,9 +336,12 @@ int main(int argc, char *argv[]) {
 uint32_t flags = 0;
 int k;
 unsigned try;
-const char *key_file = NULL;
 usec_t until;
 crypt_status_info status;
+const char *key_file = NULL, *cipher = NULL, *cipher_mode = 
NULL,
+   *hash = NULL, *name = NULL;
+_cleanup_free_ char *description = NULL, *name_buffer = NULL,
+*mount_point = NULL, *truncated_cipher = 
NULL;
 
 /* Arguments: systemd-cryptsetup attach VOLUME SOURCE-DEVICE 
[PASSWORD] [OPTIONS] */
 
@@ -386,73 +444,14 @@ int main(int argc, char *argv[]) {
 
 for (try = 0; try  opt_tries; try++) {
 bool pass_volume_key = false;
-
-strv_free(passwords);
-passwords = NULL;
+_cleanup_strv_free_ char **passwords = NULL;
 
 if (!key_file) {
-char *text, **p;
-
-if (asprintf(text, Please enter passphrase 
for disk %s!, name)  0) {
-log_oom();
-goto finish;
-}
-
-k = ask_password_auto(text, drive-harddisk, 
until, try == 0  !opt_verify, passwords);
-free(text);
-
-if (k  0) {
-log_error(Failed to query password: 
%s, strerror(-k));
+k = get_password(name, until, try == 0  
!opt_verify, passwords);
+if (k == -EAGAIN)
+continue;
+  

[systemd-devel] [PATCH 3/3 v2] cryptsetup: Add tcrypt support

2013-07-13 Thread Jan Janssen
Tcrypt uses a different approach to passphrases/key files. The
passphrase and all key files are incorporated into the password
to open the volume. So, the idea of slots that provide a way to
open the volume with different passphrases/key files that are
independent from each other like with LUKS does not apply.

Therefore, we use the key file from /etc/crypttab as the source
for the passphrase. The actual key files that are combined with
the passphrase into a password are provided as a new option in
/etc/crypttab and can be given multiple times if more than one
key file is used by a volume.
---
 configure.ac|   2 +-
 man/crypttab.xml| 300 +++-
 src/cryptsetup/cryptsetup.c |  79 +++-
 3 files changed, 258 insertions(+), 123 deletions(-)

diff --git a/configure.ac b/configure.ac
index 1e196f7..115208a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -553,7 +553,7 @@ AC_SUBST(AUDIT_LIBS)
 have_libcryptsetup=no
 AC_ARG_ENABLE(libcryptsetup, AS_HELP_STRING([--disable-libcryptsetup], 
[disable libcryptsetup tools]))
 if test x$enable_libcryptsetup != xno; then
-PKG_CHECK_MODULES(LIBCRYPTSETUP, [ libcryptsetup = 1.4.2 ],
+PKG_CHECK_MODULES(LIBCRYPTSETUP, [ libcryptsetup = 1.6.0 ],
 [AC_DEFINE(HAVE_LIBCRYPTSETUP, 1, [Define if libcryptsetup is 
available]) have_libcryptsetup=yes], have_libcryptsetup=no)
 if test x$have_libcryptsetup = xno -a x$enable_libcryptsetup = 
xyes; then
 AC_MSG_ERROR([*** libcryptsetup support requested but 
libraries not found])
diff --git a/man/crypttab.xml b/man/crypttab.xml
index e52b7e6..298f39e 100644
--- a/man/crypttab.xml
+++ b/man/crypttab.xml
@@ -75,23 +75,29 @@
 fields are mandatory, the remaining two are
 optional./para
 
+paraSetting up encrypted block devices using this file
+supports three encryption modes: LUKS, TrueCrypt and plain.
+See 
citerefentryrefentrytitlecryptsetup/refentrytitlemanvolnum8/manvolnum/citerefentry
+for more information about each mode. When no mode is specified
+in the options field and the block device contains a LUKS
+signature, it is opened as a LUKS device; otherwise, it is
+assumed to be in raw dm-crypt (plain mode) format./para
+
 paraThe first field contains the name of the
 resulting encrypted block device; the device is set up
 within filename/dev/mapper//filename./para
 
 paraThe second field contains a path to the
-underlying block device, or a specification of a block
+underlying block device or file, or a specification of a block
 device via literalUUID=/literal followed by the
-UUID.  If the block device contains a LUKS signature,
-it is opened as a LUKS encrypted partition; otherwise,
-it is assumed to be a raw dm-crypt partition./para
+UUID./para
 
 paraThe third field specifies the encryption
 password.  If the field is not present or the password
-is set to none, the password has to be manually
-entered during system boot.  Otherwise, the field is
-interpreted as a path to a file containing the
-encryption password.  For swap encryption,
+is set to literalnone/literal or literal-/literal,
+the password has to be manually entered during system boot.
+Otherwise, the field is interpreted as a absolute path to
+a file containing the encryption password. For swap encryption,
 filename/dev/urandom/filename or the hardware
 device filename/dev/hw_random/filename can be used
 as the password file; using
@@ -104,181 +110,237 @@
 options are recognized:/para
 
 variablelist class='crypttab-options'
+
+varlistentry
+termvarnameallow-discards/varname/term
+
+listitemparaAllow discard requests to be
+passed through the encrypted block device. This
+improves performance on SSD storage but has
+security implications./para/listitem
+/varlistentry
+
 varlistentry
 termvarnamecipher=/varname/term
 
-listitemparaSpecifies the cipher
-to use; see
+listitemparaSpecifies the cipher to use. 
See
 
citerefentryrefentrytitlecryptsetup/refentrytitlemanvolnum8/manvolnum/citerefentry
-   

[systemd-devel] [PATCH 2/3 v2] cryptsetup: Move attaching of the device out of main

2013-07-13 Thread Jan Janssen
---
 src/cryptsetup/cryptsetup.c | 222 +++-
 1 file changed, 114 insertions(+), 108 deletions(-)

diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index 994a0e0..e84ebba 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -301,6 +301,102 @@ static int get_password(const char *name, usec_t until, 
bool accept_cached, char
 return 0;
 }
 
+static int attach_luks_or_plain(struct crypt_device *cd,
+const char *name,
+const char *key_file,
+char **passwords,
+uint32_t flags) {
+int r = 0;
+bool pass_volume_key = false;
+
+assert(cd);
+assert(name);
+assert(key_file || passwords);
+
+if (!opt_type || streq(opt_type, CRYPT_LUKS1))
+r = crypt_load(cd, CRYPT_LUKS1, NULL);
+
+if ((!opt_type  r  0) || streq_ptr(opt_type, CRYPT_PLAIN)) {
+struct crypt_params_plain params = {};
+const char *cipher, *cipher_mode;
+_cleanup_free_ char *truncated_cipher = NULL;
+
+if (opt_hash) {
+/* plain isn't a real hash type. it just means use no 
hash */
+if (!streq(opt_hash, plain))
+params.hash = opt_hash;
+} else
+params.hash = ripemd160;
+
+if (opt_cipher) {
+size_t l;
+
+l = strcspn(opt_cipher, -);
+truncated_cipher = strndup(opt_cipher, l);
+if (!truncated_cipher)
+return log_oom();
+
+cipher = truncated_cipher;
+cipher_mode = opt_cipher[l] ? opt_cipher+l+1 : plain;
+} else {
+cipher = aes;
+cipher_mode = cbc-essiv:sha256;
+}
+
+/* for CRYPT_PLAIN limit reads
+ * from keyfile to key length, and
+ * ignore keyfile-size */
+opt_keyfile_size = opt_key_size / 8;
+
+/* In contrast to what the name
+ * crypt_setup() might suggest this
+ * doesn't actually format anything,
+ * it just configures encryption
+ * parameters when used for plain
+ * mode. */
+r = crypt_format(cd, CRYPT_PLAIN, cipher, cipher_mode,
+ NULL, NULL, opt_keyfile_size, params);
+
+/* hash == NULL implies the user passed plain */
+pass_volume_key = (params.hash == NULL);
+}
+
+if (r  0) {
+log_error(Loading of cryptographic parameters failed: %s, 
strerror(-r));
+return r;
+}
+
+log_info(Set cipher %s, mode %s, key size %i bits for device %s.,
+ crypt_get_cipher(cd),
+ crypt_get_cipher_mode(cd),
+ crypt_get_volume_key_size(cd)*8,
+ crypt_get_device_name(cd));
+
+if (key_file) {
+r = crypt_activate_by_keyfile_offset(cd, name, CRYPT_ANY_SLOT,
+ key_file, 
opt_keyfile_size,
+ opt_keyfile_offset, 
flags);
+if (r  0) {
+log_error(Failed to activate with key file '%s': %s, 
key_file, strerror(-r));
+return -EAGAIN;
+}
+} else {
+char **p;
+
+STRV_FOREACH(p, passwords) {
+if (pass_volume_key)
+r = crypt_activate_by_volume_key(cd, name, *p, 
opt_key_size, flags);
+else
+r = crypt_activate_by_passphrase(cd, name, 
CRYPT_ANY_SLOT, *p, strlen(*p), flags);
+
+if (r = 0)
+break;
+}
+}
+
+return r;
+}
+
 static int help(void) {
 
 printf(%s attach VOLUME SOURCEDEVICE [PASSWORD] [OPTIONS]\n
@@ -335,13 +431,11 @@ int main(int argc, char *argv[]) {
 if (streq(argv[1], attach)) {
 uint32_t flags = 0;
 int k;
-unsigned try;
+unsigned tries;
 usec_t until;
 crypt_status_info status;
-const char *key_file = NULL, *cipher = NULL, *cipher_mode = 
NULL,
-   *hash = NULL, *name = NULL;
-_cleanup_free_ char *description = NULL, *name_buffer = NULL,
-*mount_point = NULL, *truncated_cipher = 
NULL;
+const char *key_file = NULL, *name = 

Re: [systemd-devel] [PATCH 3/3 (rebased)] cryptsetup: Add tcrypt support

2013-07-12 Thread Jan Janssen

On 07/12/2013 08:36 PM, Lennart Poettering wrote:

On Tue, 09.07.13 21:15, Jan Janssen (medhe...@web.de) wrote:


+if (*key_file) {
+r = read_one_line_file(*key_file, passphrase);
+if (r  0) {
+log_error(Failed to read key file: %s, strerror(-r));
+*key_file = NULL;
+return -EAGAIN;


I can't say I like functions that change the parameters when they fail,
any chance we can fix that?

otherwise looks good.

Lennart



When I read the (old) luks code correctly, it does the same: falling
back to normal password query if the key file does not work. I just
thought it would be best to do the same here.

I can certainly make this a fatal error, so no retries are attempted,
but then the luks code should do the same, imho. What do you think?

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


[systemd-devel] [PATCH 3/3 (rebased)] cryptsetup: Add tcrypt support

2013-07-09 Thread Jan Janssen
Tcrypt uses a different approach to passphrases/key files. The
passphrase and all key files are incorporated into the password
to open the volume. So, the idea of slots that provide a way to
open the volume with different passphrases/key files that are
independent from each other like with LUKS does not apply.

Therefore, we use the key file from /etc/crypttab as the source
for the passphrase. The actual key files that are combined with
the passphrase into a password are provided as a new option in
/etc/crypttab and can be given multiple times if more than one
key file is used by a volume.
---
Hi,
this is just a rebase so this patch applies cleanly. The other two
patches still work.

I would really like to see this one get in. I've been using this
to mount my system encrypted truecrypt partition ever since I
cooked this up and it works very nicely.

Anyone who wants to test system encryption mode should probably
get themselves the latest git version of cryptsetup since it
contains a few fixes for that mode (mainly making this mode work
on a drive with other patitions already mounted/in use). But as long
as you don't use system mode (removeable media, truecrypt container
files, or non-system encrypted partitions) you'd only need
cryptsetup 1.6.0.

Thanks,
Jan

 man/crypttab.xml| 300 +++-
 src/cryptsetup/cryptsetup.c |  81 +++-
 2 files changed, 259 insertions(+), 122 deletions(-)

diff --git a/man/crypttab.xml b/man/crypttab.xml
index e52b7e6..298f39e 100644
--- a/man/crypttab.xml
+++ b/man/crypttab.xml
@@ -75,23 +75,29 @@
 fields are mandatory, the remaining two are
 optional./para
 
+paraSetting up encrypted block devices using this file
+supports three encryption modes: LUKS, TrueCrypt and plain.
+See 
citerefentryrefentrytitlecryptsetup/refentrytitlemanvolnum8/manvolnum/citerefentry
+for more information about each mode. When no mode is specified
+in the options field and the block device contains a LUKS
+signature, it is opened as a LUKS device; otherwise, it is
+assumed to be in raw dm-crypt (plain mode) format./para
+
 paraThe first field contains the name of the
 resulting encrypted block device; the device is set up
 within filename/dev/mapper//filename./para
 
 paraThe second field contains a path to the
-underlying block device, or a specification of a block
+underlying block device or file, or a specification of a block
 device via literalUUID=/literal followed by the
-UUID.  If the block device contains a LUKS signature,
-it is opened as a LUKS encrypted partition; otherwise,
-it is assumed to be a raw dm-crypt partition./para
+UUID./para
 
 paraThe third field specifies the encryption
 password.  If the field is not present or the password
-is set to none, the password has to be manually
-entered during system boot.  Otherwise, the field is
-interpreted as a path to a file containing the
-encryption password.  For swap encryption,
+is set to literalnone/literal or literal-/literal,
+the password has to be manually entered during system boot.
+Otherwise, the field is interpreted as a absolute path to
+a file containing the encryption password. For swap encryption,
 filename/dev/urandom/filename or the hardware
 device filename/dev/hw_random/filename can be used
 as the password file; using
@@ -104,181 +110,237 @@
 options are recognized:/para
 
 variablelist class='crypttab-options'
+
+varlistentry
+termvarnameallow-discards/varname/term
+
+listitemparaAllow discard requests to be
+passed through the encrypted block device. This
+improves performance on SSD storage but has
+security implications./para/listitem
+/varlistentry
+
 varlistentry
 termvarnamecipher=/varname/term
 
-listitemparaSpecifies the cipher
-to use; see
+listitemparaSpecifies the cipher to use. 
See
 
citerefentryrefentrytitlecryptsetup/refentrytitlemanvolnum8/manvolnum/citerefentry
-for possible values and the default
-value of this option.  A cipher with
-  

[systemd-devel] [PATCH 1/3] cryptsetup: Move password query out of main

2013-07-02 Thread Jan Janssen
Also use _cleanup_free_ where possible.
---
 src/cryptsetup/cryptsetup.c | 153 +---
 1 file changed, 72 insertions(+), 81 deletions(-)

diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index 347394d..994a0e0 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -215,7 +215,8 @@ finish:
 }
 
 static char *disk_mount_point(const char *label) {
-char *mp = NULL, *device = NULL;
+char *mp = NULL;
+_cleanup_free_ char *device = NULL;
 FILE *f = NULL;
 struct mntent *m;
 
@@ -238,11 +239,68 @@ finish:
 if (f)
 endmntent(f);
 
-free(device);
-
 return mp;
 }
 
+static int get_password(const char *name, usec_t until, bool accept_cached, 
char ***passwords) {
+int r;
+char **p;
+_cleanup_free_ char *text = NULL;
+
+assert(name);
+assert(passwords);
+
+if (asprintf(text, Please enter passphrase for disk %s!, name)  0)
+return log_oom();
+
+r = ask_password_auto(text, drive-harddisk, until, accept_cached, 
passwords);
+if (r  0) {
+log_error(Failed to query password: %s, strerror(-r));
+return r;
+}
+
+if (opt_verify) {
+_cleanup_strv_free_ char **passwords2 = NULL;
+
+assert(strv_length(*passwords) == 1);
+
+if (asprintf(text, Please enter passphrase for disk %s! 
(verification), name)  0)
+return log_oom();
+
+r = ask_password_auto(text, drive-harddisk, until, false, 
passwords2);
+if (r  0) {
+log_error(Failed to query verification password: %s, 
strerror(-r));
+return r;
+}
+
+assert(strv_length(passwords2) == 1);
+
+if (!streq(*passwords[0], passwords2[0])) {
+log_warning(Passwords did not match, retrying.);
+return -EAGAIN;
+}
+}
+
+strv_uniq(*passwords);
+
+STRV_FOREACH(p, *passwords) {
+char *c;
+
+if (strlen(*p)+1 = opt_key_size)
+continue;
+
+/* Pad password if necessary */
+if (!(c = new(char, opt_key_size)))
+return log_oom();
+
+strncpy(c, *p, opt_key_size);
+free(*p);
+*p = c;
+}
+
+return 0;
+}
+
 static int help(void) {
 
 printf(%s attach VOLUME SOURCEDEVICE [PASSWORD] [OPTIONS]\n
@@ -257,9 +315,6 @@ static int help(void) {
 int main(int argc, char *argv[]) {
 int r = EXIT_FAILURE;
 struct crypt_device *cd = NULL;
-char **passwords = NULL, *truncated_cipher = NULL;
-const char *cipher = NULL, *cipher_mode = NULL, *hash = NULL, *name = 
NULL;
-char *description = NULL, *name_buffer = NULL, *mount_point = NULL;
 
 if (argc = 1) {
 help();
@@ -281,9 +336,12 @@ int main(int argc, char *argv[]) {
 uint32_t flags = 0;
 int k;
 unsigned try;
-const char *key_file = NULL;
 usec_t until;
 crypt_status_info status;
+const char *key_file = NULL, *cipher = NULL, *cipher_mode = 
NULL,
+   *hash = NULL, *name = NULL;
+_cleanup_free_ char *description = NULL, *name_buffer = NULL,
+*mount_point = NULL, *truncated_cipher = 
NULL;
 
 /* Arguments: systemd-cryptsetup attach VOLUME SOURCE-DEVICE 
[PASSWORD] [OPTIONS] */
 
@@ -386,73 +444,14 @@ int main(int argc, char *argv[]) {
 
 for (try = 0; try  opt_tries; try++) {
 bool pass_volume_key = false;
-
-strv_free(passwords);
-passwords = NULL;
+_cleanup_strv_free_ char **passwords = NULL;
 
 if (!key_file) {
-char *text, **p;
-
-if (asprintf(text, Please enter passphrase 
for disk %s!, name)  0) {
-log_oom();
-goto finish;
-}
-
-k = ask_password_auto(text, drive-harddisk, 
until, try == 0  !opt_verify, passwords);
-free(text);
-
-if (k  0) {
-log_error(Failed to query password: 
%s, strerror(-k));
+k = get_password(name, until, try == 0  
!opt_verify, passwords);
+if (k == -EAGAIN)
+continue;
+  

[systemd-devel] [PATCH 2/3] cryptsetup: Move attaching of the device out of main

2013-07-02 Thread Jan Janssen
---
 src/cryptsetup/cryptsetup.c | 229 +++-
 1 file changed, 121 insertions(+), 108 deletions(-)

diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index 994a0e0..cb48009 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -301,6 +301,108 @@ static int get_password(const char *name, usec_t until, 
bool accept_cached, char
 return 0;
 }
 
+static int attach_luks_or_plain(struct crypt_device *cd,
+const char *name,
+const char **key_file,
+char **passwords,
+uint32_t flags) {
+int r = 0;
+bool pass_volume_key = false;
+
+assert(cd);
+assert(name);
+assert(key_file);
+
+if (!opt_type || streq(opt_type, CRYPT_LUKS1))
+r = crypt_load(cd, CRYPT_LUKS1, NULL);
+
+if ((!opt_type  r  0) || streq_ptr(opt_type, CRYPT_PLAIN)) {
+struct crypt_params_plain params = {};
+const char *cipher, *cipher_mode;
+_cleanup_free_ char *truncated_cipher = NULL;
+
+if (opt_hash) {
+/* plain isn't a real hash type. it just means use no 
hash */
+if (!streq(opt_hash, plain))
+params.hash = opt_hash;
+} else
+params.hash = ripemd160;
+
+if (opt_cipher) {
+size_t l;
+
+l = strcspn(opt_cipher, -);
+truncated_cipher = strndup(opt_cipher, l);
+if (!truncated_cipher)
+return log_oom();
+
+cipher = truncated_cipher;
+cipher_mode = opt_cipher[l] ? opt_cipher+l+1 : plain;
+} else {
+cipher = aes;
+cipher_mode = cbc-essiv:sha256;
+}
+
+/* for CRYPT_PLAIN limit reads
+ * from keyfile to key length, and
+ * ignore keyfile-size */
+opt_keyfile_size = opt_key_size / 8;
+
+/* In contrast to what the name
+ * crypt_setup() might suggest this
+ * doesn't actually format anything,
+ * it just configures encryption
+ * parameters when used for plain
+ * mode. */
+r = crypt_format(cd, CRYPT_PLAIN,
+ cipher,
+ cipher_mode,
+ NULL,
+ NULL,
+ opt_keyfile_size,
+ params);
+
+/* hash == NULL implies the user passed plain */
+pass_volume_key = (params.hash == NULL);
+}
+
+if (r  0) {
+log_error(Loading of cryptographic parameters failed: %s, 
strerror(-r));
+return r;
+}
+
+log_info(Set cipher %s, mode %s, key size %i bits for device %s.,
+ crypt_get_cipher(cd),
+ crypt_get_cipher_mode(cd),
+ crypt_get_volume_key_size(cd)*8,
+ crypt_get_device_name(cd));
+
+if (*key_file) {
+r = crypt_activate_by_keyfile_offset(cd, name, CRYPT_ANY_SLOT,
+ *key_file, 
opt_keyfile_size,
+ opt_keyfile_offset, 
flags);
+if (r  0) {
+log_error(Failed to activate with key file '%s': %s, 
*key_file, strerror(-r));
+*key_file = NULL;
+return -EAGAIN;
+}
+} else {
+char **p;
+
+STRV_FOREACH(p, passwords) {
+if (pass_volume_key)
+r = crypt_activate_by_volume_key(cd, name, *p, 
opt_key_size, flags);
+else
+r = crypt_activate_by_passphrase(cd, name, 
CRYPT_ANY_SLOT, *p, strlen(*p), flags);
+
+if (r = 0)
+break;
+}
+}
+
+return r;
+}
+
 static int help(void) {
 
 printf(%s attach VOLUME SOURCEDEVICE [PASSWORD] [OPTIONS]\n
@@ -335,13 +437,11 @@ int main(int argc, char *argv[]) {
 if (streq(argv[1], attach)) {
 uint32_t flags = 0;
 int k;
-unsigned try;
+unsigned tries;
 usec_t until;
 crypt_status_info status;
-const char *key_file = NULL, *cipher = NULL, *cipher_mode = 
NULL,
-   *hash = NULL, *name 

[systemd-devel] [PATCH 3/3] cryptsetup: Add tcrypt support

2013-07-02 Thread Jan Janssen
Tcrypt uses a different approach to passphrases/key files. The
passphrase and all key files are incorpaorated into the password
to open the volume. So, the idea of slots that provide a way to
open the volume with different passphrases/key files that are
independent from each other like with LUKS does not apply.

Therefore, we use the key file from /etc/crypttab as the source
for the passphrase. If the passphrase of a volume is empty, using
/dev/null as key file is enough.

The actual key files that are combined with the passphrase into
a password are provided as a new option in /etc/crypttab and can
be given multiple times if more than one key file was used for a
volume.
---
 man/crypttab.xml| 300 +++-
 src/cryptsetup/cryptsetup.c |  81 +++-
 2 files changed, 259 insertions(+), 122 deletions(-)

diff --git a/man/crypttab.xml b/man/crypttab.xml
index 1063b46..386fa0d 100644
--- a/man/crypttab.xml
+++ b/man/crypttab.xml
@@ -75,23 +75,29 @@
 fields are mandatory, the remaining two are
 optional./para
 
+paraSetting up encrypted block devices using this file
+supports three encryption modes: LUKS, TrueCrypt and plain.
+See 
citerefentryrefentrytitlecryptsetup/refentrytitlemanvolnum8/manvolnum/citerefentry
+for more information about each mode. When no mode is specified
+in the options field and the block device contains a LUKS
+signature, it is opened as a LUKS device; otherwise it is
+assumed to be in raw dm-crypt (plain mode) format./para
+
 paraThe first field contains the name of the
 resulting encrypted block device; the device is set up
 within filename/dev/mapper//filename./para
 
 paraThe second field contains a path to the
-underlying block device, or a specification of a block
+underlying block device or file, or a specification of a block
 device via literalUUID=/literal followed by the
-UUID.  If the block device contains a LUKS signature,
-it is opened as a LUKS encrypted partition; otherwise
-it is assumed to be a raw dm-crypt partition./para
+UUID./para
 
 paraThe third field specifies the encryption
 password.  If the field is not present or the password
-is set to none, the password has to be manually
-entered during system boot.  Otherwise the field is
-interpreted as a path to a file containing the
-encryption password.  For swap encryption
+is set to none or literal-/literal, the password has
+to be manually entered during system boot.  Otherwise the
+field is interpreted as a absolute path to a file containing 
the
+encryption password. For swap encryption
 filename/dev/urandom/filename or the hardware
 device filename/dev/hw_random/filename can be used
 as the password file; using
@@ -104,181 +110,237 @@
 options are recognized:/para
 
 variablelist class='crypttab-options'
+
+varlistentry
+termvarnameallow-discards/varname/term
+
+listitemparaAllow discard requests to be
+passed through the encrypted block device. This
+improves performance on SSD storage but has
+security implications./para/listitem
+/varlistentry
+
 varlistentry
 termvarnamecipher=/varname/term
 
-listitemparaSpecifies the cipher
-to use; see
+listitemparaSpecifies the cipher to use. 
See
 
citerefentryrefentrytitlecryptsetup/refentrytitlemanvolnum8/manvolnum/citerefentry
-for possible values and the default
-value of this option.  A cipher with
-unpredictable IV values, such as
-literalaes-cbc-essiv:sha256/literal,
-is recommended. /para/listitem
+for possible values and the default value of
+this option. A cipher with unpredictable IV
+values, such as 
literalaes-cbc-essiv:sha256/literal,
+is recommended./para/listitem
 /varlistentry
 
-
 varlistentry
-

[systemd-devel] [PATCH] journal-verify: Use proper printf placeholder

2013-06-27 Thread Jan Janssen
---
 src/journal/journal-verify.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c
index 781b1ee..3405811 100644
--- a/src/journal/journal-verify.c
+++ b/src/journal/journal-verify.c
@@ -67,7 +67,7 @@ static int journal_file_object_verify(JournalFile *f, 
uint64_t offset, Object *o
 }
 
 if (le64toh(o-object.size) - offsetof(DataObject, payload) = 
0) {
-log_error(OFSfmt: bad object size (= %PRIu64): 
%PRIu64,
+log_error(OFSfmt: bad object size (= %zu): %PRIu64,
   offset,
   offsetof(DataObject, payload),
   le64toh(o-object.size));
@@ -120,7 +120,7 @@ static int journal_file_object_verify(JournalFile *f, 
uint64_t offset, Object *o
 
 case OBJECT_FIELD:
 if (le64toh(o-object.size) - offsetof(FieldObject, payload) 
= 0) {
-log_error(OFSfmt: bad field size (= %PRIu64): 
%PRIu64,
+log_error(OFSfmt: bad field size (= %zu): %PRIu64,
   offset,
   offsetof(FieldObject, payload),
   le64toh(o-object.size));
@@ -139,7 +139,7 @@ static int journal_file_object_verify(JournalFile *f, 
uint64_t offset, Object *o
 
 case OBJECT_ENTRY:
 if ((le64toh(o-object.size) - offsetof(EntryObject, items)) % 
sizeof(EntryItem) != 0) {
-log_error(OFSfmt: bad entry size (= %PRIu64): 
%PRIu64,
+log_error(OFSfmt: bad entry size (= %zu): %PRIu64,
   offset,
   offsetof(EntryObject, items),
   le64toh(o-object.size));
-- 
1.8.3.1

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


[systemd-devel] [PATCH] test: Add list testcase

2013-06-26 Thread Jan Janssen
---
 .gitignore   |   1 +
 Makefile.am  |  12 +-
 src/shared/list.h|   2 +-
 src/test/test-list.c | 109 +++
 4 files changed, 122 insertions(+), 2 deletions(-)
 create mode 100644 src/test/test-list.c

diff --git a/.gitignore b/.gitignore
index d1e2ae9..866d8eb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -116,6 +116,7 @@
 /test-journal-syslog
 /test-journal-verify
 /test-libudev
+/test-list
 /test-log
 /test-login
 /test-loopback
diff --git a/Makefile.am b/Makefile.am
index 016d7da..bfd09e4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1099,7 +1099,8 @@ tests += \
test-prioq \
test-fileio \
test-time \
-   test-hashmap
+   test-hashmap \
+   test-list
 
 EXTRA_DIST += \
test/sched_idle_bad.service \
@@ -1199,6 +1200,15 @@ test_hashmap_CFLAGS = \
 test_hashmap_LDADD = \
libsystemd-core.la
 
+test_list_SOURCES = \
+   src/test/test-list.c
+
+test_list_CFLAGS = \
+   $(AM_CFLAGS)
+
+test_list_LDADD = \
+   libsystemd-core.la
+
 test_prioq_SOURCES = \
src/test/test-prioq.c
 
diff --git a/src/shared/list.h b/src/shared/list.h
index 96d6237..4767574 100644
--- a/src/shared/list.h
+++ b/src/shared/list.h
@@ -81,7 +81,7 @@
 (head) = _item; \
 } while (false)
 
-/* Find the head of the list */
+/* Find the tail of the list */
 #define LIST_FIND_TAIL(t,name,item,tail)\
 do {\
 t *_item = (item);  \
diff --git a/src/test/test-list.c b/src/test/test-list.c
new file mode 100644
index 000..2710504
--- /dev/null
+++ b/src/test/test-list.c
@@ -0,0 +1,109 @@
+/***
+  This file is part of systemd
+
+  Copyright 2013 Jan Janssen
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see http://www.gnu.org/licenses/.
+***/
+
+#include list.h
+#include util.h
+
+int main(int argc, const char *argv[]) {
+size_t i;
+typedef struct list_item {
+LIST_FIELDS(struct list_item, item);
+} list_item;
+LIST_HEAD(list_item, head);
+list_item items[4];
+list_item *cursor;
+
+LIST_HEAD_INIT(list_item, head);
+assert_se(head == NULL);
+
+for (i = 0; i  ELEMENTSOF(items); i++) {
+LIST_INIT(list_item, item, items[i]);
+assert_se(LIST_JUST_US(item, items[i]));
+LIST_PREPEND(list_item, item, head, items[i]);
+}
+
+assert_se(!LIST_JUST_US(item, head));
+
+assert_se(items[0].item_next == NULL);
+assert_se(items[1].item_next == items[0]);
+assert_se(items[2].item_next == items[1]);
+assert_se(items[3].item_next == items[2]);
+
+assert_se(items[0].item_prev == items[1]);
+assert_se(items[1].item_prev == items[2]);
+assert_se(items[2].item_prev == items[3]);
+assert_se(items[3].item_prev == NULL);
+
+LIST_FIND_HEAD(list_item, item, items[0], cursor);
+assert_se(cursor == items[3]);
+
+LIST_FIND_TAIL(list_item, item, items[3], cursor);
+assert_se(cursor == items[0]);
+
+LIST_REMOVE(list_item, item, head, items[1]);
+assert_se(LIST_JUST_US(item, items[1]));
+
+assert_se(items[0].item_next == NULL);
+assert_se(items[2].item_next == items[0]);
+assert_se(items[3].item_next == items[2]);
+
+assert_se(items[0].item_prev == items[2]);
+assert_se(items[2].item_prev == items[3]);
+assert_se(items[3].item_prev == NULL);
+
+LIST_INSERT_AFTER(list_item, item, head, items[3], items[1]);
+assert_se(items[0].item_next == NULL);
+assert_se(items[2].item_next == items[0]);
+assert_se(items[1].item_next == items[2]);
+assert_se(items[3].item_next == items[1]);
+
+assert_se(items[0].item_prev == items[2]);
+assert_se(items[2].item_prev == items[1]);
+assert_se(items[1].item_prev == items[3]);
+assert_se(items[3].item_prev == NULL);
+
+LIST_REMOVE(list_item, item, head, items[0]);
+assert_se(LIST_JUST_US(item, items[0]));
+
+assert_se(items[2].item_next == NULL);
+assert_se(items[1].item_next == items[2]);
+assert_se(items[3].item_next == items

[systemd-devel] [PATCH] libudev: Use correct type for sizeof

2013-06-22 Thread Jan Janssen
---
 src/udev/udev-rules.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 7a4fb70..fe65e2d 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -1614,7 +1614,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int 
resolve_names)
 }
 strv_uniq(rules-dirs);
 
-rules-dirs_ts_usec = calloc(strv_length(rules-dirs), sizeof(long 
long));
+rules-dirs_ts_usec = calloc(strv_length(rules-dirs), sizeof(usec_t));
 if(!rules-dirs_ts_usec)
 return udev_rules_unref(rules);
 udev_rules_check_timestamp(rules);
-- 
1.8.3.1

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


Re: [systemd-devel] [PATCH v4] journalctl: Add support for showing messages from a previous boot

2013-06-15 Thread Jan Janssen

On 06/14/2013 10:43 PM, Zbigniew Jędrzejewski-Szmek wrote:

On Wed, Jun 12, 2013 at 02:41:15PM +0200, Jan Janssen wrote:

Unfortunately, to get a chronological list of boot IDs, we
need to search through the journal. sd_journal_enumerate_unique()
doesn't help us here, because the order of returned values
is undefined.

Hi Jan,

as an experiment, I tried to create the time-sorted list of boot
ids in python:

from pprint import pprint
from systemd import journal
j = journal.Reader()
matches={}
for id in j.query_unique('_BOOT_ID'):
j.add_match(_BOOT_ID=id.hex)
j.seek_head()
try:
ts = j.get_next()['__REALTIME_TIMESTAMP']
print(ts)
except OSError as e:
print(e)# [1]
else:
matches[ts] = id
j.flush_matches()

pprint(sorted(matches.items()))

This runs very fast on my machine... I have ~1GB of logs (cached in RAM),
and it runs .12s including Python load time. In fact python -c '' takes .04s,
so not an insubstantial chunk of the time for the whole query.

I think you might be overcomplicating the function to query boot
ids.

I like the idea. But sorting the boot IDs could order a few boots
wrongly, since realtime can jump backwards.

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


Re: [systemd-devel] [PATCH] udev hwdb: Store binary database in libdir, not in /etc

2013-06-14 Thread Jan Janssen

On 06/14/2013 01:08 PM, Tom Gundersen wrote:

That said, I don't think libdir is appropriate as this data is not
under the control of the package manager (as it is generated at
install-time rather than at build-time, it would for instance not be
suitable for sharing between hosts). I guess localstatedir would be
another alternative, but the problem there is that it is not
(necessarily) available during early boot when this db is needed.

One could introduce a /cache where such files could be stored. Similar
to how /run was introduced to fix a similar issue. The folder would
be required to be available at boot time.

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


[systemd-devel] Compile errors with -Og

2013-06-12 Thread Jan Janssen

Hi,

I just tried compiling with -Og and I get these compiler errors.
Those don't appear with any other optimization level, so I'm
suspecting a compiler but here. But since I'm no C expert, I thought
it would be best if I share this here to see if I'm right about this
or whether this just shows some subtle bug in the code.

This is on a up-to-date arch box (gcc 4.8.1) and make clean
run before trying to compile.

Jan

---
  CC   src/shared/util.lo
src/shared/util.c: In function 'safe_atod':
src/shared/util.c:383:16: warning: 'd' may be used uninitialized in this 
function [-Wmaybe-uninitialized]

 *ret_d = (double) d;
^
In file included from /usr/include/fcntl.h:296:0,
 from src/shared/util.c:35:
In function 'open',
inlined from 'open_terminal' at src/shared/util.c:1834:20:
/usr/include/bits/fcntl2.h:50:24: error: call to '__open_missing_mode' 
declared with attribute error: open with O_CREAT in second argument 
needs 3 arguments

__open_missing_mode ();
^
In file included from /usr/include/fcntl.h:296:0,
 from src/shared/util.c:35:
In function 'openat',
inlined from 'xopendirat' at src/shared/util.c:3478:13:
/usr/include/bits/fcntl2.h:126:26: error: call to 
'__openat_missing_mode' declared with attribute error: openat with 
O_CREAT in third argument needs 4 arguments

__openat_missing_mode ();
  ^
src/shared/util.c: In function 'create_tmp_dir':
src/shared/util.c:5718:12: warning: 'd' may be used uninitialized in 
this function [-Wmaybe-uninitialized]

 dt = strjoin(d, /tmp, NULL);
^
make[2]: *** [src/shared/util.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] gitignore: Add test-journal-interleaving

2013-06-12 Thread Jan Janssen
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 7534ac1..d1e2ae9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -109,6 +109,7 @@
 /test-job-type
 /test-journal
 /test-journal-enum
+/test-journal-interleaving
 /test-journal-match
 /test-journal-send
 /test-journal-stream
-- 
1.8.3.1

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


[systemd-devel] [PATCH v4] journalctl: Add support for showing messages from a previous boot

2013-06-12 Thread Jan Janssen
Unfortunately, to get a chronological list of boot IDs, we
need to search through the journal. sd_journal_enumerate_unique()
doesn't help us here, because the order of returned values
is undefined.

An initial search for the reference boot ID is performed. We then
start a search filtering by SD_MESSAGE_JOURNAL_START. This
message ID should come up in every journal and is therefore a good
start to reduce the amount of messages the lookup process has to
walk through to find the previous/next boot IDs.

Note that this or any other message ID could get rotated away,
so lookup is not guaranteed to be precise. This should only affect
old (and uninteresting) journal entries, though.
---
Changes in v4:
  - search for the nth boot starting from the beginning of the
journal if only :n with positive n is provided
  - further improvemed wording in the man page

Changes in v3:
  - do filter by MESSAGE_ID and simply declare the cases where we
skip boot IDs not a problem
  - --this-boot not documented anymore
  - usage of : instead of ^ to define relative IDs
  - improved wording in the man page
  - indentation fixes

Changes in v2:
  - prevent unnecessary strdup by changing the argv value in place
  - speed up the lookup by doing an initial search for the boot ID

 TODO |   1 -
 man/journalctl.xml   |  54 ---
 shell-completion/bash/journalctl |  11 ++-
 src/journal/journalctl.c | 205 ---
 4 files changed, 244 insertions(+), 27 deletions(-)

diff --git a/TODO b/TODO
index df3725f..95580ad 100644
--- a/TODO
+++ b/TODO
@@ -274,7 +274,6 @@ Features:
   - journal-send.c, log.c: when the log socket is clogged, and we drop, count 
this and write a message about this when it gets unclogged again.
   - journal: find a way to allow dropping history early, based on priority, 
other rules
   - journal: When used on NFS, check payload hashes
-  - Introduce journalctl -b nr to show journal messages of a previous boot
   - journald: check whether it is OK if the client can still modify delivered 
journal entries
   - journal live copy, based on libneon (client) and libmicrohttpd (server)
   - journald: add kernel cmdline option to disable ratelimiting for debug 
purposes
diff --git a/man/journalctl.xml b/man/journalctl.xml
index f399868..a8af46f 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -312,23 +312,51 @@
 /varlistentry
 
 varlistentry
-termoption-b/option/term
-termoption--this-boot/option/term
-
-listitemparaShow data only from
-current boot. This will add a match
-for literal_BOOT_ID=/literal for
-the current boot ID of the
-kernel./para/listitem
+termoption-b 
optionalreplaceableID/replaceable/optional/option/term
+
termoption--boot=optionalreplaceableID/replaceable/optional/option/term
+
+listitemparaShow messages from the 
specified
+boot replaceableID/replaceable or from
+current boot if no 
replaceableID/replaceable
+is given. This will add a match for
+literal_BOOT_ID=/literal./para
+
+paraThe argument is a 128 bit ID given in
+short or UUID form and optionally followed by
+literal:n/literal which identifies the nth
+boot relative to the boot ID given to the left
+of literal:/literal. Supplying a negative
+value for n will look for a past boot and a
+positive value for a future boot. The boot IDs
+are searched for in chronological order. If no
+number is provided after literal:/literal,
+literal-1/literal is assumed. A value of 0
+is valid and equivalent to omitting
+literal:0/literal./para
+
+paraAlternatively, the argument may constist
+only of literal:n/literal. In this case, a
+positive value will look up the nth boot
+starting from the beginning of the jouranl. A
+negative value will look up a previous boot
+starting from the current boot. 
literal:0/literal
+will look for the current boot ID. Thus,
+  

[systemd-devel] [PATCH v3] journalctl: Add support for showing messages from a previous boot

2013-06-05 Thread Jan Janssen
Unfortunately, to get a chronological list of boot IDs, we
need to search through the journal. sd_journal_enumerate_unique()
doesn't help us here, because order of returned values is undefined.

An initial search for the reference boot ID is performed. We then
start a search filtering by SD_MESSAGE_JOURNAL_START. This
message ID should come up in every journal and is therefore a good
start to reduce the amount of messages the lookup process has to
walk through to find the previous/next boot IDs.

Note that this or any other message ID could get rotated away,
so lookup is not guaranteed to be precise. This should only affect
old (and uninteresting) journal entries, though.
---
Changes in v3:
  - do filter by MESSAGE_ID and simply declare the cases where we
skip boot IDs not a problem
  - --this-boot not documented anymore
  - usage of : instead of ^ to define relative IDs
  - improved wording in the man page
  - indentation fixes

Changes in v2:
  - prevent unnecessary strdup by changing the argv value in place
  - speed up the lookup by doing an initial search for the boot ID

 TODO |   1 -
 man/journalctl.xml   |  58 +---
 shell-completion/bash/journalctl |   8 +-
 src/journal/journalctl.c | 186 ---
 4 files changed, 228 insertions(+), 25 deletions(-)

diff --git a/TODO b/TODO
index ecc5748..2b2aafc 100644
--- a/TODO
+++ b/TODO
@@ -259,7 +259,6 @@ Features:
   - journal-send.c, log.c: when the log socket is clogged, and we drop, count 
this and write a message about this when it gets unclogged again.
   - journal: find a way to allow dropping history early, based on priority, 
other rules
   - journal: When used on NFS, check payload hashes
-  - Introduce journalctl -b nr to show journal messages of a previous boot
   - journald: check whether it is OK if the client can still modify delivered 
journal entries
   - journal live copy, based on libneon (client) and libmicrohttpd (server)
   - journald: add kernel cmdline option to disable ratelimiting for debug 
purposes
diff --git a/man/journalctl.xml b/man/journalctl.xml
index d9ca0a6..6cbeb22 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -312,23 +312,55 @@
 /varlistentry
 
 varlistentry
-termoption-b/option/term
-termoption--this-boot/option/term
-
-listitemparaShow data only from
-current boot. This will add a match
-for literal_BOOT_ID=/literal for
-the current boot ID of the
-kernel./para/listitem
+termoption-b 
optionalreplaceableID/replaceable/optional/option/term
+
termoption--boot=optionalreplaceableID/replaceable/optional/option/term
+
+listitemparaShow messages from specified
+boot replaceableID/replaceable. This will
+add a match for 
literal_BOOT_ID=/literal./para
+
+paraThe argument is a 128 bit ID given in
+short or UUID form and optionally followed by
+literal:n/literal which identifies the nth
+boot relative to the boot ID given to the left
+of literal:/literal. Supplying a negative
+value will look for a past boot and a positive
+value for a future boot. The boot IDs are
+searched for in chronological order./para
+
+paraIf no number is provided after
+literal:/literal, literal-1/literal is
+assumed. A value of 0 is valid and equivalent 
to
+omitting literal:0/literal. The boot ID may
+be omitted if literal:/literal is provided,
+which will assume the current boot ID as the
+reference./para
+
+paraFor example, if 
literal962e0810b0c44735a6a70e7132996502/literal
+were the ID of the current boot, the following
+are all equivalent:
+
option962e0810b0c44735a6a70e7132996502/option,
+
option962e0810-b0c4-4735-a6a7-0e7132996502/option,
+option:0/option,
+
option962e0810b0c44735a6a70e7132996502:0/option,
+
option962e0810-b0c4-4735-a6a7-0e7132996502:0/option.
+

Re: [systemd-devel] [PATCH v2] journalctl: Add support for showing messages from a previous boot

2013-06-04 Thread Jan Janssen

Sorry, I failed to hit Reply-All.

On 06/04/2013 07:10 PM, Lennart Poettering wrote:

On Tue, 04.06.13 18:47, Jan Janssen (medhe...@web.de) wrote:



On 06/04/2013 04:42 PM, Lennart Poettering wrote:

On Thu, 30.05.13 17:24, Jan Janssen (medhe...@web.de) wrote:

I like this idea!


The format to specify the boot ID is inspired by git's ^n syntax
and it even allows to look into the future.

Unfortunately, to get a chronological list of boot IDs, we
need search through the journal. sd_journal_enumerate_unique()
doesn't help us here, because order of returned values is undefined.

To make things less painful, an initial search for the reference
boot ID is performed, which will either quickly fail so we don't have
to needlessly walk the full journal or give us a cursor from which
to start the slow lookup process.


Hmm, I think this should be implemented differently: we should define a
new message with a fixed message ID which is ussed once during boot,
which we then can search for. We already have
SD_MESSAGE_STARTUP_FINISHED which kinda does that, but is generated only
after startup finished. For this feature we should have a message that
is generated as early as possible in the boot process as possible
(i.e. right after the journal is up), and from PID1, and only once
during boot. We'd then simply search for this message ID in the
database, and this would return a nicely ordered list of boots. We then
pick the one we want and use it in an entirely new query.

This would work, but only if this message won't rotate away.
Otherwise results would be unexpected to users. Although, now that I
think about it, I guess I could look into ensuring that...


Hmm, looking for startup messages plus an extra check for the boot ID of
the oldest entry in all journals should give you a full list.

Any journal file could contain messages from more than one boot. And
if you have a (user) journal file with two or more boot IDs from boots
that are not in the list obtained by message ID, you'd miss some boot
IDs. Or I just don't grok your approach.


I am not sure I really like the ^ syntax. This after all is different

from git, as the ^ would works strictly by time, there is no real

ancestral information. (or in other words: the result of ^ differs
when you use different filters...).

Actually, the final boot ID result doesn't change even if you
provide other filters. The lookup is done before all user defined
filters are added.


Yeah, but that's not what I meant. I meant that on the conceptional
level in git the ^ actually indicates an ancestral relation, but this
--boot= stuff would give you different results if you would apply a
filter, or there are missing journal files and so on. it would simply
return the newest boot id that is before the specified id
_which_is_in_the_current_dataset_. If you follow what I mean...

Now I see what you mean. I'll try some other/better phrasing for docs.


Maybe we can use a different syntax? Something like --boot=-5 or
--boot=bd1b92058dd24e1eab573808e114f18b-5 or so?

If there is consent on one. Hyphen is rather sub-optimal. It clashes
with boot IDs given in UUIDs form
(6bf79b04-3e50-4336-94ff-4ccf1083a005). It's supported, though not
explicitly stated.


Indeed, - sucks. Hmm, not sure what we could use instead. I'd like a
syntax that is sufficiently different from git's so that people don't
make the wrong assumption, but something that is still easy to type...

Maybe use bd1b92058dd24e1eab573808e114f18b:-5 and
bd1b92058dd24e1eab573808e114f18b:+5 or so?

degree should probably be an unsigned rather than an int. We try to
use types that indicate the sensible range of the variable, and a
negative value here doesn't appear to make sense, so please use unsigned.

A negative value does make sense. It allows to see into the future.
To try it, just look for a past boot ID and look up the following
boot by
appending ^-1. Trying it on the current boot will fail for obvious
reasons.


Oh, true. Sorry for my confusion...

Lennart



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


[systemd-devel] [PATCH v2] journalctl: Add support for showing messages from a previous boot

2013-05-30 Thread Jan Janssen
The format to specify the boot ID is inspired by git's ^n syntax
and it even allows to look into the future.

Unfortunately, to get a chronological list of boot IDs, we
need search through the journal. sd_journal_enumerate_unique()
doesn't help us here, because order of returned values is undefined.

To make things less painful, an initial search for the reference
boot ID is performed, which will either quickly fail so we don't have
to needlessly walk the full journal or give us a cursor from which
to start the slow lookup process.
The lookup process itself has to walk all entries because we can't
just single out some MESSAGE_ID that could get rotated away. But
that shouldn't be a problem for the most common use case of
just going back/forth a few boot IDs.
---
Changes in v2:
  - prevent unnecessary strdup by changing the argv value in place
  - speed up the lookup by doing an initial search for the boot ID

 TODO |   1 -
 man/journalctl.xml   |  34 +---
 shell-completion/bash/journalctl |   8 +-
 src/journal/journalctl.c | 164 +++
 4 files changed, 179 insertions(+), 28 deletions(-)

diff --git a/TODO b/TODO
index f8a1b1b..7dd9376 100644
--- a/TODO
+++ b/TODO
@@ -267,7 +267,6 @@ Features:
   - journal-send.c, log.c: when the log socket is clogged, and we drop, count 
this and write a message about this when it gets unclogged again.
   - journal: find a way to allow dropping history early, based on priority, 
other rules
   - journal: When used on NFS, check payload hashes
-  - Introduce journalctl -b nr to show journal messages of a previous boot
   - journald: check whether it is OK if the client can still modify delivered 
journal entries
   - journal live copy, based on libneon (client) and libmicrohttpd (server)
   - journald: add kernel cmdline option to disable ratelimiting for debug 
purposes
diff --git a/man/journalctl.xml b/man/journalctl.xml
index d9ca0a6..1690e00 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -312,23 +312,33 @@
 /varlistentry
 
 varlistentry
-termoption-b/option/term
-termoption--this-boot/option/term
+termoption-b 
optionalreplaceableID/replaceable/optional/option/term
+
termoption--boot=optionalreplaceableID/replaceable/optional/option/term
+
termoption--this-boot=optionalreplaceableID/replaceable/optional/option/term
 
-listitemparaShow data only from
-current boot. This will add a match
-for literal_BOOT_ID=/literal for
-the current boot ID of the
-kernel./para/listitem
+listitemparaShow messages from specified
+boot replaceableID/replaceable. This will
+add a match for 
literal_BOOT_ID=/literal./para
+
+paraThe argument is a 128 bit ID
+optionally followed by the ancestry identifier
+literal^n/literal, which identifies the
+chronologically nth previous boot ID. Supplying
+a negative value will look for the 
chronologically
+next boot ID. literaln/literal may be 
ommitted,
+in which case 1 is assumed. A value of 0 is
+equivalent to the current boot ID. If the 
ancestry
+indentifier is supplied, the boot ID itself 
may be
+ommited and the current boot is 
assumed./para/listitem
 /varlistentry
 
 varlistentry
 termoption-k/option/term
 termoption--dmesg/option/term
 
-listitemparaShow kernel messages from
-current boot. This implies option-b/option
-and adds the match 
literal_TRANSPORT=kernel/literal.
+listitemparaShow only kernel messages. This
+implies option-b/option and adds the match
+literal_TRANSPORT=kernel/literal.
 /para/listitem
 /varlistentry
 
@@ -666,6 +676,10 @@
 
 programlistingjournalctl /dev/sda/programlisting
 
+paraShow all kernel logs from last boot:/para
+
+programlistingjournalctl -k -b ^/programlisting
+
 /refsect1
 
 refsect1
diff --git 

[systemd-devel] [PATCH] journalctl: Add support for showing messages from a previous boot

2013-05-29 Thread Jan Janssen
The format to specify the boot ID is inspired by git's ^n syntax
and it even allows to look into the future.

Unfortuneately, to get a chronological list of boot IDs, we
need to first iterate over all journal entries.
sd_journal_enumerate_unique() doesn't help us here, because order
of returned values is undefined.
But it shouldn't be a problem for the most common use case of
just going back to the previous or last few boots. Looking up future
boot IDs is painfully slow if the journal is big, though.
---
 TODO |   1 -
 man/journalctl.xml   |  34 +++---
 shell-completion/bash/journalctl |   8 ++-
 src/journal/journalctl.c | 143 +++
 4 files changed, 158 insertions(+), 28 deletions(-)

diff --git a/TODO b/TODO
index f8a1b1b..7dd9376 100644
--- a/TODO
+++ b/TODO
@@ -267,7 +267,6 @@ Features:
   - journal-send.c, log.c: when the log socket is clogged, and we drop, count 
this and write a message about this when it gets unclogged again.
   - journal: find a way to allow dropping history early, based on priority, 
other rules
   - journal: When used on NFS, check payload hashes
-  - Introduce journalctl -b nr to show journal messages of a previous boot
   - journald: check whether it is OK if the client can still modify delivered 
journal entries
   - journal live copy, based on libneon (client) and libmicrohttpd (server)
   - journald: add kernel cmdline option to disable ratelimiting for debug 
purposes
diff --git a/man/journalctl.xml b/man/journalctl.xml
index d9ca0a6..1690e00 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -312,23 +312,33 @@
 /varlistentry
 
 varlistentry
-termoption-b/option/term
-termoption--this-boot/option/term
+termoption-b 
optionalreplaceableID/replaceable/optional/option/term
+
termoption--boot=optionalreplaceableID/replaceable/optional/option/term
+
termoption--this-boot=optionalreplaceableID/replaceable/optional/option/term
 
-listitemparaShow data only from
-current boot. This will add a match
-for literal_BOOT_ID=/literal for
-the current boot ID of the
-kernel./para/listitem
+listitemparaShow messages from specified
+boot replaceableID/replaceable. This will
+add a match for 
literal_BOOT_ID=/literal./para
+
+paraThe argument is a 128 bit ID
+optionally followed by the ancestry identifier
+literal^n/literal, which identifies the
+chronologically nth previous boot ID. Supplying
+a negative value will look for the 
chronologically
+next boot ID. literaln/literal may be 
ommitted,
+in which case 1 is assumed. A value of 0 is
+equivalent to the current boot ID. If the 
ancestry
+indentifier is supplied, the boot ID itself 
may be
+ommited and the current boot is 
assumed./para/listitem
 /varlistentry
 
 varlistentry
 termoption-k/option/term
 termoption--dmesg/option/term
 
-listitemparaShow kernel messages from
-current boot. This implies option-b/option
-and adds the match 
literal_TRANSPORT=kernel/literal.
+listitemparaShow only kernel messages. This
+implies option-b/option and adds the match
+literal_TRANSPORT=kernel/literal.
 /para/listitem
 /varlistentry
 
@@ -666,6 +676,10 @@
 
 programlistingjournalctl /dev/sda/programlisting
 
+paraShow all kernel logs from last boot:/para
+
+programlistingjournalctl -k -b ^/programlisting
+
 /refsect1
 
 refsect1
diff --git a/shell-completion/bash/journalctl b/shell-completion/bash/journalctl
index 19362ae..2c6ced9 100644
--- a/shell-completion/bash/journalctl
+++ b/shell-completion/bash/journalctl
@@ -38,17 +38,21 @@ _journalctl() {
 local field_vals= cur=${COMP_WORDS[COMP_CWORD]} 
prev=${COMP_WORDS[COMP_CWORD-1]}
 local -A OPTS=(
 [STANDALONE]='-a --all --full
-  -b --this-boot --disk-usage -f 

[systemd-devel] [PATCH 1/2] Fix --no-ask-password

2013-05-17 Thread Jan Janssen
---
 src/hostname/hostnamectl.c |  6 +++---
 src/locale/localectl.c | 12 
 src/timedate/timedatectl.c | 14 +-
 3 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index 064581a..7c45ce5 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -219,7 +219,7 @@ static int show_status(DBusConnection *bus, char **args, 
unsigned n) {
 
 static int set_hostname(DBusConnection *bus, char **args, unsigned n) {
 _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-dbus_bool_t interactive = true;
+dbus_bool_t interactive = arg_ask_password;
 _cleanup_free_ char *h = NULL;
 const char *hostname = args[1];
 int r;
@@ -311,7 +311,7 @@ static int set_hostname(DBusConnection *bus, char **args, 
unsigned n) {
 
 static int set_icon_name(DBusConnection *bus, char **args, unsigned n) {
 _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-dbus_bool_t interactive = true;
+dbus_bool_t interactive = arg_ask_password;
 
 assert(args);
 assert(n == 2);
@@ -333,7 +333,7 @@ static int set_icon_name(DBusConnection *bus, char **args, 
unsigned n) {
 
 static int set_chassis(DBusConnection *bus, char **args, unsigned n) {
 _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-dbus_bool_t interactive = true;
+dbus_bool_t interactive = arg_ask_password;
 
 assert(args);
 assert(n == 2);
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 50250c4..422ac2c 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -223,7 +223,7 @@ static int show_status(DBusConnection *bus, char **args, 
unsigned n) {
 
 static int set_locale(DBusConnection *bus, char **args, unsigned n) {
 _cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL;
-dbus_bool_t interactive = true;
+dbus_bool_t interactive = arg_ask_password;
 DBusError error;
 DBusMessageIter iter;
 int r;
@@ -459,7 +459,7 @@ static int list_locales(DBusConnection *bus, char **args, 
unsigned n) {
 
 static int set_vconsole_keymap(DBusConnection *bus, char **args, unsigned n) {
 _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-dbus_bool_t interactive = true, b;
+dbus_bool_t interactive = arg_ask_password, b;
 const char *map, *toggle_map;
 
 assert(bus);
@@ -565,7 +565,7 @@ static int list_vconsole_keymaps(DBusConnection *bus, char 
**args, unsigned n) {
 
 static int set_x11_keymap(DBusConnection *bus, char **args, unsigned n) {
 _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-dbus_bool_t interactive = true, b;
+dbus_bool_t interactive = arg_ask_password, b;
 const char *layout, *model, *variant, *options;
 
 assert(bus);
@@ -757,7 +757,7 @@ static int parse_argv(int argc, char *argv[]) {
 assert(argc = 0);
 assert(argv);
 
-while ((c = getopt_long(argc, argv, has:H:P, options, NULL)) = 0) {
+while ((c = getopt_long(argc, argv, hH:P, options, NULL)) = 0) {
 
 switch (c) {
 
@@ -787,6 +787,10 @@ static int parse_argv(int argc, char *argv[]) {
 arg_no_pager = true;
 break;
 
+case ARG_NO_ASK_PASSWORD:
+arg_ask_password = false;
+break;
+
 case '?':
 return -EINVAL;
 
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 8d4e560..37e0a4f 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -304,7 +304,7 @@ static int show_status(DBusConnection *bus, char **args, 
unsigned n) {
 
 static int set_time(DBusConnection *bus, char **args, unsigned n) {
 _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-dbus_bool_t relative = false, interactive = true;
+dbus_bool_t relative = false, interactive = arg_ask_password;
 usec_t t;
 dbus_int64_t u;
 int r;
@@ -338,7 +338,7 @@ static int set_time(DBusConnection *bus, char **args, 
unsigned n) {
 
 static int set_timezone(DBusConnection *bus, char **args, unsigned n) {
 _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-dbus_bool_t interactive = true;
+dbus_bool_t interactive = arg_ask_password;
 
 assert(args);
 assert(n == 2);
@@ -360,7 +360,7 @@ static int set_timezone(DBusConnection *bus, char **args, 
unsigned n) {
 
 static int set_local_rtc(DBusConnection *bus, char **args, unsigned n) {
 _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-dbus_bool_t interactive = true, b, q;
+dbus_bool_t interactive = arg_ask_password, b, q;
 int r;
 
 assert(args);
@@ -393,7 +393,7 @@ static int set_local_rtc(DBusConnection *bus, char **args, 
unsigned 

[systemd-devel] [PATCH 2/2] man: Document missing options

2013-05-17 Thread Jan Janssen
---
 man/hostnamectl.xml|  8 
 man/journalctl.xml | 10 ++
 man/localectl.xml  |  8 
 man/timedatectl.xml|  8 
 src/hostname/hostnamectl.c |  1 +
 src/journal/coredumpctl.c  |  1 +
 src/locale/localectl.c |  1 +
 src/timedate/timedatectl.c |  1 +
 8 files changed, 38 insertions(+)

diff --git a/man/hostnamectl.xml b/man/hostnamectl.xml
index 9efe220..801ab3a 100644
--- a/man/hostnamectl.xml
+++ b/man/hostnamectl.xml
@@ -116,6 +116,14 @@
 /varlistentry
 
 varlistentry
+termoption-P/option/term
+termoption--privileged/option/term
+
+listitemparaAcquire privileges via 
PolicyKit
+before executing the 
operation./para/listitem
+/varlistentry
+
+varlistentry
 termoption-H/option/term
 termoption--host/option/term
 
diff --git a/man/journalctl.xml b/man/journalctl.xml
index cc7d1a0..d9ca0a6 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -323,6 +323,16 @@
 /varlistentry
 
 varlistentry
+termoption-k/option/term
+termoption--dmesg/option/term
+
+listitemparaShow kernel messages from
+current boot. This implies option-b/option
+and adds the match 
literal_TRANSPORT=kernel/literal.
+/para/listitem
+/varlistentry
+
+varlistentry
 termoption-u/option/term
 termoption--unit=/option/term
 
diff --git a/man/localectl.xml b/man/localectl.xml
index 0b13c11..febdeec 100644
--- a/man/localectl.xml
+++ b/man/localectl.xml
@@ -109,6 +109,14 @@
 /varlistentry
 
 varlistentry
+termoption-P/option/term
+termoption--privileged/option/term
+
+listitemparaAcquire privileges via 
PolicyKit
+before executing the 
operation./para/listitem
+/varlistentry
+
+varlistentry
 termoption-H/option/term
 termoption--host/option/term
 
diff --git a/man/timedatectl.xml b/man/timedatectl.xml
index faccc50..e291f04 100644
--- a/man/timedatectl.xml
+++ b/man/timedatectl.xml
@@ -98,6 +98,14 @@
 /varlistentry
 
 varlistentry
+termoption-P/option/term
+termoption--privileged/option/term
+
+listitemparaAcquire privileges via 
PolicyKit
+before executing the 
operation./para/listitem
+/varlistentry
+
+varlistentry
 termoption-H/option/term
 termoption--host/option/term
 
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index 7c45ce5..d108a24 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -362,6 +362,7 @@ static int help(void) {
 --transient Only set transient hostname\n
 --staticOnly set static hostname\n
 --prettyOnly set pretty hostname\n
+ -P --privilegedAcquire privileges before execution\n
 --no-ask-password   Do not prompt for password\n
  -H --host=[USER@]HOST  Operate on remote host\n\n
Commands:\n
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index 5652c2f..e1bd862 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -84,6 +84,7 @@ static int help(void) {
Flags:\n
  -o --output=FILE  Write output to FILE\n
 --no-pager Do not pipe output into a pager\n
+--no-legendDo not print the column headers.\n\n
 
Commands:\n
  -h --help Show this help\n
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 422ac2c..b5cd344 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -712,6 +712,7 @@ static int help(void) {
 --version Show package version\n
 --no-convert  Don't convert keyboard mappings\n
 --no-pagerDo not pipe output into a pager\n
+ -P --privileged  Acquire 

[systemd-devel] [PATCH 2/3] man: Unify title for configuration files

2013-03-07 Thread Jan Janssen
---
 man/hostname.xml   | 2 +-
 man/localtime.xml  | 2 +-
 man/machine-id.xml | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/man/hostname.xml b/man/hostname.xml
index 84a2961..f89332e 100644
--- a/man/hostname.xml
+++ b/man/hostname.xml
@@ -24,7 +24,7 @@
 
 refentry id=hostname
 refentryinfo
-title/etc/hostname/title
+titlehostname/title
 productnamesystemd/productname
 
 authorgroup
diff --git a/man/localtime.xml b/man/localtime.xml
index 88c84a3..d3da4ed 100644
--- a/man/localtime.xml
+++ b/man/localtime.xml
@@ -25,7 +25,7 @@
 
 refentry id=localtime
 refentryinfo
-title/etc/localtime/title
+titlelocaltime/title
 productnamesystemd/productname
 
 authorgroup
diff --git a/man/machine-id.xml b/man/machine-id.xml
index 7d424b7..153ae4d 100644
--- a/man/machine-id.xml
+++ b/man/machine-id.xml
@@ -24,7 +24,7 @@
 
 refentry id=machine-id
 refentryinfo
-title/etc/machine-id/title
+titlemachine-id/title
 productnamesystemd/productname
 
 authorgroup
-- 
1.8.1.5

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


[systemd-devel] [PATCH 1/3] man: Fix id attributes

2013-03-07 Thread Jan Janssen
---
 man/sd-readahead.xml | 2 +-
 man/sd_readahead.xml | 2 +-
 man/systemd-activate.xml | 2 +-
 man/systemd-update-utmp-runlevel.service.xml | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/man/sd-readahead.xml b/man/sd-readahead.xml
index ee7c936..f8a0a0b 100644
--- a/man/sd-readahead.xml
+++ b/man/sd-readahead.xml
@@ -21,7 +21,7 @@
   along with systemd; If not, see http://www.gnu.org/licenses/.
 --
 
-refentry id=sd-daemon conditional='ENABLE_READAHEAD'
+refentry id=sd-readahead conditional='ENABLE_READAHEAD'
 
 refentryinfo
 titlesd-readahead/title
diff --git a/man/sd_readahead.xml b/man/sd_readahead.xml
index 39e3469..c26d5c6 100644
--- a/man/sd_readahead.xml
+++ b/man/sd_readahead.xml
@@ -21,7 +21,7 @@
   along with systemd; If not, see http://www.gnu.org/licenses/.
 --
 
-refentry id=sd_notify conditional='ENABLE_READAHEAD'
+refentry id=sd_readahead conditional='ENABLE_READAHEAD'
 
 refentryinfo
 titlesd_readahead/title
diff --git a/man/systemd-activate.xml b/man/systemd-activate.xml
index 6949731..a5cab8e 100644
--- a/man/systemd-activate.xml
+++ b/man/systemd-activate.xml
@@ -21,7 +21,7 @@ You should have received a copy of the GNU Lesser General 
Public License
 along with systemd; If not, see http://www.gnu.org/licenses/.
 --
 
-refentry id=systemd-journal-gatewayd.service
+refentry id=systemd-activate
 
   refentryinfo
 titlesystemd-activate/title
diff --git a/man/systemd-update-utmp-runlevel.service.xml 
b/man/systemd-update-utmp-runlevel.service.xml
index 0e19581..867b958 100644
--- a/man/systemd-update-utmp-runlevel.service.xml
+++ b/man/systemd-update-utmp-runlevel.service.xml
@@ -19,7 +19,7 @@
   You should have received a copy of the GNU Lesser General Public License
   along with systemd; If not, see http://www.gnu.org/licenses/.
 --
-refentry id=systemd-user-sessions.service
+refentry id=systemd-update-utmp-runlevel.service
 
 refentryinfo
 titlesystemd-update-utmp-runlevel.service/title
-- 
1.8.1.5

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


[systemd-devel] [PATCH 3/3] util: Fix grammar in comment

2013-03-07 Thread Jan Janssen
---
 src/shared/util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/shared/util.c b/src/shared/util.c
index b7ba7fb..c493a34 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3607,8 +3607,8 @@ void execute_directory(const char *directory, DIR *d, 
char *argv[]) {
 
 assert(directory);
 
-/* Executes all binaries in a directory in parallel and waits
- * until all they all finished. */
+/* Executes all binaries in a directory in parallel and
+ * waits for them to finish. */
 
 if (!d) {
 if (!(_d = opendir(directory))) {
-- 
1.8.1.5

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


[systemd-devel] [PATCH] systemctl: Don't give re-activation warning if unit is masked

2013-02-15 Thread Jan Janssen
---
 src/systemctl/systemctl.c | 39 ++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 4c91a18..0ff3e0a 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -1319,7 +1319,9 @@ static void check_triggering_units(
 _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
 DBusMessageIter iter, sub;
 const char *interface = org.freedesktop.systemd1.Unit,
-   *triggered_by_property = TriggeredBy;
+   *load_state_property = LoadState,
+   *triggered_by_property = TriggeredBy,
+   *state;
 char _cleanup_free_ *unit_path = NULL, *n = NULL;
 bool print_warning_label = true;
 int r;
@@ -1345,6 +1347,41 @@ static void check_triggering_units(
 reply,
 NULL,
 DBUS_TYPE_STRING, interface,
+DBUS_TYPE_STRING, load_state_property,
+DBUS_TYPE_INVALID);
+if (r  0)
+return;
+
+if (!dbus_message_iter_init(reply, iter) ||
+dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT) {
+log_error(Failed to parse reply.);
+return;
+}
+
+dbus_message_iter_recurse(iter, sub);
+
+if (dbus_message_iter_get_arg_type(sub) != DBUS_TYPE_STRING)  {
+log_error(Failed to parse reply.);
+return;
+}
+
+dbus_message_iter_get_basic(sub, state);
+
+if (streq(state, masked))
+return;
+
+dbus_message_unref(reply);
+reply = NULL;
+
+r = bus_method_call_with_reply(
+bus,
+org.freedesktop.systemd1,
+unit_path,
+org.freedesktop.DBus.Properties,
+Get,
+reply,
+NULL,
+DBUS_TYPE_STRING, interface,
 DBUS_TYPE_STRING, triggered_by_property,
 DBUS_TYPE_INVALID);
 if (r  0)
-- 
1.8.1.3

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


Re: [systemd-devel] Calendar timer events on non-24/7 systems

2013-02-06 Thread Jan Janssen
On Wednesday 06 February 2013 13:14:00 Kay Sievers wrote:
 This will all be implemented in the future, and work a bit like
 anacron, it just isn't done yet.
 
 Kay

Thanks. It's nice to know that it's intended to be implemented in the future.

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


[systemd-devel] Calendar timer events on non-24/7 systems

2013-02-05 Thread Jan Janssen
Hello,

I was wondering how (calendar) timer events triggering occurs on systems that 
aren't running 24/7 (e.g. a typical desktop system). To do that I used these 
two simple units:

[Unit]
Description=Calendar Test Service
[Service]
Type=oneshot
ExecStart=/usr/bin/systemd-cat -t calendar-test date

[Unit]
Description=Daily Timer Test
[Timer]
OnCalendar=daily
Unit=calendar-test.service

And as I expected, the service isn't started on a daily basis on my computer  
since (calendar based) timers don't remember the last time they got activated 
after a fresh boot.

It would be nice if timers got scheduled based on their last time they got 
triggered. Best would be an option to toggle it per unit.

The main reason I was thinking about it was, that all /etc/cron.
{hourly,daily,weekly,monthly}/* scripts that are shipped by distros these days 
should actually be implemented as native timer units (by today's standards, 
they have no good reason to be shipped there anyways other than for legacy 
reasons). But those need a reliable way to make sure that they are actually 
run daily/weekly/monthly, even if the system reboots. Just like anacron does 
in some distros.

I wonder if this has been a deliberate decision or just been oversight. And if 
it's the latter, wether there are any plans to make reliable timer units 
across reboots possible,

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