[systemd-devel] [PATCH] systemctl: introduce --now for enable, disable and mask

2015-05-14 Thread jsynacek
From: Jan Synacek jsyna...@redhat.com

---
 Makefile.am  |  1 +
 man/systemctl.xml| 33 -
 src/libsystemd/sd-bus/bus-util.c |  6 +-
 src/libsystemd/sd-bus/bus-util.h |  3 ++-
 src/machine/machinectl.c |  2 +-
 src/shared/install.c |  2 +-
 src/shared/install.h |  3 +++
 src/systemctl/systemctl.c| 33 +
 8 files changed, 66 insertions(+), 17 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index e8a329f..861f3b2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5351,6 +5351,7 @@ machinectl_LDADD = \
libsystemd-internal.la \
libsystemd-logs.la \
libsystemd-journal-internal.la \
+   libsystemd-units.la \
libsystemd-shared.la
 
 rootbin_PROGRAMS += \
diff --git a/man/systemctl.xml b/man/systemctl.xml
index 4dbdfe1..951ce4d 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -456,6 +456,17 @@
   /varlistentry
 
   varlistentry
+termoption--now/option/term
+
+listitem
+  paraWhen used with commandenable/command, the units
+  will also be started. When used with commanddisable/command
+  or commandmask/command, the units will additionally be
+  stopped./para
+/listitem
+  /varlistentry
+
+  varlistentry
 termoption--root=/option/term
 
 listitem
@@ -921,11 +932,12 @@ kobject-uevent 1 systemd-udevd-kernel.socket 
systemd-udevd.service
 the changes are taken into account immediately. Note that
 this does emphasisnot/emphasis have the effect of also
 starting any of the units being enabled. If this
-is desired, a separate commandstart/command command must
-be invoked for the unit. Also note that in case of instance
-enablement, symlinks named the same as instances are created in
-the install location, however they all point to the same
-template unit file./para
+is desired, either option--now/option should be used
+together with this command, or a separate commandstart/command
+command must be invoked for the unit. Also note that in case of
+instance enablement, symlinks named the same as instances
+are created in the install location, however they all point to the
+same template unit file./para
 
 paraThis command will print the actions executed. This
 output may be suppressed by passing option--quiet/option.
@@ -980,9 +992,10 @@ kobject-uevent 1 systemd-udevd-kernel.socket 
systemd-udevd.service
 commandenable/command. This call implicitly reloads the
 systemd daemon configuration after completing the disabling
 of the units. Note that this command does not implicitly
-stop the units that are being disabled. If this is desired,
-an additional commandstop/command command should be
-executed afterwards./para
+stop the units that are being disabled. If this is desired, either
+option--now/option should be used together with this command, 
or
+an additional commandstop/command command should be executed
+afterwards./para
 
 paraThis command will print the actions executed. This
 output may be suppressed by passing option--quiet/option.
@@ -1128,7 +1141,9 @@ kobject-uevent 1 systemd-udevd-kernel.socket 
systemd-udevd.service
 activation of the unit, including enablement and manual
 activation. Use this option with care. This honors the
 option--runtime/option option to only mask temporarily
-until the next reboot of the system./para
+until the next reboot of the system. The option--now/option
+can be additionally used to ensure that the units are also
+stopped./para
   /listitem
 /varlistentry
 
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
index 7536a96..fe7eb43 100644
--- a/src/libsystemd/sd-bus/bus-util.c
+++ b/src/libsystemd/sd-bus/bus-util.c
@@ -1899,7 +1899,7 @@ int bus_wait_for_jobs_one(BusWaitForJobs *d, const char 
*path, bool quiet) {
 return bus_wait_for_jobs(d, quiet);
 }
 
-int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet) {
+int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet, 
UnitFileChange **changes, unsigned *n_changes) {
 const char *type, *path, *source;
 int r;
 
@@ -1914,6 +1914,10 @@ int 
bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet) {
 else
 log_info(Removed symlink %s., path);
 }
+
+r = add_file_change(changes, n_changes, streq(type, symlink) 
? UNIT_FILE_SYMLINK : 

Re: [systemd-devel] [PATCH] systemctl: introduce --now for enable, disable and mask

2015-05-14 Thread Zbigniew Jędrzejewski-Szmek
On Thu, May 14, 2015 at 02:26:34PM +0200, jsyna...@redhat.com wrote:
 From: Jan Synacek jsyna...@redhat.com
 
 ---
  Makefile.am  |  1 +
  man/systemctl.xml| 33 -
  src/libsystemd/sd-bus/bus-util.c |  6 +-
  src/libsystemd/sd-bus/bus-util.h |  3 ++-
  src/machine/machinectl.c |  2 +-
  src/shared/install.c |  2 +-
  src/shared/install.h |  3 +++
  src/systemctl/systemctl.c| 33 +
  8 files changed, 66 insertions(+), 17 deletions(-)
 
 diff --git a/Makefile.am b/Makefile.am
 index e8a329f..861f3b2 100644
 --- a/Makefile.am
 +++ b/Makefile.am
 @@ -5351,6 +5351,7 @@ machinectl_LDADD = \
   libsystemd-internal.la \
   libsystemd-logs.la \
   libsystemd-journal-internal.la \
 + libsystemd-units.la \
   libsystemd-shared.la
  
  rootbin_PROGRAMS += \
 diff --git a/man/systemctl.xml b/man/systemctl.xml
 index 4dbdfe1..951ce4d 100644
 --- a/man/systemctl.xml
 +++ b/man/systemctl.xml
 @@ -456,6 +456,17 @@
/varlistentry
  
varlistentry
 +termoption--now/option/term
 +
 +listitem
 +  paraWhen used with commandenable/command, the units
 +  will also be started. When used with commanddisable/command
 +  or commandmask/command, the units will additionally be
 +  stopped./para
 +/listitem
 +  /varlistentry
 +
 +  varlistentry
  termoption--root=/option/term
  
  listitem
 @@ -921,11 +932,12 @@ kobject-uevent 1 systemd-udevd-kernel.socket 
 systemd-udevd.service
  the changes are taken into account immediately. Note that
  this does emphasisnot/emphasis have the effect of also
  starting any of the units being enabled. If this
 -is desired, a separate commandstart/command command must
 -be invoked for the unit. Also note that in case of instance
 -enablement, symlinks named the same as instances are created in
 -the install location, however they all point to the same
 -template unit file./para
 +is desired, either option--now/option should be used
 +together with this command, or a separate 
 commandstart/command
 +command must be invoked for the unit. Also note that in case of
 +instance enablement, symlinks named the same as instances
 +are created in the install location, however they all point to 
 the
 +same template unit file./para
  
  paraThis command will print the actions executed. This
  output may be suppressed by passing option--quiet/option.
 @@ -980,9 +992,10 @@ kobject-uevent 1 systemd-udevd-kernel.socket 
 systemd-udevd.service
  commandenable/command. This call implicitly reloads the
  systemd daemon configuration after completing the disabling
  of the units. Note that this command does not implicitly
 -stop the units that are being disabled. If this is desired,
 -an additional commandstop/command command should be
 -executed afterwards./para
 +stop the units that are being disabled. If this is desired, 
 either
 +option--now/option should be used together with this 
 command, or
 +an additional commandstop/command command should be executed
 +afterwards./para
  
  paraThis command will print the actions executed. This
  output may be suppressed by passing option--quiet/option.
 @@ -1128,7 +1141,9 @@ kobject-uevent 1 systemd-udevd-kernel.socket 
 systemd-udevd.service
  activation of the unit, including enablement and manual
  activation. Use this option with care. This honors the
  option--runtime/option option to only mask temporarily
 -until the next reboot of the system./para
 +until the next reboot of the system. The option--now/option
 +can be additionally used to ensure that the units are also
 +stopped./para
/listitem
  /varlistentry
  
 diff --git a/src/libsystemd/sd-bus/bus-util.c 
 b/src/libsystemd/sd-bus/bus-util.c
 index 7536a96..fe7eb43 100644
 --- a/src/libsystemd/sd-bus/bus-util.c
 +++ b/src/libsystemd/sd-bus/bus-util.c
 @@ -1899,7 +1899,7 @@ int bus_wait_for_jobs_one(BusWaitForJobs *d, const char 
 *path, bool quiet) {
  return bus_wait_for_jobs(d, quiet);
  }
  
 -int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool 
 quiet) {
 +int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool 
 quiet, UnitFileChange **changes, unsigned *n_changes) {
  const char *type, *path, *source;
  int r;
  
 @@ -1914,6 +1914,10 @@ int 
 bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet) {
  else
 

Re: [systemd-devel] [PATCH] systemctl: introduce --now for enable, disable and mask

2015-05-14 Thread systemd github import bot
Patchset imported to github.
Pull request:
https://github.com/systemd-devs/systemd/compare/master...systemd-mailing-devs:1431606394-31015-1-git-send-email-jsynacek%40redhat.com

--
Generated by https://github.com/haraldh/mail2git
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] systemctl: introduce --now for enable, disable and mask

2015-05-14 Thread Lennart Poettering
On Thu, 14.05.15 14:26, jsyna...@redhat.com (jsyna...@redhat.com) wrote:

  const char *unit_file_preset_mode_to_string(UnitFilePresetMode m) _const_;
  UnitFilePresetMode unit_file_preset_mode_from_string(const char *s) _pure_;
 +
 +
 +int add_file_change(UnitFileChange **changes, unsigned *n_changes,
  UnitFileChangeType type, const char *path, const char *source);

No double newlines please.

More importantly though, if you export this function it should really
carry some useful namespace prefix, and not begin with the verb. 

Given that we already have unit_file_changes_free() as public call, it
should probably be called unit_file_changes_add() and be placed next
to it in the header and .c file.

Having good names for static, internal calls is not as important as
for non-static, exported ones, hence the need for the rename.

 +if (arg_now  n_changes  0  STR_IN_SET(args[0], enable, 
 disable, mask)) {
 +_cleanup_strv_free_ char **new_args = NULL;
 +unsigned i;
 +
 +r = strv_push(new_args, streq(args[0], enable) ? 
 strdup(start) : strdup(stop));
 +if (r  0)
 +goto finish;

This will crash on OOM.

strv_extend() internally does strdup() + strv_push() and checks for
OOM, hence that sounds like the better option.

That said, both strv_extend() and strv_push() internally reallocate
the string array. That's fine for small arrays, or when you don't know
how many entries to expect, but in this case you really do know, you
get it passed back in n_changes after all. Hence, please make use of
this, allocate a temporary array (maybe with newa()) then add the
entries to it, use and forget it.

 +
 +for (i = 0; i  n_changes; i++) {
 +r = strv_push(new_args,
 strdup(strrchr(changes[i].path, '/') + 1));

The strrchr appears to be something where useing basename() is the
better option...

Lennart

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


Re: [systemd-devel] [PATCH] systemctl: introduce --now for enable, disable and mask

2015-05-14 Thread Cam Hutchison
jsyna...@redhat.com writes:

diff --git a/man/systemctl.xml b/man/systemctl.xml
index 4dbdfe1..951ce4d 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -456,6 +456,17 @@
   /varlistentry
 
   varlistentry
+termoption--now/option/term
+
+listitem
+  paraWhen used with commandenable/command, the units
+  will also be started. When used with commanddisable/command
+  or commandmask/command, the units will additionally be

Just a small nit: s/additionally/also/. You used the word also in the
previous sentence, and when I see different language being used in
different places in documentation, I wonder whether there is something
different about the cases.

+  stopped./para

Could you elaborate on ordering here? Is the unit first enabled then started,
and first stopped then disabled? Some other order? Indeterminate?

+/listitem
+  /varlistentry
+
+  varlistentry
 termoption--root=/option/term
 
 listitem
@@ -921,11 +932,12 @@ kobject-uevent 1 systemd-udevd-kernel.socket 
systemd-udevd.service
 the changes are taken into account immediately. Note that
 this does emphasisnot/emphasis have the effect of also
 starting any of the units being enabled. If this
-is desired, a separate commandstart/command command must
-be invoked for the unit. Also note that in case of instance
-enablement, symlinks named the same as instances are created in
-the install location, however they all point to the same
-template unit file./para
+is desired, either option--now/option should be used
+together with this command, or a separate commandstart/command

Similar to my nit above - this uses separate, the disable paragraph uses
additional. (I realise this is pre-existing language, but while you're here
it can be fixed).

+command must be invoked for the unit. Also note that in case of
+instance enablement, symlinks named the same as instances
+are created in the install location, however they all point to the
+same template unit file./para
 
 paraThis command will print the actions executed. This
 output may be suppressed by passing option--quiet/option.
@@ -980,9 +992,10 @@ kobject-uevent 1 systemd-udevd-kernel.socket 
systemd-udevd.service
 commandenable/command. This call implicitly reloads the
 systemd daemon configuration after completing the disabling
 of the units. Note that this command does not implicitly
-stop the units that are being disabled. If this is desired,
-an additional commandstop/command command should be
-executed afterwards./para
+stop the units that are being disabled. If this is desired, either
+option--now/option should be used together with this command, 
or
+an additional commandstop/command command should be executed

additional used here. See previous comment.

+afterwards./para
 
 paraThis command will print the actions executed. This
 output may be suppressed by passing option--quiet/option.
@@ -1128,7 +1141,9 @@ kobject-uevent 1 systemd-udevd-kernel.socket 
systemd-udevd.service
 activation of the unit, including enablement and manual
 activation. Use this option with care. This honors the
 option--runtime/option option to only mask temporarily
-until the next reboot of the system./para
+until the next reboot of the system. The option--now/option
+can be additionally used to ensure that the units are also
+stopped./para

Drop the word additionally since there is an also later in the sentence
(and options by their nature are additional).

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