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

« back to all changes in this revision

Viewing changes to init/job.c

  • Committer: Scott James Remnant
  • Date: 2006-08-16 12:31:49 UTC
  • Revision ID: scott@netsplit.com-20060816123149-153af61c6bf9257e
* init/job.c (job_start): Check for dependencies before starting
the process, if we have any that aren't running we stay in waiting
until they are.  Any that aren't even starting get poked with a
dependency event to see whether that wakes them up.
* init/tests/test_job.c (test_start): Test paths through new
dependency code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
791
791
void
792
792
job_start (Job *job)
793
793
{
 
794
        int held = FALSE;
 
795
 
794
796
        nih_assert (job != NULL);
795
797
 
796
798
        job_init ();
814
816
                return;
815
817
        }
816
818
 
817
 
        /* FIXME
818
 
         * if there are dependencies, we stay in waiting
819
 
         */
820
 
 
821
 
        job_change_state (job, job_next_state (job));
 
819
        /* Iterate our dependencies */
 
820
        NIH_LIST_FOREACH (&job->depends, iter) {
 
821
                JobName *dep = (JobName *)iter;
 
822
                Job     *dep_job;
 
823
 
 
824
                /* First check the dependency is actually known; if not we
 
825
                 * still hold the job but we warn that there's a potential
 
826
                 * bogon in there.
 
827
                 */
 
828
                dep_job = job_find_by_name (dep->name);
 
829
                if (! dep_job) {
 
830
                        nih_warn (_("%s waiting for unknown dependency: %s"),
 
831
                                  job->name, dep->name);
 
832
                        held = TRUE;
 
833
                        continue;
 
834
                }
 
835
 
 
836
                /* If the dependency is running with an active process,
 
837
                 * we don't need to hold for it.
 
838
                 */
 
839
                if ((dep_job->goal == JOB_START)
 
840
                    && (dep_job->state == JOB_RUNNING)
 
841
                    && (dep_job->process_state == PROCESS_ACTIVE))
 
842
                        continue;
 
843
 
 
844
                /* Hold for it */
 
845
                held = TRUE;
 
846
                nih_info (_("%s waiting for dependency: %s"),
 
847
                          job->name, dep_job->name);
 
848
 
 
849
                /* If the job isn't going to be started, try sending it
 
850
                 * a dependency event and see whether that starts it
 
851
                 */
 
852
                if (dep_job->goal == JOB_STOP) {
 
853
                        Event *event;
 
854
 
 
855
                        NIH_MUST (event = event_new (NULL, "dependency"));
 
856
                        job_start_event (dep_job, event);
 
857
                        nih_free (event);
 
858
                }
 
859
        }
 
860
 
 
861
        if (! held)
 
862
                job_change_state (job, job_next_state (job));
822
863
}
823
864
 
824
865
/**