346
366
nih_assert (job != NULL);
371
nih_message ("XXX:%s:%d: state=%s, job: %s, goal=%s, state=%s",
373
job_state_name (state),
375
job_goal_name (job->goal),
376
job_state_name (job->state));
348
380
while (job->state != state) {
381
//JobState old_state;
384
nih_assert (! job->blocker);
386
/* Allow the event to be emitted before proceeding */
392
nih_message ("XXX:%s:%d: while: state=%s, job: %s, goal=%s, state=%s",
394
job_state_name (state),
396
job_goal_name (job->goal),
397
job_state_name (job->state));
402
Event *event = (Event *)job->blocker;
404
nih_message ("XXX:%s:%d: job->blocker event=%s (env='%s', progress=%d)",
407
event->env ? event->env[0] : "",
411
/* FIXME: cannot assert this since there will be a
352
414
nih_assert (job->blocker == NULL);
416
/* FIXME: only true if not calling job_process_start()!!! */
354
417
nih_info (_("%s state changed from %s to %s"), job_name (job),
355
418
job_state_name (job->state), job_state_name (state));
357
old_state = job->state;
422
nih_message ("XXX:%s:%d: while: state=%s, job: %s, goal=%s, state=%s",
424
job_state_name (state),
426
job_goal_name (job->goal),
427
job_state_name (job->state));
431
/* FIXME: should not change state until job known to
432
* have started successfully!
434
//old_state = job->state;
435
//job->state = state;
437
/* FIXME: emitted too early !! */
360
439
NIH_LIST_FOREACH (control_conns, iter) {
361
440
NihListEntry *entry = (NihListEntry *)iter;
362
441
DBusConnection *conn = (DBusConnection *)entry->data;
366
445
job_state_name (job->state)));
369
449
/* Perform whatever action is necessary to enter the new
370
450
* state, such as executing a process or emitting an event.
372
switch (job->state) {
373
453
case JOB_STARTING:
374
454
nih_assert (job->goal == JOB_START);
375
nih_assert ((old_state == JOB_WAITING)
376
|| (old_state == JOB_POST_STOP));
455
nih_assert ((job->state == JOB_WAITING)
456
|| (job->state == JOB_POST_STOP));
378
458
/* Throw away our old environment and use the newly
379
459
* set environment from now on; unless that's NULL
398
478
job->failed_process = PROCESS_INVALID;
399
479
job->exit_status = 0;
401
job->blocker = job_emit_event (job);
483
nih_message ("XXX:%s:%d: while: state=%s, job: %s, goal=%s, state=%s: @@@@@ setting job->blocker",
485
job_state_name (state),
487
job_goal_name (job->goal),
488
job_state_name (job->state));
490
job->blocker = job_emit_event (job, state);
404
495
case JOB_SECURITY:
405
496
nih_assert (job->goal == JOB_START);
406
nih_assert (old_state == JOB_STARTING);
497
nih_assert (job->state == JOB_STARTING);
408
499
if (job->class->process[PROCESS_SECURITY]
409
500
&& apparmor_available()) {
410
job_process_start (job, state,
501
job_process_start (job, state, PROCESS_SECURITY);
414
505
state = job_next_state (job);
509
case JOB_PRE_STARTING:
510
nih_assert (job->goal == JOB_START);
511
nih_assert (job->state == JOB_SECURITY);
513
state = job_next_state (job);
418
515
case JOB_PRE_START:
419
516
nih_assert (job->goal == JOB_START);
420
nih_assert (old_state == JOB_SECURITY);
517
nih_assert (job->state == JOB_PRE_STARTING);
422
519
if (job->class->process[PROCESS_PRE_START]) {
423
job_process_start (job,state,
424
PROCESS_PRE_START, job_error_handler);
520
job_process_start (job, state, PROCESS_PRE_START);
426
524
state = job_next_state (job);
529
nih_assert (job->goal == JOB_START);
530
nih_assert (job->state == JOB_PRE_START);
533
state = job_next_state (job);
430
535
case JOB_SPAWNED:
431
536
nih_assert (job->goal == JOB_START);
432
nih_assert (old_state == JOB_PRE_START);
537
nih_assert (job->state == JOB_SPAWNING);
434
539
if (job->class->process[PROCESS_MAIN]) {
435
job_process_start (job, state,
436
PROCESS_MAIN, job_error_handler);
540
job_process_start (job, state, PROCESS_MAIN);
437
541
if (job->class->expect == EXPECT_NONE) {
438
543
state = job_next_state (job);
441
549
state = job_next_state (job);
553
case JOB_POST_STARTING:
554
nih_assert (job->goal == JOB_START);
555
nih_assert (job->state == JOB_SPAWNED);
557
state = job_next_state (job);
445
559
case JOB_POST_START:
446
560
nih_assert (job->goal == JOB_START);
447
nih_assert (old_state == JOB_SPAWNED);
561
nih_assert (job->state == JOB_POST_STARTING);
449
563
if (job->class->process[PROCESS_POST_START]) {
450
job_process_start (job, state,
451
PROCESS_POST_START, job_error_handler);
564
job_process_start (job, state, PROCESS_POST_START);
453
568
state = job_next_state (job);
457
572
case JOB_RUNNING:
458
573
nih_assert (job->goal == JOB_START);
459
nih_assert ((old_state == JOB_POST_START)
460
|| (old_state == JOB_PRE_STOP));
574
nih_assert ((job->state == JOB_POST_START)
575
|| (job->state == JOB_PRE_STOP));
462
if (old_state == JOB_PRE_STOP) {
577
if (job->state == JOB_PRE_STOP) {
463
578
/* Throw away the stop environment */
464
579
if (job->stop_env) {
465
580
nih_unref (job->stop_env, job);
469
584
/* Cancel the stop attempt */
470
585
job_finished (job, FALSE);
472
job_emit_event (job);
589
nih_message ("XXX:%s:%d: while: state=%s, job: %s, goal=%s, state=%s: @@@@@ setting job->blocker",
591
job_state_name (state),
593
job_goal_name (job->goal),
594
job_state_name (job->state));
596
job_emit_event (job, state);
474
598
/* If we're not a task, our goal is to be
478
602
job_finished (job, FALSE);
608
case JOB_PRE_STOPPING:
609
nih_assert (job->goal == JOB_STOP);
610
nih_assert (job->state == JOB_RUNNING);
612
state = job_next_state (job);
482
614
case JOB_PRE_STOP:
483
615
nih_assert (job->goal == JOB_STOP);
484
nih_assert (old_state == JOB_RUNNING);
616
nih_assert (job->state == JOB_PRE_STOPPING);
486
618
if (job->class->process[PROCESS_PRE_STOP]) {
487
job_process_start (job, state,
488
PROCESS_PRE_STOP, job_error_handler);
619
job_process_start (job, state, PROCESS_PRE_STOP);
490
623
state = job_next_state (job);
494
627
case JOB_STOPPING:
495
nih_assert ((old_state == JOB_STARTING)
496
|| (old_state == JOB_PRE_START)
497
|| (old_state == JOB_SECURITY)
498
|| (old_state == JOB_SPAWNED)
499
|| (old_state == JOB_POST_START)
500
|| (old_state == JOB_RUNNING)
501
|| (old_state == JOB_PRE_STOP));
503
job->blocker = job_emit_event (job);
628
nih_assert ((job->state == JOB_STARTING)
629
|| (job->state == JOB_PRE_START)
630
|| (job->state == JOB_SECURITY)
631
|| (job->state == JOB_SPAWNED)
632
|| (job->state == JOB_POST_START)
633
|| (job->state == JOB_RUNNING)
634
|| (job->state == JOB_PRE_STOP));
638
nih_message ("XXX:%s:%d: while: state=%s, job: %s, goal=%s, state=%s: @@@@@ setting job->blocker",
640
job_state_name (state),
642
job_goal_name (job->goal),
643
job_state_name (job->state));
645
job->blocker = job_emit_event (job, state);
507
nih_assert (old_state == JOB_STOPPING);
651
nih_assert (job->state == JOB_STOPPING);
509
653
if (job->class->process[PROCESS_MAIN]
510
654
&& (job->pid[PROCESS_MAIN] > 0)) {
511
655
job_process_kill (job, PROCESS_MAIN);
513
658
state = job_next_state (job);
662
case JOB_POST_STOPPING:
663
nih_assert (job->state == JOB_KILLED);
665
state = job_next_state (job);
517
667
case JOB_POST_STOP:
518
nih_assert (old_state == JOB_KILLED);
668
nih_assert (job->state == JOB_POST_STOPPING);
520
670
if (job->class->process[PROCESS_POST_STOP]) {
521
job_process_start (job, state,
522
PROCESS_POST_STOP, job_error_handler);
671
job_process_start (job, state, PROCESS_POST_STOP);
524
675
state = job_next_state (job);
528
679
case JOB_WAITING:
529
680
nih_assert (job->goal == JOB_STOP);
530
nih_assert ((old_state == JOB_POST_STOP)
531
|| (old_state == JOB_STARTING));
681
nih_assert ((job->state == JOB_POST_STOP)
682
|| (job->state == JOB_STARTING));
533
job_emit_event (job);
686
nih_message ("XXX:%s:%d: while: state=%s, job: %s, goal=%s, state=%s: @@@@@ setting job->blocker",
688
job_state_name (state),
690
job_goal_name (job->goal),
691
job_state_name (job->state));
693
job_emit_event (job, state);
535
695
job_finished (job, FALSE);
1136
1380
return JOB_STARTING;
1137
1381
} else if (! strcmp (state, "security")) {
1138
1382
return JOB_SECURITY;
1383
} else if (! strcmp (state, "pre-starting")) {
1384
return JOB_PRE_STARTING;
1139
1385
} else if (! strcmp (state, "pre-start")) {
1140
1386
return JOB_PRE_START;
1387
} else if (! strcmp (state, "spawning")) {
1388
return JOB_SPAWNING;
1141
1389
} else if (! strcmp (state, "spawned")) {
1142
1390
return JOB_SPAWNED;
1391
} else if (! strcmp (state, "post-starting")) {
1392
return JOB_POST_STARTING;
1143
1393
} else if (! strcmp (state, "post-start")) {
1144
1394
return JOB_POST_START;
1145
1395
} else if (! strcmp (state, "running")) {
1146
1396
return JOB_RUNNING;
1397
} else if (! strcmp (state, "pre-stopping")) {
1398
return JOB_PRE_STOPPING;
1147
1399
} else if (! strcmp (state, "pre-stop")) {
1148
1400
return JOB_PRE_STOP;
1149
1401
} else if (! strcmp (state, "stopping")) {
1150
1402
return JOB_STOPPING;
1151
1403
} else if (! strcmp (state, "killed")) {
1152
1404
return JOB_KILLED;
1405
} else if (! strcmp (state, "post-stopping")) {
1406
return JOB_POST_STOPPING;
1153
1407
} else if (! strcmp (state, "post-stop")) {
1154
1408
return JOB_POST_STOP;
1766
2021
json_object_object_add (json, "log", json_logs);
2023
nih_debug ("XXX:%s:%d:", __func__, __LINE__);
2024
json_handler_data = job_process_data_serialise (job, job->handler_data);
2025
if (! json_handler_data)
2027
nih_debug ("XXX:%s:%d:", __func__, __LINE__);
2029
json_object_object_add (json, "handler_data", json_handler_data);
2031
nih_debug ("XXX:%s:%d:", __func__, __LINE__);
2168
2443
* Returns: string representation of @state, or NULL if not known.
2171
2446
job_state_enum_to_str (JobState state)
2173
2448
state_enum_to_str (JOB_WAITING, state);
2174
2449
state_enum_to_str (JOB_STARTING, state);
2175
2450
state_enum_to_str (JOB_SECURITY, state);
2451
state_enum_to_str (JOB_PRE_STARTING, state);
2176
2452
state_enum_to_str (JOB_PRE_START, state);
2453
state_enum_to_str (JOB_SPAWNING, state);
2177
2454
state_enum_to_str (JOB_SPAWNED, state);
2455
state_enum_to_str (JOB_POST_STARTING, state);
2178
2456
state_enum_to_str (JOB_POST_START, state);
2179
2457
state_enum_to_str (JOB_RUNNING, state);
2458
state_enum_to_str (JOB_PRE_STOPPING, state);
2180
2459
state_enum_to_str (JOB_PRE_STOP, state);
2181
2460
state_enum_to_str (JOB_STOPPING, state);
2182
2461
state_enum_to_str (JOB_KILLED, state);
2462
state_enum_to_str (JOB_POST_STOPPING, state);
2183
2463
state_enum_to_str (JOB_POST_STOP, state);
2195
2475
* Returns: JobState representation of @state, or -1 if not known.
2198
2478
job_state_str_to_enum (const char *state)
2200
2480
state_str_to_enum (JOB_WAITING, state);
2201
2481
state_str_to_enum (JOB_STARTING, state);
2202
2482
state_str_to_enum (JOB_SECURITY, state);
2483
state_str_to_enum (JOB_PRE_STARTING, state);
2203
2484
state_str_to_enum (JOB_PRE_START, state);
2485
state_str_to_enum (JOB_SPAWNING, state);
2204
2486
state_str_to_enum (JOB_SPAWNED, state);
2487
state_str_to_enum (JOB_POST_STARTING, state);
2205
2488
state_str_to_enum (JOB_POST_START, state);
2206
2489
state_str_to_enum (JOB_RUNNING, state);
2490
state_str_to_enum (JOB_PRE_STOPPING, state);
2207
2491
state_str_to_enum (JOB_PRE_STOP, state);
2208
2492
state_str_to_enum (JOB_STOPPING, state);
2209
2493
state_str_to_enum (JOB_KILLED, state);
2494
state_str_to_enum (JOB_POST_STOPPING, state);
2210
2495
state_str_to_enum (JOB_POST_STOP, state);
2364
* job_error_handler:
2649
* job_child_error_handler:
2367
* @state: state job was trying to move to,
2368
2652
* @process: process that failed to start.
2370
2654
* JobProcessErrorHandler that deals with errors resulting from
2371
2655
* a failure to start a job process.
2374
job_error_handler (Job *job, JobState state, ProcessType process)
2658
job_child_error_handler (Job *job, ProcessType process)
2376
2660
nih_assert (job);
2377
2661
nih_assert (process > PROCESS_INVALID);
2378
2662
nih_assert (process < PROCESS_LAST);
2666
nih_message ("XXX:%s:%d: job: %s, state=%s, goal=%s, process=%s",
2669
job_state_name (job->state),
2670
job_goal_name (job->goal),
2671
process_name (process));
2380
2674
switch (process) {
2381
2675
case PROCESS_SECURITY:
2382
2676
job_failed (job, PROCESS_SECURITY, -1);