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

« back to all changes in this revision

Viewing changes to init/parse_job.c

* init/job_class.h (JobClass): Replace oom_adj with oom_score_adj
* init/job_class.c (job_class_new): Replace oom_adj with oom_score_adj.
* init/job_process.c (job_process_spawn): Write the new score
adjustment, falling back to calculating and writing the old value if
necessary.
* init/parse_job.c (stanza_oom): Parse both the new and old values,
converting the old value to the new value if present.
* init/errors.h: Add new error string.
* init/man/init.5: Documentation update.
* init/tests/test_job_class.c (test_new): Update check.
* init/tests/test_parse_job.c (test_stanza_oom): Update tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2233
2233
        nih_local char *arg = NULL;
2234
2234
        char           *endptr;
2235
2235
        size_t          a_pos, a_lineno;
 
2236
        int             oom_adj;
2236
2237
        int             ret = -1;
2237
2238
 
2238
2239
        nih_assert (class != NULL);
2247
2248
        if (! arg)
2248
2249
                goto finish;
2249
2250
 
2250
 
        if (! strcmp (arg, "never")) {
2251
 
                class->oom_adj = -17;
 
2251
        if (! strcmp (arg, "score")) {
 
2252
                nih_local char *scorearg = NULL;
 
2253
 
 
2254
                /* Update error position to the score value */
 
2255
                *pos = a_pos;
 
2256
                if (lineno)
 
2257
                        *lineno = a_lineno;
 
2258
 
 
2259
                scorearg = nih_config_next_arg (NULL, file, len,
 
2260
                                                &a_pos, &a_lineno);
 
2261
                if (! scorearg)
 
2262
                        goto finish;
 
2263
 
 
2264
                if (! strcmp (scorearg, "never")) {
 
2265
                        class->oom_score_adj = -1000;
 
2266
                } else {
 
2267
                        errno = 0;
 
2268
                        class->oom_score_adj = (int)strtol (scorearg, &endptr, 10);
 
2269
                        if (errno || *endptr ||
 
2270
                            (class->oom_score_adj < -1000) ||
 
2271
                            (class->oom_score_adj > 1000))
 
2272
                                nih_return_error (-1, PARSE_ILLEGAL_OOM,
 
2273
                                                  _(PARSE_ILLEGAL_OOM_SCORE_STR));
 
2274
                }
 
2275
        } else if (! strcmp (arg, "never")) {
 
2276
                class->oom_score_adj = -1000;
2252
2277
        } else {
2253
2278
                errno = 0;
2254
 
                class->oom_adj = (int)strtol (arg, &endptr, 10);
2255
 
                if (errno || *endptr || (class->oom_adj < -17) || (class->oom_adj > 15))
 
2279
                oom_adj = (int)strtol (arg, &endptr, 10);
 
2280
                class->oom_score_adj = (oom_adj * 1000) / ((oom_adj < 0) ? 17 : 15);
 
2281
                if (errno || *endptr || (oom_adj < -17) || (oom_adj > 15))
2256
2282
                        nih_return_error (-1, PARSE_ILLEGAL_OOM,
2257
2283
                                          _(PARSE_ILLEGAL_OOM_STR));
2258
2284
        }