Re: [systemd-devel] [PATCH v4 4/4] run: introduce timer support option

2014-12-02 Thread WaLyong Cho
On 12/02/2014 11:29 PM, WaLyong Cho wrote:
> Supported timer options --on-active=, --on-boot=, --on-startup=,
> --on-unit-active=, --on-unit-inactive=, --on-calendar=. Each options
> corresponding with OnActiveSec=, OnBootSec=, OnStartupSec=,
> OnUnitActiveSec=, OnUnitInactiveSec= of timer respectively.
> ---
>  man/systemd-run.xml  |  42 +++
>  src/libsystemd/sd-bus/bus-util.c |  14 +-
>  src/run/run.c| 583 
> ---
>  3 files changed, 539 insertions(+), 100 deletions(-)
> 
> diff --git a/src/run/run.c b/src/run/run.c
> index 85eb052..03f49df 100644
> --- a/src/run/run.c
> +++ b/src/run/run.c
> @@ -551,7 +934,7 @@ static int start_transient_scope(
>  int main(int argc, char* argv[]) {
>  _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
>  _cleanup_bus_close_unref_ sd_bus *bus = NULL;
> -_cleanup_free_ char *description = NULL, *command = NULL;
> +_cleanup_free_ char *description = NULL, *command = NULL, *state = 
> NULL;

Sorry, unused valuable, please ignore this.

>  int r;
>  
>  log_parse_environment();
> @@ -588,6 +971,8 @@ int main(int argc, char* argv[]) {
>  
>  if (arg_scope)
>  r = start_transient_scope(bus, argv + optind, &error);
> +else if (with_timer)
> +r = start_transient_timer(bus, argv + optind, &error);
>  else
>  r = start_transient_service(bus, argv + optind, &error);
>  
> 
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v4 4/4] run: introduce timer support option

2014-12-02 Thread WaLyong Cho
Supported timer options --on-active=, --on-boot=, --on-startup=,
--on-unit-active=, --on-unit-inactive=, --on-calendar=. Each options
corresponding with OnActiveSec=, OnBootSec=, OnStartupSec=,
OnUnitActiveSec=, OnUnitInactiveSec= of timer respectively.
---
 man/systemd-run.xml  |  42 +++
 src/libsystemd/sd-bus/bus-util.c |  14 +-
 src/run/run.c| 583 ---
 3 files changed, 539 insertions(+), 100 deletions(-)

diff --git a/man/systemd-run.xml b/man/systemd-run.xml
index 28a9878..abac26c 100644
--- a/man/systemd-run.xml
+++ b/man/systemd-run.xml
@@ -210,6 +210,37 @@ along with systemd; If not, see 
.
   
   
 
+  
+--on-active=
+--on-boot=
+--on-startup=
+--on-unit-active=
+--on-unit-inactive=
+
+Defines monotonic timers relative to different
+starting points. Also see OnActiveSec=,
+OnBootSec=,
+OnStartupSec=,
+OnUnitActiveSec= and
+OnUnitInactiveSec= in
+
systemd.timer5.
 This
+option has no effect in conjunction with
+--scope.
+
+  
+
+  
+--on-calendar=
+
+Defines realtime (i.e. wallclock) timers with
+calendar event expressions. Also see
+OnCalendar= in
+
systemd.timer5.
 This
+option has no effect in conjunction with
+--scope.
+
+  
+
   
   
 
@@ -250,6 +281,16 @@ Sep 08 07:37:21 bupkis env[19948]: 
BOOT_IMAGE=/vmlinuz-3.11.0-0.rc5.git6.2.fc20.
 property.
 
 # systemd-run -p BlockIOWeight=10 updatedb
+
+The following command will touch a file after 10 seconds.
+
+# date; systemd-run --on-active=10 touch /tmp/hello
+Mon Oct 27 20:02:57 KST 2014
+Running as unit run-66.timer.
+# journalctl -u run-115.service
+-- Logs begin at Mon 2014-10-27 19:44:57 KST, end at Mon 2014-10-27 20:03:15 
KST. --
+Oct 27 20:03:15 container systemd[1]: Starting /bin/touch /tmp/hello...
+Oct 27 20:03:15 container systemd[1]: Started /bin/touch 
/tmp/hello.
   
 
   
@@ -263,6 +304,7 @@ Sep 08 07:37:21 bupkis env[19948]: 
BOOT_IMAGE=/vmlinuz-3.11.0-0.rc5.git6.2.fc20.
   
systemd.slice5,
   
systemd.exec5,
   
systemd.resource-control5,
+  
systemd.timer5,
   
machinectl1
 
   
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
index bdaa449..0f1a89c 100644
--- a/src/libsystemd/sd-bus/bus-util.c
+++ b/src/libsystemd/sd-bus/bus-util.c
@@ -1372,7 +1372,8 @@ int bus_append_unit_property_assignment(sd_bus_message 
*m, const char *assignmen
 
 if (STR_IN_SET(field,
"CPUAccounting", "MemoryAccounting", 
"BlockIOAccounting",
-   "SendSIGHUP", "SendSIGKILL")) {
+   "SendSIGHUP", "SendSIGKILL",
+   "WakeSystem")) {
 
 r = parse_boolean(eq);
 if (r < 0) {
@@ -1533,6 +1534,17 @@ int bus_append_unit_property_assignment(sd_bus_message 
*m, const char *assignmen
 
 r = sd_bus_message_append(m, "v", "i", sig);
 
+} else if (streq(field, "AccuracySec")) {
+usec_t u;
+
+r = parse_sec(eq, &u);
+if (r < 0) {
+log_error("Failed to parse %s value %s", field, eq);
+return -EINVAL;
+}
+
+r = sd_bus_message_append(m, "v", "t", u);
+
 } else {
 log_error("Unknown assignment %s.", assignment);
 return -EINVAL;
diff --git a/src/run/run.c b/src/run/run.c
index 85eb052..03f49df 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -30,6 +30,7 @@
 #include "env-util.h"
 #include "path-util.h"
 #include "bus-error.h"
+#include "calendarspec.h"
 
 static bool arg_scope = false;
 static bool arg_remain_after_exit = false;
@@ -47,10 +48,19 @@ static int arg_nice = 0;
 static bool arg_nice_set = false;
 static char **arg_environment = NULL;
 static char **arg_property = NULL;
+static bool with_timer = false;
+static usec_t arg_on_active = 0;
+static usec_t arg_on_boot = 0;
+static usec_t arg_on_startup = 0;
+static usec_t arg_on_unit_active = 0;
+static usec_t arg_on_unit_inactive = 0;
+static char *arg_on_calendar = NULL;
 
 static void help(void) {
-printf("%s [OPTIONS...] COMMAND [ARGS...]\n\n"
-   "Run the specified command in a transient scope or service 
unit.\n\n"
+printf("%s [OPTIONS...] [COMMAND] [ARGS...]\n\n"
+   "Run the specified command in a transient scope or service or 
timer\n"
+   "unit. If timer option is specified and unit is exist which 
is\n"
+   "specified with --unit option then command can be ommited.\n\n"
"  -h --help Show this help\n"
" --version  Show package version\n"
" --user Run as u