~jamesodhunt/upstart/serialise-remaining-objects

« back to all changes in this revision

Viewing changes to init/state.c

  • Committer: James Hunt
  • Date: 2013-05-10 13:17:33 UTC
  • Revision ID: james.hunt@ubuntu.com-20130510131733-n04137py44o5cxzf
Revert to not supporting deserialisation of JobClasses with associated
user/chroot sessions to avoid behavioural change for now.

* init/job_class.c: 
  - job_class_deserialise(): Revert to failing if associated session is
    non-NULL.
  - job_class_deserialise_all(): Revert to ignoring failure to
    deserialise a JobClass iff it has a non-NULL associated session.
* init/state.c: 
  - state_to_string(): Provide some diagnostics if serialisation fails.
  - state_from_string(): Provide some diagnostics if deserialisation fails.
  - state_deserialise_resolve_deps(): Ignore failure to lookup JobClass
    iff it has an associated user/chroot session.
  - state_deserialise_blocking(): Revert to ignoring failure to
    deserialise a Blocked object that is associated with a Job whose
    JobClass has a non-NULL session.
* init/tests/test_state.c: test_blocking(): Revert test to assert that
  blocked job with non-NULL session is ignored.

Show diffs side-by-side

added added

removed removed

Lines of Context:
371
371
                return -1;
372
372
 
373
373
        json_header = state_create_header ();
374
 
        if (! json_header)
 
374
        if (! json_header) {
 
375
                nih_error ("%s header", _("Failed to serialise"));
375
376
                goto error;
 
377
        }
376
378
 
377
379
        json_object_object_add (json, "header", json_header);
378
380
 
379
381
        json_sessions = session_serialise_all ();
380
 
        if (! json_sessions)
 
382
        if (! json_sessions) {
 
383
                nih_error ("%s Sessions", _("Failed to serialise"));
381
384
                goto error;
 
385
        }
382
386
 
383
387
        json_object_object_add (json, "sessions", json_sessions);
384
388
 
385
389
        json_events = event_serialise_all ();
386
 
        if (! json_events)
 
390
        if (! json_events) {
 
391
                nih_error ("%s Events", _("Failed to serialise"));
387
392
                goto error;
 
393
        }
388
394
 
389
395
        json_object_object_add (json, "events", json_events);
390
396
 
391
397
        json_classes = job_class_serialise_all ();
392
398
 
393
 
        if (! json_classes)
 
399
        if (! json_classes) {
 
400
                nih_error ("%s JobClasses", _("Failed to serialise"));
394
401
                goto error;
 
402
        }
395
403
 
396
404
        json_object_object_add (json, "job_classes", json_classes);
397
405
 
398
406
        json_conf_sources = conf_source_serialise_all ();
399
407
 
400
 
        if (! json_conf_sources)
 
408
        if (! json_conf_sources) {
 
409
                nih_error ("%s ConfSources", _("Failed to serialise"));
401
410
                goto error;
 
411
        }
402
412
 
403
413
        json_object_object_add (json, "conf_sources", json_conf_sources);
404
414
 
462
472
        if (state_read_header (json) < 0)
463
473
                nih_warn ("%s", _("No header present in state data"));
464
474
 
465
 
        if (session_deserialise_all (json) < 0)
 
475
        if (session_deserialise_all (json) < 0) {
 
476
                nih_error ("%s Sessions", _("Failed to deserialise"));
466
477
                goto out;
 
478
        }
467
479
 
468
 
        if (event_deserialise_all (json) < 0)
 
480
        if (event_deserialise_all (json) < 0) {
 
481
                nih_error ("%s Events", _("Failed to deserialise"));
469
482
                goto out;
 
483
        }
470
484
 
471
485
        /* Again, we cannot error here since older JSON state data did
472
486
         * not encode ConfSource or ConfFile objects.
474
488
        if (conf_source_deserialise_all (json) < 0)
475
489
                nih_warn ("%s", _("No ConfSources present in state data"));
476
490
 
477
 
        if (job_class_deserialise_all (json) < 0)
 
491
        if (job_class_deserialise_all (json) < 0) {
 
492
                nih_error ("%s JobClasses", _("Failed to deserialise"));
478
493
                goto out;
 
494
        }
479
495
 
480
 
        if (state_deserialise_resolve_deps (json) < 0)
 
496
        if (state_deserialise_resolve_deps (json) < 0) {
 
497
                nih_error (_("Failed to resolve deserialisation dependencies"));
481
498
                goto out;
 
499
        }
482
500
 
483
501
        ret = 0;
484
502
 
1233
1251
 
1234
1252
                /* lookup class associated with JSON class index */
1235
1253
                class = state_index_to_job_class (i);
1236
 
                if (! class)
1237
 
                        goto error;
 
1254
                if (! class) {
 
1255
                        int session_index = -1;
 
1256
 
 
1257
                        if (state_get_json_int_var (json_class, "session", session_index)
 
1258
                                        && session_index > 0) {
 
1259
 
 
1260
                                /* Although ConfSources are now serialised, ignore
 
1261
                                 * JobClasses with associated user/chroot sessions to avoid
 
1262
                                 * behavioural changes for the time being.
 
1263
                                 */
 
1264
                                continue;
 
1265
                        } else {
 
1266
                                goto error;
 
1267
                        }
 
1268
                }
1238
1269
 
1239
1270
                if (! state_get_json_var_full (json_class, "jobs", array, json_jobs))
1240
1271
                        goto error;
1712
1743
                if (! json_blocked)
1713
1744
                        goto error;
1714
1745
 
 
1746
                /* Don't error in this scenario to allow for possibility
 
1747
                 * that version of Upstart that performed the
 
1748
                 * serialisation did not correctly handle user and
 
1749
                 * chroot jobs.
 
1750
                 */
1715
1751
                if (! state_deserialise_blocked (parent, json_blocked, list))
1716
 
                        goto error;
 
1752
                        ;
1717
1753
        }
1718
1754
 
1719
1755
        return 0;