Merge lp:~jamesodhunt/upstart/fix-job_find into lp:upstart

Proposed by James Hunt
Status: Merged
Merged at revision: 1599
Proposed branch: lp:~jamesodhunt/upstart/fix-job_find
Merge into: lp:upstart
Diff against target: 877 lines (+708/-20)
6 files modified
ChangeLog (+24/-0)
init/control.c (+29/-13)
init/control.h (+6/-5)
init/job.c (+3/-0)
init/tests/test_control.c (+527/-2)
init/tests/test_job.c (+119/-0)
To merge this branch: bzr merge lp:~jamesodhunt/upstart/fix-job_find
Reviewer Review Type Date Requested Status
Upstart Reviewers Pending
Review via email: mp+195632@code.launchpad.net

Description of the change

Fixes a bug that could cause a Session Init to crash.

To post a comment you must log in.
lp:~jamesodhunt/upstart/fix-job_find updated
1574. By James Hunt

* Sync with lp:upstart.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2013-11-18 10:31:21 +0000
+++ ChangeLog 2013-11-18 16:45:10 +0000
@@ -1,3 +1,27 @@
12013-11-18 James Hunt <james.hunt@ubuntu.com>
2
3 * init/control.c:
4 - control_set_env():
5 - Check permissions before anything else.
6 - Explicit check on @var rather than an assert.
7 - control_unset_env(): Explicit check on @name rather than an assert.
8 - control_get_env(): Explicit check on @name.
9 - control_reset_env(): Check permissions before anything else.
10 * init/control.h: control_get_job():
11 - Pass @job_name to job_find() rather than hard-coded NULL.
12 - Handle instance being NULL when raising NIH D-Bus error.
13 * init/job.c: job_find(): Handle NULL job_name.
14 * init/tests/test_control.c:
15 - Typo.
16 - New functions:
17 - test_list_env().
18 - test_list_env().
19 - test_get_env().
20 - test_set_env().
21 - test_unset_env().
22 - test_reset_env().
23 * init/tests/test_job.c: test_job_find(): New function.
24
12013-11-16 Dmitrijs Ledkovs <xnox@ubuntu.com>252013-11-16 Dmitrijs Ledkovs <xnox@ubuntu.com>
226
3 * init/xdg.c, util/Makefile.am, test/Makefile.am, init/conf.c:27 * init/xdg.c, util/Makefile.am, test/Makefile.am, init/conf.c:
428
=== modified file 'init/control.c'
--- init/control.c 2013-11-05 16:15:19 +0000
+++ init/control.c 2013-11-18 16:45:10 +0000
@@ -1288,7 +1288,13 @@
12881288
1289 nih_assert (message);1289 nih_assert (message);
1290 nih_assert (job_details);1290 nih_assert (job_details);
1291 nih_assert (var);1291
1292 if (! control_check_permission (message)) {
1293 nih_dbus_error_raise_printf (
1294 DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
1295 _("You do not have permission to modify job environment"));
1296 return -1;
1297 }
12921298
1293 if (job_details[0]) {1299 if (job_details[0]) {
1294 job_name = job_details[0];1300 job_name = job_details[0];
@@ -1302,10 +1308,9 @@
1302 return -1;1308 return -1;
1303 }1309 }
13041310
1305 if (! control_check_permission (message)) {1311 if (! var || ! *var) {
1306 nih_dbus_error_raise_printf (1312 nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
1307 DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",1313 _("Variable may not be empty string"));
1308 _("You do not have permission to modify job environment"));
1309 return -1;1314 return -1;
1310 }1315 }
13111316
@@ -1386,7 +1391,6 @@
13861391
1387 nih_assert (message);1392 nih_assert (message);
1388 nih_assert (job_details);1393 nih_assert (job_details);
1389 nih_assert (name);
13901394
1391 if (! control_check_permission (message)) {1395 if (! control_check_permission (message)) {
1392 nih_dbus_error_raise_printf (1396 nih_dbus_error_raise_printf (
@@ -1395,6 +1399,12 @@
1395 return -1;1399 return -1;
1396 }1400 }
13971401
1402 if (! name || ! *name) {
1403 nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
1404 _("Variable may not be empty string"));
1405 return -1;
1406 }
1407
1398 if (job_details[0]) {1408 if (job_details[0]) {
1399 job_name = job_details[0];1409 job_name = job_details[0];
14001410
@@ -1490,6 +1500,12 @@
1490 return -1;1500 return -1;
1491 }1501 }
14921502
1503 if (! name || ! *name) {
1504 nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
1505 _("Variable may not be empty string"));
1506 return -1;
1507 }
1508
1493 if (job_details[0]) {1509 if (job_details[0]) {
1494 job_name = job_details[0];1510 job_name = job_details[0];
14951511
@@ -1649,6 +1665,13 @@
1649 nih_assert (message);1665 nih_assert (message);
1650 nih_assert (job_details);1666 nih_assert (job_details);
16511667
1668 if (! control_check_permission (message)) {
1669 nih_dbus_error_raise_printf (
1670 DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
1671 _("You do not have permission to modify job environment"));
1672 return -1;
1673 }
1674
1652 if (job_details[0]) {1675 if (job_details[0]) {
1653 job_name = job_details[0];1676 job_name = job_details[0];
16541677
@@ -1661,13 +1684,6 @@
1661 return -1;1684 return -1;
1662 }1685 }
16631686
1664 if (! control_check_permission (message)) {
1665 nih_dbus_error_raise_printf (
1666 DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
1667 _("You do not have permission to modify job environment"));
1668 return -1;
1669 }
1670
1671 /* Verify that job name is valid */1687 /* Verify that job name is valid */
1672 if (job_name && ! strlen (job_name)) {1688 if (job_name && ! strlen (job_name)) {
1673 nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,1689 nih_dbus_error_raise_printf (DBUS_ERROR_INVALID_ARGS,
16741690
=== modified file 'init/control.h'
--- init/control.h 2013-10-25 13:49:49 +0000
+++ init/control.h 2013-11-18 16:45:10 +0000
@@ -1,6 +1,6 @@
1/* upstart1/* upstart
2 *2 *
3 * Copyright 2009-2011 Canonical Ltd.3 * Copyright © 2009-2011 Canonical Ltd.
4 * Author: Scott James Remnant <scott@netsplit.com>.4 * Author: Scott James Remnant <scott@netsplit.com>.
5 *5 *
6 * This program is free software; you can redistribute it and/or modify6 * This program is free software; you can redistribute it and/or modify
@@ -60,7 +60,7 @@
60 **/60 **/
61#define control_get_job(session, job, job_name, instance) \61#define control_get_job(session, job, job_name, instance) \
62{ \62{ \
63 if (job_name != NULL ) { \63 if (job_name) { \
64 JobClass *class; \64 JobClass *class; \
65 \65 \
66 class = job_class_get_registered (job_name, session); \66 class = job_class_get_registered (job_name, session); \
@@ -73,13 +73,14 @@
73 return -1; \73 return -1; \
74 } \74 } \
75 \75 \
76 job = job_find (session, class, NULL, instance); \76 job = job_find (session, class, job_name, instance); \
77 if (job == NULL) { \77 if (! job) { \
78 nih_dbus_error_raise_printf ( \78 nih_dbus_error_raise_printf ( \
79 DBUS_INTERFACE_UPSTART \79 DBUS_INTERFACE_UPSTART \
80 ".Error.UnknownJobInstance", \80 ".Error.UnknownJobInstance", \
81 _("Unknown instance: %s of job %s"), \81 _("Unknown instance: %s of job %s"), \
82 instance, job_name); \82 instance ? instance : "(null)", \
83 job_name); \
83 return -1; \84 return -1; \
84 } \85 } \
85 } \86 } \
8687
=== modified file 'init/job.c'
--- init/job.c 2013-08-21 11:07:36 +0000
+++ init/job.c 2013-11-18 16:45:10 +0000
@@ -2350,6 +2350,9 @@
2350 nih_assert (class || job_class);2350 nih_assert (class || job_class);
2351 nih_assert (job_classes);2351 nih_assert (job_classes);
23522352
2353 if (! job_name)
2354 goto error;
2355
2353 if (! class)2356 if (! class)
2354 class = job_class_get_registered (job_class, session);2357 class = job_class_get_registered (job_class, session);
23552358
23562359
=== modified file 'init/tests/test_control.c'
--- init/tests/test_control.c 2013-10-25 13:49:49 +0000
+++ init/tests/test_control.c 2013-11-18 16:45:10 +0000
@@ -61,9 +61,10 @@
61#include "control.h"61#include "control.h"
62#include "errors.h"62#include "errors.h"
6363
64#include "test_util_common.h"
6465
65extern const char *control_server_address;66extern const char *control_server_address;
6667extern int no_inherit_env;
6768
68void69void
69test_server_open (void)70test_server_open (void)
@@ -933,7 +934,7 @@
933 strcat (filename, "/baz");934 strcat (filename, "/baz");
934935
935 /* XXX: note that this will generate an error message when this936 /* XXX: note that this will generate an error message when this
936 * test runs sine "/baz" does not exist as a directory.937 * test runs since "/baz" does not exist as a directory.
937 */938 */
938 source3 = conf_source_new (NULL, filename, CONF_DIR);939 source3 = conf_source_new (NULL, filename, CONF_DIR);
939940
@@ -2176,6 +2177,524 @@
2176 nih_log_priority = NIH_LOG_UNKNOWN;2177 nih_log_priority = NIH_LOG_UNKNOWN;
2177}2178}
21782179
2180void
2181test_list_env (void)
2182{
2183 NihDBusMessage *message = NULL;
2184 int ret;
2185 nih_local char **env = NULL;
2186 nih_local char **job_details = NULL;
2187 nih_local char **job_details2 = NULL;
2188 JobClass *class;
2189 Job *job;
2190 NihError *error;
2191
2192 TEST_FUNCTION ("control_list_env");
2193
2194 nih_error_init ();
2195 job_class_init ();
2196 job_class_environment_init ();
2197
2198 no_inherit_env = TRUE;
2199
2200 message = nih_new (NULL, NihDBusMessage);
2201 TEST_NE_P (message, NULL);
2202 message->connection = NULL;
2203 message->message = NULL;
2204
2205 job_details = nih_str_array_new (NULL);
2206 nih_assert (job_details);
2207
2208 class = job_class_new (NULL, "foo", NULL);
2209 TEST_NE_P (class, NULL);
2210
2211 job = job_new (class, "");
2212 TEST_NE_P (job, NULL);
2213
2214 nih_hash_add (job_classes, &class->entry);
2215
2216 assert0 (job_class_environment_set ("hello=world", TRUE));
2217
2218 /************************************************************/
2219 TEST_FEATURE ("with empty array");
2220
2221 ret = control_list_env (NULL, message, job_details, &env);
2222 TEST_EQ (ret, 0);
2223
2224 /* Default variables that Upstart adds */
2225 TEST_STR_MATCH (env[0], "PATH=*");
2226 TEST_STR_MATCH (env[1], "TERM=*");
2227
2228 TEST_EQ_STR (env[2], "hello=world");
2229 TEST_EQ_P (env[3], NULL);
2230
2231 /************************************************************/
2232 TEST_FEATURE ("with empty job class name");
2233
2234 job_details2 = nih_str_array_copy (NULL, NULL, job_details);
2235 TEST_NE_P (job_details2, NULL);
2236
2237 nih_assert (nih_str_array_add (&job_details2,
2238 NULL,
2239 NULL,
2240 ""));
2241
2242 ret = control_list_env (NULL, message, job_details2, &env);
2243 TEST_LT (ret, 0);
2244
2245 error = nih_error_get ();
2246 TEST_EQ (error->number, NIH_DBUS_ERROR);
2247 nih_free (error);
2248
2249 /************************************************************/
2250 TEST_FEATURE ("with missing instance name");
2251
2252 /* add name */
2253 nih_assert (nih_str_array_add (&job_details,
2254 NULL,
2255 NULL,
2256 "foo"));
2257
2258 ret = control_list_env (NULL, message, job_details, &env);
2259 TEST_LT (ret, 0);
2260
2261 error = nih_error_get ();
2262 TEST_EQ (error->number, NIH_DBUS_ERROR);
2263 nih_free (error);
2264
2265 /************************************************************/
2266 /* We can't wrap this in a TEST_ALLOC_FAIL() block since the
2267 * nih_dbus_*() calls such as nih_dbus_error_raise_printf() use
2268 * NIH_MUST() which defeats the fail macro
2269 */
2270 TEST_FEATURE ("with correct job details");
2271
2272 /* add instance */
2273 nih_assert (nih_str_array_add (&job_details,
2274 NULL,
2275 NULL,
2276 ""));
2277
2278 ret = control_list_env (NULL, message, job_details, &env);
2279 TEST_EQ (ret, 0);
2280
2281 nih_free (message);
2282}
2283
2284void
2285test_get_env (void)
2286{
2287 NihDBusMessage *message = NULL;
2288 int ret;
2289 char *value = NULL;
2290 nih_local char **job_details = NULL;
2291 nih_local char **job_details2 = NULL;
2292 JobClass *class;
2293 Job *job;
2294 NihError *error;
2295
2296 TEST_FUNCTION ("control_get_env");
2297
2298 nih_error_init ();
2299 job_class_init ();
2300 job_class_environment_init ();
2301
2302 no_inherit_env = TRUE;
2303
2304 message = nih_new (NULL, NihDBusMessage);
2305 TEST_NE_P (message, NULL);
2306 message->connection = NULL;
2307 message->message = NULL;
2308
2309 job_details = nih_str_array_new (NULL);
2310 nih_assert (job_details);
2311
2312 job_details2 = nih_str_array_copy (NULL, NULL, job_details);
2313 TEST_NE_P (job_details2, NULL);
2314
2315 nih_assert (nih_str_array_add (&job_details2,
2316 NULL,
2317 NULL,
2318 ""));
2319
2320 class = job_class_new (NULL, "foo", NULL);
2321 TEST_NE_P (class, NULL);
2322
2323 job = job_new (class, "");
2324 TEST_NE_P (job, NULL);
2325
2326 nih_hash_add (job_classes, &class->entry);
2327
2328 assert0 (job_class_environment_set ("hello=world", TRUE));
2329
2330 /************************************************************/
2331 TEST_FEATURE ("with NULL variable name");
2332
2333 ret = control_get_env (NULL, message, job_details2, NULL, &value);
2334 TEST_LT (ret, 0);
2335
2336 error = nih_error_get ();
2337 TEST_EQ (error->number, NIH_DBUS_ERROR);
2338 nih_free (error);
2339
2340 /************************************************************/
2341 TEST_FEATURE ("with empty variable name");
2342
2343 ret = control_get_env (NULL, message, job_details2, "", &value);
2344 TEST_LT (ret, 0);
2345
2346 error = nih_error_get ();
2347 TEST_EQ (error->number, NIH_DBUS_ERROR);
2348 nih_free (error);
2349
2350 /************************************************************/
2351 TEST_FEATURE ("with empty job class name");
2352
2353 ret = control_get_env (NULL, message, job_details2, "hello", &value);
2354 TEST_LT (ret, 0);
2355
2356 error = nih_error_get ();
2357 TEST_EQ (error->number, NIH_DBUS_ERROR);
2358 nih_free (error);
2359
2360 /************************************************************/
2361 TEST_FEATURE ("with missing instance name");
2362
2363 /* add name */
2364 nih_assert (nih_str_array_add (&job_details,
2365 NULL,
2366 NULL,
2367 "foo"));
2368
2369 ret = control_get_env (NULL, message, job_details, "hello", &value);
2370 TEST_LT (ret, 0);
2371
2372 error = nih_error_get ();
2373 TEST_EQ (error->number, NIH_DBUS_ERROR);
2374 nih_free (error);
2375
2376 /************************************************************/
2377 TEST_FEATURE ("with correct job details");
2378
2379 /* add instance */
2380 nih_assert (nih_str_array_add (&job_details,
2381 NULL,
2382 NULL,
2383 ""));
2384
2385 ret = control_get_env (NULL, message, job_details, "hello", &value);
2386 TEST_EQ (ret, 0);
2387 TEST_EQ_STR (value, "world");
2388
2389 /************************************************************/
2390 /* tidy up */
2391
2392 nih_free (value);
2393 nih_free (message);
2394}
2395
2396void
2397test_set_env (void)
2398{
2399 NihDBusMessage *message = NULL;
2400 int ret;
2401 nih_local char **job_details = NULL;
2402 nih_local char **job_details2 = NULL;
2403 JobClass *class;
2404 Job *job;
2405 NihError *error;
2406
2407 TEST_FUNCTION ("control_set_env");
2408
2409 nih_error_init ();
2410 job_class_init ();
2411 job_class_environment_init ();
2412
2413 no_inherit_env = TRUE;
2414
2415 message = nih_new (NULL, NihDBusMessage);
2416 TEST_NE_P (message, NULL);
2417 message->connection = NULL;
2418 message->message = NULL;
2419
2420 job_details = nih_str_array_new (NULL);
2421 nih_assert (job_details);
2422
2423 job_details2 = nih_str_array_copy (NULL, NULL, job_details);
2424 TEST_NE_P (job_details2, NULL);
2425
2426 nih_assert (nih_str_array_add (&job_details2,
2427 NULL,
2428 NULL,
2429 ""));
2430
2431 class = job_class_new (NULL, "foo", NULL);
2432 TEST_NE_P (class, NULL);
2433
2434 job = job_new (class, "");
2435 TEST_NE_P (job, NULL);
2436
2437 nih_hash_add (job_classes, &class->entry);
2438
2439 /************************************************************/
2440 TEST_FEATURE ("with NULL variable name");
2441
2442 ret = control_set_env (NULL, message, job_details2, NULL, TRUE);
2443 TEST_LT (ret, 0);
2444
2445 error = nih_error_get ();
2446 TEST_EQ (error->number, NIH_DBUS_ERROR);
2447 nih_free (error);
2448
2449 /************************************************************/
2450 TEST_FEATURE ("with empty variable name");
2451
2452 ret = control_set_env (NULL, message, job_details2, "", TRUE);
2453 TEST_LT (ret, 0);
2454
2455 error = nih_error_get ();
2456 TEST_EQ (error->number, NIH_DBUS_ERROR);
2457 nih_free (error);
2458
2459 /************************************************************/
2460 TEST_FEATURE ("with empty job class name");
2461
2462 ret = control_set_env (NULL, message, job_details2, "hello=world", TRUE);
2463 TEST_LT (ret, 0);
2464
2465 error = nih_error_get ();
2466 TEST_EQ (error->number, NIH_DBUS_ERROR);
2467 nih_free (error);
2468
2469 /************************************************************/
2470 TEST_FEATURE ("with missing instance name");
2471
2472 /* add name */
2473 nih_assert (nih_str_array_add (&job_details,
2474 NULL,
2475 NULL,
2476 "foo"));
2477
2478 ret = control_set_env (NULL, message, job_details, "hello=world", TRUE);
2479 TEST_LT (ret, 0);
2480
2481 error = nih_error_get ();
2482 TEST_EQ (error->number, NIH_DBUS_ERROR);
2483 nih_free (error);
2484
2485 /************************************************************/
2486 TEST_FEATURE ("with correct job details");
2487
2488 /* add instance */
2489 nih_assert (nih_str_array_add (&job_details,
2490 NULL,
2491 NULL,
2492 ""));
2493
2494 ret = control_set_env (NULL, message, job_details, "hello=world", TRUE);
2495 TEST_EQ (ret, 0);
2496
2497 /************************************************************/
2498 /* tidy up */
2499
2500 nih_free (message);
2501}
2502
2503void
2504test_unset_env (void)
2505{
2506 NihDBusMessage *message = NULL;
2507 int ret;
2508 nih_local char **job_details = NULL;
2509 nih_local char **job_details2 = NULL;
2510 JobClass *class;
2511 Job *job;
2512 NihError *error;
2513
2514 TEST_FUNCTION ("control_unset_env");
2515
2516 nih_error_init ();
2517 job_class_init ();
2518 job_class_environment_init ();
2519
2520 no_inherit_env = TRUE;
2521
2522 message = nih_new (NULL, NihDBusMessage);
2523 TEST_NE_P (message, NULL);
2524 message->connection = NULL;
2525 message->message = NULL;
2526
2527 job_details = nih_str_array_new (NULL);
2528 nih_assert (job_details);
2529
2530 job_details2 = nih_str_array_copy (NULL, NULL, job_details);
2531 TEST_NE_P (job_details2, NULL);
2532
2533 nih_assert (nih_str_array_add (&job_details2,
2534 NULL,
2535 NULL,
2536 ""));
2537
2538 class = job_class_new (NULL, "foo", NULL);
2539 TEST_NE_P (class, NULL);
2540
2541 job = job_new (class, "");
2542 TEST_NE_P (job, NULL);
2543
2544 nih_hash_add (job_classes, &class->entry);
2545
2546 assert0 (job_class_environment_set ("hello=world", TRUE));
2547
2548 /************************************************************/
2549 TEST_FEATURE ("with NULL variable name");
2550
2551 ret = control_unset_env (NULL, message, job_details2, NULL);
2552 TEST_LT (ret, 0);
2553
2554 error = nih_error_get ();
2555 TEST_EQ (error->number, NIH_DBUS_ERROR);
2556 nih_free (error);
2557
2558 /************************************************************/
2559 TEST_FEATURE ("with empty variable name");
2560
2561 ret = control_unset_env (NULL, message, job_details2, "");
2562 TEST_LT (ret, 0);
2563
2564 error = nih_error_get ();
2565 TEST_EQ (error->number, NIH_DBUS_ERROR);
2566 nih_free (error);
2567
2568 /************************************************************/
2569 TEST_FEATURE ("with empty job class name");
2570
2571 ret = control_unset_env (NULL, message, job_details2, "hello");
2572 TEST_LT (ret, 0);
2573
2574 error = nih_error_get ();
2575 TEST_EQ (error->number, NIH_DBUS_ERROR);
2576 nih_free (error);
2577
2578 /************************************************************/
2579 TEST_FEATURE ("with missing instance name");
2580
2581 /* add name */
2582 nih_assert (nih_str_array_add (&job_details,
2583 NULL,
2584 NULL,
2585 "foo"));
2586
2587 ret = control_unset_env (NULL, message, job_details, "hello");
2588 TEST_LT (ret, 0);
2589
2590 error = nih_error_get ();
2591 TEST_EQ (error->number, NIH_DBUS_ERROR);
2592 nih_free (error);
2593
2594 /************************************************************/
2595 TEST_FEATURE ("with correct job details");
2596
2597 /* add instance */
2598 nih_assert (nih_str_array_add (&job_details,
2599 NULL,
2600 NULL,
2601 ""));
2602
2603 ret = control_unset_env (NULL, message, job_details, "hello");
2604 TEST_EQ (ret, 0);
2605
2606 /************************************************************/
2607 /* tidy up */
2608
2609 nih_free (message);
2610}
2611
2612void
2613test_reset_env (void)
2614{
2615 NihDBusMessage *message = NULL;
2616 int ret;
2617 nih_local char **job_details = NULL;
2618 nih_local char **job_details2 = NULL;
2619 JobClass *class;
2620 Job *job;
2621 NihError *error;
2622
2623 TEST_FUNCTION ("control_reset_env");
2624
2625 nih_error_init ();
2626 job_class_init ();
2627 job_class_environment_init ();
2628
2629 no_inherit_env = TRUE;
2630
2631 message = nih_new (NULL, NihDBusMessage);
2632 TEST_NE_P (message, NULL);
2633 message->connection = NULL;
2634 message->message = NULL;
2635
2636 job_details = nih_str_array_new (NULL);
2637 nih_assert (job_details);
2638
2639 class = job_class_new (NULL, "foo", NULL);
2640 TEST_NE_P (class, NULL);
2641
2642 job = job_new (class, "");
2643 TEST_NE_P (job, NULL);
2644
2645 nih_hash_add (job_classes, &class->entry);
2646
2647 /************************************************************/
2648 TEST_FEATURE ("with empty job class name");
2649
2650 job_details2 = nih_str_array_copy (NULL, NULL, job_details);
2651 TEST_NE_P (job_details2, NULL);
2652
2653 nih_assert (nih_str_array_add (&job_details2,
2654 NULL,
2655 NULL,
2656 ""));
2657
2658 ret = control_reset_env (NULL, message, job_details2);
2659 TEST_LT (ret, 0);
2660
2661 error = nih_error_get ();
2662 TEST_EQ (error->number, NIH_DBUS_ERROR);
2663 nih_free (error);
2664
2665 /************************************************************/
2666 TEST_FEATURE ("with missing instance name");
2667
2668 /* add name */
2669 nih_assert (nih_str_array_add (&job_details,
2670 NULL,
2671 NULL,
2672 "foo"));
2673
2674 ret = control_reset_env (NULL, message, job_details);
2675 TEST_LT (ret, 0);
2676
2677 error = nih_error_get ();
2678 TEST_EQ (error->number, NIH_DBUS_ERROR);
2679 nih_free (error);
2680
2681 /************************************************************/
2682 TEST_FEATURE ("with correct job details");
2683
2684 /* add instance */
2685 nih_assert (nih_str_array_add (&job_details,
2686 NULL,
2687 NULL,
2688 ""));
2689
2690 ret = control_reset_env (NULL, message, job_details);
2691 TEST_EQ (ret, 0);
2692
2693 /************************************************************/
2694 /* tidy up */
2695
2696 nih_free (message);
2697}
21792698
2180int2699int
2181main (int argc,2700main (int argc,
@@ -2205,5 +2724,11 @@
2205 test_get_log_priority ();2724 test_get_log_priority ();
2206 test_set_log_priority ();2725 test_set_log_priority ();
22072726
2727 test_list_env ();
2728 test_get_env ();
2729 test_set_env ();
2730 test_unset_env ();
2731 test_reset_env ();
2732
2208 return 0;2733 return 0;
2209}2734}
22102735
=== modified file 'init/tests/test_job.c'
--- init/tests/test_job.c 2013-08-23 12:46:42 +0000
+++ init/tests/test_job.c 2013-11-18 16:45:10 +0000
@@ -7493,6 +7493,123 @@
7493 }7493 }
7494}7494}
74957495
7496void
7497test_job_find (void)
7498{
7499 ConfFile *file;
7500 ConfSource *source;
7501 Job *job, *ret;
7502 JobClass *class;
7503 Session *session;
7504
7505 TEST_FUNCTION ("job_find");
7506 nih_error_init ();
7507 conf_init ();
7508 job_class_init ();
7509
7510 TEST_HASH_EMPTY (job_classes);
7511
7512 source = conf_source_new (NULL, "/tmp", CONF_JOB_DIR);
7513 TEST_NE_P (source, NULL);
7514
7515 file = conf_file_new (source, "/tmp/test");
7516 TEST_NE_P (file, NULL);
7517
7518 class = file->job = job_class_new (NULL, "test", NULL);
7519 TEST_NE_P (class, NULL);
7520
7521 job = job_new (class, "");
7522 TEST_NE_P (job, NULL);
7523
7524 TEST_HASH_EMPTY (job_classes);
7525 TEST_TRUE (job_class_consider (class));
7526 TEST_HASH_NOT_EMPTY (job_classes);
7527
7528 /***********************************************************/
7529 TEST_FEATURE ("JobClass, no job name or Session");
7530
7531 ret = job_find (NULL, class, NULL, NULL);
7532 TEST_EQ_P (ret, NULL);
7533
7534 /***********************************************************/
7535 TEST_FEATURE ("job class name, no job name or Session");
7536
7537 ret = job_find (NULL, NULL, "test", NULL);
7538 TEST_EQ_P (ret, NULL);
7539
7540 /***********************************************************/
7541 TEST_FEATURE ("JobClass+job name, no Session");
7542
7543 ret = job_find (NULL, class, NULL, "");
7544 TEST_EQ (ret, job);
7545
7546 /***********************************************************/
7547 TEST_FEATURE ("job class name+job name, no Session");
7548
7549 ret = job_find (NULL, NULL, "test", "");
7550 TEST_EQ (ret, job);
7551
7552 /***********************************************************/
7553 /* recreate env */
7554
7555 nih_free (conf_sources);
7556 nih_free (job_classes);
7557
7558 conf_sources = NULL;
7559 job_classes = NULL;
7560
7561 conf_init ();
7562 job_class_init ();
7563
7564 TEST_HASH_EMPTY (job_classes);
7565
7566 source = conf_source_new (NULL, "/tmp", CONF_JOB_DIR);
7567 TEST_NE_P (source, NULL);
7568
7569 session = session_new (NULL, "/abc");
7570 TEST_NE_P (session, NULL);
7571 session->conf_path = NIH_MUST (nih_strdup (session, "/def/ghi"));
7572
7573 source->session = session;
7574
7575 file = conf_file_new (source, "/tmp/test");
7576 TEST_NE_P (file, NULL);
7577
7578 class = file->job = job_class_new (NULL, "test", session);
7579 TEST_NE_P (class, NULL);
7580
7581 job = job_new (class, "");
7582 TEST_NE_P (job, NULL);
7583
7584 TEST_TRUE (job_class_consider (class));
7585 TEST_HASH_NOT_EMPTY (job_classes);
7586
7587 /***********************************************************/
7588 TEST_FEATURE ("JobClass+Session, no job name");
7589
7590 ret = job_find (session, class, NULL, NULL);
7591 TEST_EQ_P (ret, NULL);
7592
7593 /***********************************************************/
7594 TEST_FEATURE ("job class name+Session, no job name");
7595
7596 ret = job_find (session, NULL, "test", NULL);
7597 TEST_EQ_P (ret, NULL);
7598
7599 /***********************************************************/
7600 /* clean up */
7601
7602 nih_free (conf_sources);
7603 nih_free (job_classes);
7604 nih_free (session);
7605
7606 conf_sources = NULL;
7607 job_classes = NULL;
7608
7609 conf_init ();
7610 job_class_init ();
7611}
7612
74967613
7497void7614void
7498deserialise_ptrace_next (void)7615deserialise_ptrace_next (void)
@@ -7608,6 +7725,8 @@
76087725
7609 test_deserialise_ptrace ();7726 test_deserialise_ptrace ();
76107727
7728 test_job_find ();
7729
7611 return 0;7730 return 0;
7612}7731}
76137732

Subscribers

People subscribed via source and target branches