1181
test_stanza_start (void)
1186
char filename[PATH_MAX];
1188
TEST_FUNCTION ("cfg_stanza_start");
1189
program_name = "test";
1190
output = tmpfile ();
1192
TEST_FILENAME (filename);
1195
/* Check that a start stanza with an on argument followed by an
1196
* event name results in the named event being added to the
1197
* start events list.
1199
TEST_FEATURE ("with on and single argument");
1200
jf = fopen (filename, "w");
1201
fprintf (jf, "exec /sbin/daemon\n");
1202
fprintf (jf, "start on wibble\n");
1205
job = cfg_read_job (NULL, filename, "test");
1207
TEST_ALLOC_SIZE (job, sizeof (Job));
1208
TEST_LIST_NOT_EMPTY (&job->start_events);
1210
event = (Event *)job->start_events.next;
1211
TEST_ALLOC_SIZE (event, sizeof (Event));
1212
TEST_EQ_STR (event->name, "wibble");
1214
nih_list_free (&job->entry);
1217
/* Check that a start stanza with a script argument begins a
1218
* block which is stored in the start_script member of the job.
1220
TEST_FEATURE ("with script and block");
1221
jf = fopen (filename, "w");
1222
fprintf (jf, "exec /sbin/daemon\n");
1223
fprintf (jf, "start script\n");
1224
fprintf (jf, " echo\n");
1225
fprintf (jf, "end script\n");
1228
job = cfg_read_job (NULL, filename, "test");
1230
TEST_ALLOC_SIZE (job, sizeof (Job));
1232
TEST_ALLOC_PARENT (job->start_script, job);
1233
TEST_EQ_STR (job->start_script, "echo\n");
1235
nih_list_free (&job->entry);
1238
/* Check that repeated start on stanzas are permitted, each appending
1241
TEST_FEATURE ("with multiple on stanzas");
1242
jf = fopen (filename, "w");
1243
fprintf (jf, "exec /sbin/daemon\n");
1244
fprintf (jf, "start on wibble\n");
1245
fprintf (jf, "start on wobble\n");
1246
fprintf (jf, "start on waggle\n");
1249
job = cfg_read_job (NULL, filename, "test");
1251
TEST_ALLOC_SIZE (job, sizeof (Job));
1252
TEST_LIST_NOT_EMPTY (&job->start_events);
1254
event = (Event *)job->start_events.next;
1255
TEST_ALLOC_SIZE (event, sizeof (Event));
1256
TEST_EQ_STR (event->name, "wibble");
1258
event = (Event *)event->entry.next;
1259
TEST_ALLOC_SIZE (event, sizeof (Event));
1260
TEST_EQ_STR (event->name, "wobble");
1262
event = (Event *)event->entry.next;
1263
TEST_ALLOC_SIZE (event, sizeof (Event));
1264
TEST_EQ_STR (event->name, "waggle");
1266
nih_list_free (&job->entry);
1269
/* Check that multiple start script stanzas results in a
1272
TEST_FEATURE ("with script and block");
1273
jf = fopen (filename, "w");
1274
fprintf (jf, "exec /sbin/daemon\n");
1275
fprintf (jf, "start script\n");
1276
fprintf (jf, " echo\n");
1277
fprintf (jf, "end script\n");
1278
fprintf (jf, "start script\n");
1279
fprintf (jf, " ls\n");
1280
fprintf (jf, "end script\n");
1283
TEST_DIVERT_STDERR (output) {
1284
job = cfg_read_job (NULL, filename, "test");
1288
TEST_EQ_P (job, NULL);
1290
TEST_ERROR_EQ (output, "6: Duplicate value\n");
1291
TEST_FILE_END (output);
1293
TEST_FILE_RESET (output);
1296
/* Check that a start stanza without a second-level argument results
1297
* in a syntax error.
1299
TEST_FEATURE ("with missing argument");
1300
jf = fopen (filename, "w");
1301
fprintf (jf, "exec /sbin/daemon\n");
1302
fprintf (jf, "start\n");
1305
TEST_DIVERT_STDERR (output) {
1306
job = cfg_read_job (NULL, filename, "test");
1310
TEST_EQ_P (job, NULL);
1312
TEST_ERROR_EQ (output, "2: Expected token\n");
1313
TEST_FILE_END (output);
1315
TEST_FILE_RESET (output);
1318
/* Check that a start stanza with an unknown second-level argument
1319
* results in a syntax error.
1321
TEST_FEATURE ("with unknown argument");
1322
jf = fopen (filename, "w");
1323
fprintf (jf, "exec /sbin/daemon\n");
1324
fprintf (jf, "start foo\n");
1327
TEST_DIVERT_STDERR (output) {
1328
job = cfg_read_job (NULL, filename, "test");
1332
TEST_EQ_P (job, NULL);
1334
TEST_ERROR_EQ (output, "2: Unknown stanza\n");
1335
TEST_FILE_END (output);
1337
TEST_FILE_RESET (output);
1340
/* Check that a start on stanza without an argument results in a
1343
TEST_FEATURE ("with on and missing argument");
1344
jf = fopen (filename, "w");
1345
fprintf (jf, "exec /sbin/daemon\n");
1346
fprintf (jf, "start on\n");
1349
TEST_DIVERT_STDERR (output) {
1350
job = cfg_read_job (NULL, filename, "test");
1354
TEST_EQ_P (job, NULL);
1356
TEST_ERROR_EQ (output, "2: Expected token\n");
1357
TEST_FILE_END (output);
1359
TEST_FILE_RESET (output);
1362
/* Check that a start on stanza with an extra argument results in a
1365
TEST_FEATURE ("with extra argument");
1366
jf = fopen (filename, "w");
1367
fprintf (jf, "exec /sbin/daemon\n");
1368
fprintf (jf, "start on foo bar\n");
1371
TEST_DIVERT_STDERR (output) {
1372
job = cfg_read_job (NULL, filename, "test");
1376
TEST_EQ_P (job, NULL);
1378
TEST_ERROR_EQ (output, "2: Unexpected token\n");
1379
TEST_FILE_END (output);
1381
TEST_FILE_RESET (output);
1384
/* Check that a start script stanza with an extra argument results
1385
* in a syntax error.
1387
TEST_FEATURE ("with extra argument");
1388
jf = fopen (filename, "w");
1389
fprintf (jf, "exec /sbin/daemon\n");
1390
fprintf (jf, "start script foo\n");
1393
TEST_DIVERT_STDERR (output) {
1394
job = cfg_read_job (NULL, filename, "test");
1398
TEST_EQ_P (job, NULL);
1400
TEST_ERROR_EQ (output, "2: Unexpected token\n");
1401
TEST_FILE_END (output);
1403
TEST_FILE_RESET (output);
1410
test_stanza_stop (void)
1415
char filename[PATH_MAX];
1417
TEST_FUNCTION ("cfg_stanza_stop");
1418
program_name = "test";
1419
output = tmpfile ();
1421
TEST_FILENAME (filename);
1424
/* Check that a stop stanza with an on argument followed by an
1425
* event name results in the named event being added to the
1428
TEST_FEATURE ("with on and single argument");
1429
jf = fopen (filename, "w");
1430
fprintf (jf, "exec /sbin/daemon\n");
1431
fprintf (jf, "stop on wibble\n");
1434
job = cfg_read_job (NULL, filename, "test");
1436
TEST_ALLOC_SIZE (job, sizeof (Job));
1437
TEST_LIST_NOT_EMPTY (&job->stop_events);
1439
event = (Event *)job->stop_events.next;
1440
TEST_ALLOC_SIZE (event, sizeof (Event));
1441
TEST_EQ_STR (event->name, "wibble");
1443
nih_list_free (&job->entry);
1446
/* Check that a stop stanza with a script argument begins a
1447
* block which is stored in the stop_script member of the job.
1449
TEST_FEATURE ("with script and block");
1450
jf = fopen (filename, "w");
1451
fprintf (jf, "exec /sbin/daemon\n");
1452
fprintf (jf, "stop script\n");
1453
fprintf (jf, " echo\n");
1454
fprintf (jf, "end script\n");
1457
job = cfg_read_job (NULL, filename, "test");
1459
TEST_ALLOC_SIZE (job, sizeof (Job));
1461
TEST_ALLOC_PARENT (job->stop_script, job);
1462
TEST_EQ_STR (job->stop_script, "echo\n");
1464
nih_list_free (&job->entry);
1467
/* Check that repeated stop on stanzas are permitted, each appending
1470
TEST_FEATURE ("with multiple on stanzas");
1471
jf = fopen (filename, "w");
1472
fprintf (jf, "exec /sbin/daemon\n");
1473
fprintf (jf, "stop on wibble\n");
1474
fprintf (jf, "stop on wobble\n");
1475
fprintf (jf, "stop on waggle\n");
1478
job = cfg_read_job (NULL, filename, "test");
1480
TEST_ALLOC_SIZE (job, sizeof (Job));
1481
TEST_LIST_NOT_EMPTY (&job->stop_events);
1483
event = (Event *)job->stop_events.next;
1484
TEST_ALLOC_SIZE (event, sizeof (Event));
1485
TEST_EQ_STR (event->name, "wibble");
1487
event = (Event *)event->entry.next;
1488
TEST_ALLOC_SIZE (event, sizeof (Event));
1489
TEST_EQ_STR (event->name, "wobble");
1491
event = (Event *)event->entry.next;
1492
TEST_ALLOC_SIZE (event, sizeof (Event));
1493
TEST_EQ_STR (event->name, "waggle");
1495
nih_list_free (&job->entry);
1498
/* Check that multiple stop script stanzas results in a
1501
TEST_FEATURE ("with script and block");
1502
jf = fopen (filename, "w");
1503
fprintf (jf, "exec /sbin/daemon\n");
1504
fprintf (jf, "stop script\n");
1505
fprintf (jf, " echo\n");
1506
fprintf (jf, "end script\n");
1507
fprintf (jf, "stop script\n");
1508
fprintf (jf, " ls\n");
1509
fprintf (jf, "end script\n");
1512
TEST_DIVERT_STDERR (output) {
1513
job = cfg_read_job (NULL, filename, "test");
1517
TEST_EQ_P (job, NULL);
1519
TEST_ERROR_EQ (output, "6: Duplicate value\n");
1520
TEST_FILE_END (output);
1522
TEST_FILE_RESET (output);
1525
/* Check that a stop stanza without a second-level argument results
1526
* in a syntax error.
1528
TEST_FEATURE ("with missing argument");
1529
jf = fopen (filename, "w");
1530
fprintf (jf, "exec /sbin/daemon\n");
1531
fprintf (jf, "stop\n");
1534
TEST_DIVERT_STDERR (output) {
1535
job = cfg_read_job (NULL, filename, "test");
1539
TEST_EQ_P (job, NULL);
1541
TEST_ERROR_EQ (output, "2: Expected token\n");
1542
TEST_FILE_END (output);
1544
TEST_FILE_RESET (output);
1547
/* Check that a stop stanza with an unknown second-level argument
1548
* results in a syntax error.
1550
TEST_FEATURE ("with unknown argument");
1551
jf = fopen (filename, "w");
1552
fprintf (jf, "exec /sbin/daemon\n");
1553
fprintf (jf, "stop foo\n");
1556
TEST_DIVERT_STDERR (output) {
1557
job = cfg_read_job (NULL, filename, "test");
1561
TEST_EQ_P (job, NULL);
1563
TEST_ERROR_EQ (output, "2: Unknown stanza\n");
1564
TEST_FILE_END (output);
1566
TEST_FILE_RESET (output);
1569
/* Check that a stop on stanza without an argument results in a
1572
TEST_FEATURE ("with on and missing argument");
1573
jf = fopen (filename, "w");
1574
fprintf (jf, "exec /sbin/daemon\n");
1575
fprintf (jf, "stop on\n");
1578
TEST_DIVERT_STDERR (output) {
1579
job = cfg_read_job (NULL, filename, "test");
1583
TEST_EQ_P (job, NULL);
1585
TEST_ERROR_EQ (output, "2: Expected token\n");
1586
TEST_FILE_END (output);
1588
TEST_FILE_RESET (output);
1591
/* Check that a stop on stanza with an extra argument results in a
1594
TEST_FEATURE ("with extra argument");
1595
jf = fopen (filename, "w");
1596
fprintf (jf, "exec /sbin/daemon\n");
1597
fprintf (jf, "stop on foo bar\n");
1600
TEST_DIVERT_STDERR (output) {
1601
job = cfg_read_job (NULL, filename, "test");
1605
TEST_EQ_P (job, NULL);
1607
TEST_ERROR_EQ (output, "2: Unexpected token\n");
1608
TEST_FILE_END (output);
1610
TEST_FILE_RESET (output);
1613
/* Check that a stop script stanza with an extra argument results
1614
* in a syntax error.
1616
TEST_FEATURE ("with extra argument");
1617
jf = fopen (filename, "w");
1618
fprintf (jf, "exec /sbin/daemon\n");
1619
fprintf (jf, "stop script foo\n");
1622
TEST_DIVERT_STDERR (output) {
1623
job = cfg_read_job (NULL, filename, "test");
1627
TEST_EQ_P (job, NULL);
1629
TEST_ERROR_EQ (output, "2: Unexpected token\n");
1630
TEST_FILE_END (output);
1632
TEST_FILE_RESET (output);
1181
1639
test_stanza_pid (void)