[systemd-devel] [PATCH] systemctl: add commands set-default and get-default

2013-05-28 Thread Vaclav Pavlin
From: Václav Pavlín vpav...@redhat.com

systemctl set-default NAME links the default.target to the given unit,
get-default prints out the path to the currently set default target.
---
 man/systemctl.xml   | 18 ++
 shell-completion/bash/systemctl |  6 +++-
 src/core/dbus-manager.c | 28 +++-
 src/shared/install.c| 73 +
 src/shared/install.h|  2 ++
 src/systemctl/systemctl.c   | 65 ++--
 6 files changed, 188 insertions(+), 4 deletions(-)

diff --git a/man/systemctl.xml b/man/systemctl.xml
index 0afb0cc..9c3a5b0 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -998,6 +998,24 @@ kobject-uevent 1 systemd-udevd-kernel.socket 
systemd-udevd.service
   /varlistentry
 
   varlistentry
+termcommandset-default 
replaceableNAME/replaceable/command/term
+
+listitem
+  paraSet the default target to boot into. Command links
+  default.target to the given unit file./para
+/listitem
+  /varlistentry
+
+  varlistentry
+termcommandget-default/command/term
+
+listitem
+   paraGet the default target specified
+   via default.target unit./para
+/listitem
+  /varlistentry
+
+  varlistentry
 termcommandload replaceableNAME/replaceable.../command/term
 
 listitem
diff --git a/shell-completion/bash/systemctl b/shell-completion/bash/systemctl
index 191b8d1..a05b756 100644
--- a/shell-completion/bash/systemctl
+++ b/shell-completion/bash/systemctl
@@ -134,9 +134,10 @@ _systemctl () {
[STANDALONE]='daemon-reexec daemon-reload default dump
  emergency exit halt hibernate hybrid-sleep kexec 
list-jobs
  list-units list-unit-files poweroff reboot rescue
- show-environment suspend'
+ show-environment suspend get-default'
  [NAME]='snapshot load'
  [FILE]='link'
+  [TARGETS]='set-default'
 )
 
 for ((i=0; $i = $COMP_CWORD; i++)); do
@@ -210,6 +211,9 @@ _systemctl () {
 elif __contains_word $verb ${VERBS[FILE]}; then
 comps=$( compgen -A file -- $cur )
 compopt -o filenames
+elif __contains_word $verb ${VERBS[TARGETS]}; then
+comps=$( __systemctl $mode list-unit-files --type target 
--full --all \
+| { while read -r a b; do echo  $a; done; } )
 fi
 
 COMPREPLY=( $(compgen -W '$comps' -- $cur) )
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 56b02a1..f3ddfc9 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -227,6 +227,13 @@
arg name=\files\ type=\as\ direction=\in\/\n   \
arg name=\runtime\ type=\b\ direction=\in\/\n  \
arg name=\changes\ type=\a(sss)\ direction=\out\/\n \
+  /method\n \
+  method name=\SetDefaultTarget\\n \
+   arg name=\files\ type=\as\ direction=\in\/\n   \
+   arg name=\changes\ type=\a(sss)\ direction=\out\/\n \
+  /method\n \
+  method name=\GetDefaultTarget\\n \
+   arg name=\name\ type=\s\ direction=\out\/\n \
   /method\n
 
 #define BUS_MANAGER_INTERFACE_SIGNALS   \
@@ -1728,7 +1735,8 @@ static DBusHandlerResult 
bus_manager_message_handler(DBusConnection *connection,
dbus_message_is_method_call(message, 
org.freedesktop.systemd1.Manager, ReenableUnitFiles) ||
dbus_message_is_method_call(message, 
org.freedesktop.systemd1.Manager, LinkUnitFiles) ||
dbus_message_is_method_call(message, 
org.freedesktop.systemd1.Manager, PresetUnitFiles) ||
-   dbus_message_is_method_call(message, 
org.freedesktop.systemd1.Manager, MaskUnitFiles)) {
+   dbus_message_is_method_call(message, 
org.freedesktop.systemd1.Manager, MaskUnitFiles) ||
+   dbus_message_is_method_call(message, 
org.freedesktop.systemd1.Manager, SetDefaultTarget)) {
 
 char **l = NULL;
 DBusMessageIter iter;
@@ -1771,6 +1779,8 @@ static DBusHandlerResult 
bus_manager_message_handler(DBusConnection *connection,
 carries_install_info = r;
 } else if (streq(member, MaskUnitFiles))
 r = unit_file_mask(scope, runtime, NULL, l, force, 
changes, n_changes);
+else if (streq(member, SetDefaultTarget))
+r = unit_file_set_default(scope, NULL, l[0], changes, 
n_changes);
 else
 assert_not_reached(Uh? Wrong 

Re: [systemd-devel] Automatic Reboot Protocol

2013-05-28 Thread Colin Guthrie
'Twas brillig, and systemdki...@yopmail.com at 26/05/13 06:29 did gyre
and gimble:
 Jan Alexander Steffens,
 
 So in this timer, where/how apply reboot.target,
 or else tell systemd to invoke? Thx
 
 --
 # /etc/systemd/system/nightjanitor.timer
 [Unit]
 Description=Nightly wee-hours heartbeat
 
 [Timer]
 OnCalendar=*-*-* 01:23:45
 Unit=nightjanitor.service
 
 [Install]
 WantedBy=multi-user.target
 
 --
 # /etc/systemd/system/nightjanitor.service
 [Unit]
 Description=Nightly chores
 
 [Service]
 Type=simple
 ExecStart=/etc/systemd/system/nightjanitor.sh
 
 --
 #!/usr/bin/env bash
 # /etc/systemd/system/nightjanitor.sh
 
 set -e
 
 # do system stuff like backup
 # and house-clean generally,
 # then REBOOT as final step

Normally calling systemctl in a script is fine, but if you call
systemctl in a script as triggered by another unit it will typically
wait for the job to complete. If the job cannot complete due to waiting
for the job

Perhaps use of the systemctl --no-block start reboot.target would work
and allow your unit to exit happily and thus not block?

Col






-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited http://www.tribalogic.net/
Open Source:
  Mageia Contributor http://www.mageia.org/
  PulseAudio Hacker http://www.pulseaudio.org/
  Trac Hacker http://trac.edgewall.org/
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] journald: DO recalculate the ACL mask, but only if it doesn't exist

2013-05-28 Thread Jan Alexander Steffens (heftig)
From: Jan Alexander Steffens (heftig) jan.steff...@gmail.com

Since 11ec7ce, journald isn't setting the ACLs properly anymore if
the files had no ACLs to begin with: acl_set_fd fails with EINVAL.

An ACL with ACL_USER or ACL_GROUP entries but no ACL_MASK entry is
invalid, so make sure a mask exists before trying to set the ACL.
---
 src/journal/journald-server.c |  6 --
 src/shared/acl-util.c | 28 
 src/shared/acl-util.h |  1 +
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index b717b92..99c40a6 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -227,9 +227,11 @@ void server_fix_perms(Server *s, JournalFile *f, uid_t 
uid) {
 }
 }
 
-/* We do not recalculate the mask here, so that the fchmod() mask 
above stays intact. */
+/* We do not recalculate the mask unconditionally here,
+ * so that the fchmod() mask above stays intact. */
 if (acl_get_permset(entry, permset)  0 ||
-acl_add_perm(permset, ACL_READ)  0) {
+acl_add_perm(permset, ACL_READ)  0 ||
+acl_calc_mask_if_needed(acl)  0) {
 log_warning(Failed to patch ACL on %s, ignoring: %m, 
f-path);
 goto finish;
 }
diff --git a/src/shared/acl-util.c b/src/shared/acl-util.c
index 48bb12f..49788a2 100644
--- a/src/shared/acl-util.c
+++ b/src/shared/acl-util.c
@@ -69,6 +69,34 @@ int acl_find_uid(acl_t acl, uid_t uid, acl_entry_t *entry) {
 return 0;
 }
 
+int acl_calc_mask_if_needed(acl_t *acl_p) {
+acl_entry_t i;
+int found;
+
+assert(acl_p);
+
+for (found = acl_get_entry(*acl_p, ACL_FIRST_ENTRY, i);
+ found  0;
+ found = acl_get_entry(*acl_p, ACL_NEXT_ENTRY, i)) {
+
+acl_tag_t tag;
+
+if (acl_get_tag_type(i, tag)  0)
+return -errno;
+
+if (tag == ACL_MASK)
+return 0;
+}
+
+if (found  0)
+return -errno;
+
+if (acl_calc_mask(acl_p)  0)
+return -errno;
+
+return 0;
+}
+
 int search_acl_groups(char*** dst, const char* path, bool* belong) {
 acl_t acl;
 
diff --git a/src/shared/acl-util.h b/src/shared/acl-util.h
index 23090d9..cbb27ba 100644
--- a/src/shared/acl-util.h
+++ b/src/shared/acl-util.h
@@ -24,4 +24,5 @@
 #include stdbool.h
 
 int acl_find_uid(acl_t acl, uid_t uid, acl_entry_t *entry);
+int acl_calc_mask_if_needed(acl_t *acl_p);
 int search_acl_groups(char*** dst, const char* path, bool* belong);
-- 
1.8.3

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


Re: [systemd-devel] [PATCH] Delay dbus connection for user session

2013-05-28 Thread Kok, Auke-jan H
On Tue, May 28, 2013 at 3:00 AM, Chengwei Yang chengwei.y...@intel.com wrote:
 Currently, if we have a user session, when systemd user session start,
 just like the situation for it as PID 1, dbus-daemon isn't ready at that
 moment, so it always failed with below error.

 Feb 06 16:50:10 localhost.localdomain systemd[417]: Failed to open
 private bus connection: Failed to connect to socket
 /run/user/app/dbus/user_bus_socket: No such file or directory

 Signed-off-by: Chengwei Yang chengwei.y...@intel.com
 ---
  src/core/manager.c |2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

 diff --git a/src/core/manager.c b/src/core/manager.c
 index 0508628..467b5ba 100644
 --- a/src/core/manager.c
 +++ b/src/core/manager.c
 @@ -503,7 +503,7 @@ int manager_new(SystemdRunningAs running_as, Manager 
 **_m) {
  goto fail;

  /* Try to connect to the busses, if possible. */
 -r = bus_init(m, running_as != SYSTEMD_SYSTEM);
 +r = bus_init(m, running_as != SYSTEMD_SYSTEM  running_as != 
 SYSTEMD_USER);
  if (r  0)
  goto fail;

So, I've looked at this code again as I've spotted this problem over a
year ago, and I'm wondering if this entire section should just be
removed, since running_as only has 2 values (_SYSTEM and _USER)
anyway...

Would there be any objection to just dropping these 4 lines entirely?
Lennart, Kay? I don't see how we'd have a 3rd manager type here.


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


Re: [systemd-devel] [PATCH] Delay dbus connection for user session

2013-05-28 Thread Yang Chengwei
On Tue, May 28, 2013 at 01:53:16PM -0700, Kok, Auke-jan H wrote:
 On Tue, May 28, 2013 at 3:00 AM, Chengwei Yang chengwei.y...@intel.com 
 wrote:
  Currently, if we have a user session, when systemd user session start,
  just like the situation for it as PID 1, dbus-daemon isn't ready at that
  moment, so it always failed with below error.
 
  Feb 06 16:50:10 localhost.localdomain systemd[417]: Failed to open
  private bus connection: Failed to connect to socket
  /run/user/app/dbus/user_bus_socket: No such file or directory
 
  Signed-off-by: Chengwei Yang chengwei.y...@intel.com
  ---
   src/core/manager.c |2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
 
  diff --git a/src/core/manager.c b/src/core/manager.c
  index 0508628..467b5ba 100644
  --- a/src/core/manager.c
  +++ b/src/core/manager.c
  @@ -503,7 +503,7 @@ int manager_new(SystemdRunningAs running_as, Manager 
  **_m) {
   goto fail;
 
   /* Try to connect to the busses, if possible. */
  -r = bus_init(m, running_as != SYSTEMD_SYSTEM);
  +r = bus_init(m, running_as != SYSTEMD_SYSTEM  running_as != 
  SYSTEMD_USER);
   if (r  0)
   goto fail;
 
 So, I've looked at this code again as I've spotted this problem over a
 year ago, and I'm wondering if this entire section should just be
 removed, since running_as only has 2 values (_SYSTEM and _USER)
 anyway...
 
 Would there be any objection to just dropping these 4 lines entirely?
 Lennart, Kay? I don't see how we'd have a 3rd manager type here.

Yes, just in that case. If all of you agreed, I'd like submit a V2 to
drop these lines.

--
Thanks,
Chengwei

 
 
 Auke


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


Re: [systemd-devel] Automatic Reboot Protocol

2013-05-28 Thread systemdkiosk
Tried all advice so far, no dice, but thanks. A more advanced
timer/service layout may be needful in this rev of systemd (204), though
I'm fairly clueless what.

Last try was
( sleep 30  systemctl --no-block start reboot.target ) 

If anyone succeeds making something work, please post and thank you.

Script runtime is indeterminate so I can't use a second timer keyed for
X minutes after the first.

I do wonder if the janitor script could systemctl launch a second timer
with --runtime flag, that one in turn performing reboot as its only
command. Someone tell me if I'm all wet, I'm certainly no expert, just
guessing around while learning.

Thanks

-- 
http://www.fastmail.fm - Faster than the air-speed velocity of an
  unladen european swallow

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


Re: [systemd-devel] Automatic Reboot Protocol

2013-05-28 Thread Andrey Borzenkov
В Wed, 29 May 2013 04:24:41 +
systemdki...@yopmail.com пишет:

 Tried all advice so far, no dice, but thanks. A more advanced
 timer/service layout may be needful in this rev of systemd (204), though
 I'm fairly clueless what.
 
 Last try was
 ( sleep 30  systemctl --no-block start reboot.target ) 
 
 If anyone succeeds making something work, please post and thank you.
 
 Script runtime is indeterminate so I can't use a second timer keyed for
 X minutes after the first.
 

I lost you here. May be if you explain what you are trying to achieve
in general terms, without trying to pull in systemd from the very
beginning, someone could suggest how it can be implemented with systemd.

 I do wonder if the janitor script could systemctl launch a second timer
 with --runtime flag, that one in turn performing reboot as its only
 command. Someone tell me if I'm all wet, I'm certainly no expert, just
 guessing around while learning.
 
 Thanks
 

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


Re: [systemd-devel] [PATCH] honor SELinux labels, when creating and writing config files

2013-05-28 Thread poma
On 14.02.2013 16:21, Harald Hoyer wrote:
 Am 14.02.2013 12:27, schrieb har...@redhat.com:
 From: Harald Hoyer har...@redhat.com

 see https://bugzilla.redhat.com/show_bug.cgi?id=881577
 
 
 obsoleted by
 http://cgit.freedesktop.org/systemd/systemd/commit/?id=a5c32cff1f56afe6f0c6c70d91a88a7a8238b2d7
 
 after reworking the patch with Kay

http://www.youtube.com/watch?v=v4fZ6TgSDcM
https://bugzilla.redhat.com/show_bug.cgi?id=881577#c36


poma

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