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

« back to all changes in this revision

Viewing changes to init/state.c

  • Committer: Steve Langasek
  • Date: 2013-11-07 03:06:51 UTC
  • Revision ID: steve.langasek@canonical.com-20131107030651-f1jzeyi7ifvvw1h8
Attempt to cherry-pick fixes for bug #1199778 to raring; something is still
missing though, the test suite segfaults on one of the json loads.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
20
 */    
21
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
# include <config.h>
 
24
#endif /* HAVE_CONFIG_H */
 
25
 
22
26
#include <string.h>
23
27
#include <sys/types.h>
24
28
#include <signal.h>
76
80
int write_state_file = FALSE;
77
81
 
78
82
/* Prototypes for static functions */
79
 
static JobClass *
80
 
state_index_to_job_class (int job_class_index)
81
 
        __attribute__ ((warn_unused_result));
82
 
 
83
83
static void state_write_file (NihIoBuffer *buffer);
84
84
 
85
85
/**
455
455
                        goto out;
456
456
                }
457
457
        } else {
458
 
                        nih_warn ("%s", _("No ConfSources present in state data"));
 
458
                nih_warn ("%s", _("No ConfSources present in state data"));
459
459
        }
460
460
 
461
461
        if (job_class_deserialise_all (json) < 0) {
1178
1178
int
1179
1179
state_deserialise_resolve_deps (json_object *json)
1180
1180
{
 
1181
        int  session_index = -1;
 
1182
 
1181
1183
        nih_assert (json);
1182
1184
 
1183
1185
        /* XXX: Sessions, Events, JobClasses, Jobs and DBusConnections
1208
1210
        }
1209
1211
 
1210
1212
        for (int i = 0; i < json_object_array_length (json_classes); i++) {
1211
 
                json_object  *json_class;
1212
 
                json_object  *json_jobs;
1213
 
                JobClass     *class = NULL;
 
1213
                json_object     *json_class;
 
1214
                json_object     *json_jobs;
 
1215
                JobClass        *class = NULL;
 
1216
                nih_local char  *class_name = NULL;
 
1217
                Session         *session;
 
1218
 
 
1219
                session_index = -1;
1214
1220
 
1215
1221
                json_class = json_object_array_get_idx (json_classes, i);
1216
1222
                if (! json_class)
1218
1224
 
1219
1225
                if (! state_check_json_type (json_class, object))
1220
1226
                        goto error;
 
1227
                
 
1228
                if (! state_get_json_int_var (json_class, "session", session_index))
 
1229
                        goto error;
 
1230
 
 
1231
                if (session_index > 0) {
 
1232
                        /* Although ConfSources are now serialised,
 
1233
                         * skip JobClasses with associated user/chroot
 
1234
                         * sessions to avoid behavioural changes for
 
1235
                         * the time being.
 
1236
                         */
 
1237
                        continue;
 
1238
                }
 
1239
 
 
1240
                session = session_from_index (session_index);
 
1241
 
 
1242
                /* All (non-NULL) sessions should already exist */
 
1243
                if (session_index > 0 && ! session)
 
1244
                        goto error;
 
1245
 
 
1246
                if (! state_get_json_string_var_strict (json_class, "name", NULL, class_name))
 
1247
                        goto error;
1221
1248
 
1222
1249
                /* lookup class associated with JSON class index */
1223
 
                class = state_index_to_job_class (i);
1224
 
                if (! class) {
1225
 
                        int session_index = -1;
1226
 
 
1227
 
                        if (state_get_json_int_var (json_class, "session", session_index)
1228
 
                                        && session_index > 0) {
1229
 
 
1230
 
                                /* Although ConfSources are now serialised, ignore
1231
 
                                 * JobClasses with associated user/chroot sessions to avoid
1232
 
                                 * behavioural changes for the time being.
1233
 
                                 */
1234
 
                                continue;
1235
 
                        } else {
1236
 
                                goto error;
1237
 
                        }
1238
 
                }
 
1250
                class = job_class_get_registered (class_name, session);
 
1251
 
 
1252
                if (! class)
 
1253
                        goto error;
 
1254
 
 
1255
                /* Sessions have been ignored, but handle the impossible
 
1256
                 * anyway.
 
1257
                 */
 
1258
                if (class->session)
 
1259
                        goto error;
1239
1260
 
1240
1261
                if (! state_get_json_var_full (json_class, "jobs", array, json_jobs))
1241
1262
                        goto error;
1729
1750
}
1730
1751
 
1731
1752
/**
1732
 
 * state_index_to_job_class:
1733
 
 *
1734
 
 * @job_class_index: job class index number.
1735
 
 *
1736
 
 * Lookup JobClass based on JSON array index number.
1737
 
 *
1738
 
 * Returns: existing JobClass on success, or NULL if JobClass not found.
1739
 
 **/
1740
 
static JobClass *
1741
 
state_index_to_job_class (int job_class_index)
1742
 
{
1743
 
        int     i = 0;
1744
 
 
1745
 
        nih_assert (job_class_index >= 0);
1746
 
        nih_assert (job_classes);
1747
 
 
1748
 
        NIH_HASH_FOREACH (job_classes, iter) {
1749
 
                JobClass *class = (JobClass *)iter;
1750
 
 
1751
 
                if (i == job_class_index)
1752
 
                        return class;
1753
 
 
1754
 
                i++;
1755
 
        }
1756
 
 
1757
 
        return NULL;
1758
 
}
1759
 
 
1760
 
/**
1761
1753
 * state_data_to_hex:
1762
1754
 *
1763
1755
 * @parent: parent,