~vorlon/ubuntu/raring/upstart/lp.1199778

« back to all changes in this revision

Viewing changes to init/job.c

  • Committer: Scott James Remnant
  • Date: 2008-05-09 01:26:15 UTC
  • Revision ID: scott@netsplit.com-20080509012615-syxaac132qqqje6s
* init/job.c (job_new): Singleton jobs have a fixed name of "",
rather than a NULL name, and a D-Bus name of "_".
(job_instance): Which rather simplifies this function (in fact,
it makes this function look like a common one).
(job_emit_event): Always set INSTANCE variable.
(job_name): Still distinguish in output, to avoid ugly "()" but
check character rather than NULL.
* init/tests/test_job.c (test_new): Check name is set to ""
and path to ".../_"
(test_change_state, test_emit_event): Update test cases to assume
an empty INSTANCE variable
(test_instance): Update to pass "" instead of NULL.
* init/job_process.c (job_process_run): Always set UPSTART_INSTANCE
* init/tests/test_job_process.c (test_run): Always assume an
UPSTART_INSTANCE variable, it may just be empty.
* init/tests/test_event.c (test_pending_handle_jobs): Expect
the name to be set to the empty string.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
 * appending it to the list of instances for @class.  The returned job
72
72
 * will also be an nih_alloc() child of @class.
73
73
 *
74
 
 * @name is used to uniquely identify the instance, and must be given if
75
 
 * the @class instance member is not NULL.
 
74
 * @name is used to uniquely identify the instance and is normally
 
75
 * generated by expanding the @class's instance member, otherwise may
 
76
 * be NULL if that is not set.
76
77
 *
77
78
 * Returns: newly allocated job structure or NULL if insufficient memory.
78
79
 **/
98
99
 
99
100
        job->class = class;
100
101
 
101
 
        job->name = NULL;
102
 
        if (name) {
103
 
                job->name = nih_strdup (job, name);
104
 
                if (! job->name)
105
 
                        goto error;
106
 
        }
 
102
        job->name = nih_strdup (job, name ? name : "");
 
103
        if (! job->name)
 
104
                goto error;
107
105
 
108
106
        job->path = nih_dbus_path (job, CONTROL_ROOT, "jobs",
109
 
                                   class->name, name ? name : "active", NULL);
 
107
                                   class->name, job->name, NULL);
110
108
        if (! job->path)
111
109
                goto error;
112
110
 
202
200
              const char *name)
203
201
{
204
202
        nih_assert (class != NULL);
205
 
 
206
 
        /* There aren't any instances in the list, always return NULL */
207
 
        if (NIH_LIST_EMPTY (&class->instances))
208
 
                return NULL;
209
 
 
210
 
        /* Not an instance job, always return the first instance */
211
 
        if (! class->instance)
212
 
                return (Job *)class->instances.next;
213
 
 
214
203
        nih_assert (name != NULL);
215
204
 
216
 
        /* Lookup an instance with the name given */
217
205
        NIH_LIST_FOREACH (&class->instances, iter) {
218
206
                Job *job = (Job *)iter;
219
207
 
220
 
                nih_assert (job->name != NULL);
221
 
 
222
208
                if (! strcmp (job->name, name))
223
209
                        return job;
224
210
        }
728
714
        /* Add the job and instance name */
729
715
        NIH_MUST (environ_set (&env, NULL, &len, TRUE,
730
716
                               "JOB=%s", job->class->name));
731
 
        if (job->name)
732
 
                NIH_MUST (environ_set (&env, NULL, &len, TRUE,
733
 
                                       "INSTANCE=%s", job->name));
 
717
        NIH_MUST (environ_set (&env, NULL, &len, TRUE,
 
718
                               "INSTANCE=%s", job->name));
734
719
 
735
720
        /* Stop events include a "failed" argument if a process failed,
736
721
         * otherwise stop events have an "ok" argument.
816
801
        if (name)
817
802
                nih_free (name);
818
803
 
819
 
        if (job->name) {
 
804
        if (*job->name) {
820
805
                NIH_MUST (name = nih_sprintf (NULL, "%s (%s)",
821
806
                                              job->class->name, job->name));
822
807
        } else {