Hi List,

this is a first and for now only compile-tested draft of the alias stanza.
Tests for the stanza are missing.
The code for the alias stanza parsing is a copy of the one for the emits stanza.
The testsuite of a patched 1.3 runs fine (exept for the X11 dependent tests as 
my box has no X11 running).

I'm unshure if the handling of blocked events with an alias configured works in 
this draft version, i'm still reading the code path of event.c and try to check 
if i'm not overlooking something.

Currently i add all blocking aliases to the main jobs blocking queue/list and 
hope that the catch in the event_poll loop works out as expected.
I think there is a call to event_block missing for every alias event.
I still have to check out how the whole blocking event chain code works...

Thanks,

Marc

=== modified file 'init/job.c'
--- init/job.c  2011-06-06 17:05:11 +0000
+++ init/job.c  2011-06-14 23:32:17 +0000
@@ -817,7 +817,7 @@ job_finished (Job *job,
 Event *
 job_emit_event (Job *job)
 {
-       Event           *event;
+       Event           *event, *alias;
        const char      *name;
        int              block = FALSE, stop = FALSE;
        nih_local char **env = NULL;
@@ -925,6 +925,22 @@ job_emit_event (Job *job)
                nih_list_add (&event->blocking, &blocked->entry);
        }
 
+       /* Send an event for each configured alias */
+       for (e = job->class->alias; e && *e; e++) {
+               NIH_MUST (environ_set (&env, NULL, &len, TRUE,
+                                      "JOB=%s", *e));
+               alias = NIH_MUST (event_new (NULL, name, env));
+               alias->session = job->class->session;
+
+               /* Add a blocking alias event to the main events blocking list 
*/
+               if (block) {
+                       Blocked *blockedalias;
+
+                       blockedalias = NIH_MUST (blocked_new (alias, 
BLOCKED_JOB, job));
+                       nih_list_add (&event->blocking, &blockedalias->entry);
+               }
+       }
+
        return event;
 }
 

=== modified file 'init/job_class.c'
--- init/job_class.c    2011-06-06 13:16:33 +0000
+++ init/job_class.c    2011-06-10 19:33:26 +0000
@@ -224,6 +224,7 @@ job_class_new (const void *parent,
 
        class->start_on = NULL;
        class->stop_on = NULL;
+       class->alias = NULL;
        class->emits = NULL;
 
        class->process = nih_alloc (class, sizeof (Process *) * PROCESS_LAST);

=== modified file 'init/job_class.h'
--- init/job_class.h    2011-05-15 12:57:29 +0000
+++ init/job_class.h    2011-06-10 19:33:14 +0000
@@ -126,6 +126,7 @@ typedef struct job_class {
 
        EventOperator  *start_on;
        EventOperator  *stop_on;
+       char          **alias;
        char          **emits;
 
        Process       **process;

=== modified file 'init/parse_job.c'
--- init/parse_job.c    2011-06-06 12:52:08 +0000
+++ init/parse_job.c    2011-06-14 23:04:14 +0000
@@ -127,6 +127,10 @@ static int stanza_stop        (JobClass
                               const char *file, size_t len,
                               size_t *pos, size_t *lineno)
        __attribute__ ((warn_unused_result));
+static int stanza_alias       (JobClass *class, NihConfigStanza *stanza,
+                              const char *file, size_t len,
+                              size_t *pos, size_t *lineno)
+       __attribute__ ((warn_unused_result));
 static int stanza_emits       (JobClass *class, NihConfigStanza *stanza,
                               const char *file, size_t len,
                               size_t *pos, size_t *lineno)
@@ -234,6 +238,7 @@ static NihConfigStanza stanzas[] = {
        { "export",      (NihConfigHandler)stanza_export      },
        { "start",       (NihConfigHandler)stanza_start       },
        { "stop",        (NihConfigHandler)stanza_stop        },
+       { "alias",       (NihConfigHandler)stanza_alias       },
        { "emits",       (NihConfigHandler)stanza_emits       },
        { "exec",        (NihConfigHandler)stanza_exec        },
        { "script",      (NihConfigHandler)stanza_script      },
@@ -1431,6 +1436,53 @@ stanza_stop (JobClass        *class,
 }
 
 /**
+ * stanza_alias:
+ * @class: job class being parsed,
+ * @stanza: stanza found,
+ * @file: file or string to parse,
+ * @len: length of @file,
+ * @pos: offset within @file,
+ * @lineno: line number.
+ *
+ * Parse an alias stanza from @file.  This stanza expects one or more
+ * arguments giving the names of additional alias events to be emitted
+ * by this job.  These are stored in the alias array, which is increased
+ * in size to accomodate the new values.
+ *
+ * Returns: zero on success, negative value on error.
+ **/
+static int
+stanza_alias (JobClass        *class,
+             NihConfigStanza *stanza,
+             const char      *file,
+             size_t           len,
+             size_t          *pos,
+             size_t          *lineno)
+{
+       nih_local char **args = NULL;
+       char           **arg;
+
+       nih_assert (class != NULL);
+       nih_assert (stanza != NULL);
+       nih_assert (file != NULL);
+       nih_assert (pos != NULL);
+
+       if (! nih_config_has_token (file, len, pos, lineno))
+               nih_return_error (-1, NIH_CONFIG_EXPECTED_TOKEN,
+                                 _(NIH_CONFIG_EXPECTED_TOKEN_STR));
+
+       args = nih_config_parse_args (NULL, file, len, pos, lineno);
+       if (! args)
+               return -1;
+
+       for (arg = args; *arg; arg++)
+               if (! nih_str_array_addp (&class->alias, class, NULL, *arg))
+                       nih_return_system_error (-1);
+
+       return 0;
+}
+
+/**
  * stanza_emits:
  * @class: job class being parsed,
  * @stanza: stanza found,


-- 
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel

Reply via email to