-
Notifications
You must be signed in to change notification settings - Fork 1
/
inittab.C
1753 lines (1402 loc) · 36.6 KB
/
inittab.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** Copyright 2024 Double Precision, Inc.
** See COPYING for distribution information.
*/
#include "config.h"
#include "inittab.H"
#include "log.H"
#include "hook.H"
#include "verac.h"
#include "yaml_writer.H"
#include "proc_loader.H"
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <string_view>
#include <fstream>
#include <sstream>
#include <filesystem>
#include <sys/stat.h>
namespace {
#if 0
}
#endif
/*! The previous identifier for each runlevel
As each line in /etc/inittab gets converted, we keep track of the
previous processed identifier for each runlevel.
*/
typedef std::unordered_map<std::string, std::string> prev_commands_t;
/*! All runlevels for the current command being processd
*/
typedef std::set<std::string> all_runlevels_t;
/*!
A new inittab entry being imported.
*/
struct inittab_entry {
/*!
Previous inittab commands
*/
prev_commands_t &prev_commands;
/*!
This entry's run levels.
*/
const all_runlevels_t all_runlevels;
/*! First field in the inittab line
*/
std::string identifier;
/*! The last file in the inittab line
It becomes the starting command.
*/
std::string starting_command;
/*! Non-defautl starting timeout */
std::string starting_timeout;
/*! Stopping command, if we know it */
std::string stopping_command;
/*! Restarting command, if we know it */
std::string restarting_command;
/*! Reload command, if we know it */
std::string reloading_command;
/*! The description that goes into the generated unit file */
std::string description;
/*! The unit's alternative-group */
std::string alternative_group;
/*! Extra headers.
This is used to link an inittab entry to an rc.d script
*/
std::unordered_map<std::string, std::string> x;
/* Unit's starting type */
const char *start_type="oneshot";
/* Unit's stop type */
const char *stop_type="manual";
// Unit or units where this inittab/namespace entry starts in.
std::vector<std::string> required_by;
// Unit or units where this inittab/namespace entry requires
std::vector<std::string> this_requires;
// Additional dependencies
std::vector<std::string> starts_before, starts_after,
stops_before, stops_after;
//! This unit starts in this runlevel.
void required_by_runlevel(const std::string &runlevel)
{
required_by.push_back("/system/"+runlevel);
}
//! New entry read from /etc/inittab
inittab_entry(prev_commands_t &prev_commands,
const all_runlevels_t &all_runlevels,
std::string identifier,
std::string starting_command,
std::string description)
: prev_commands{prev_commands},
all_runlevels{all_runlevels},
identifier{std::move(identifier)},
starting_command{std::move(starting_command)},
description{std::move(description)}
{
// If there's a previous command this one will start after it
// and stop before it.
std::unordered_set<std::string> all_prev_commands;
for (auto &rl:all_runlevels)
{
auto &prev_command=prev_commands[rl];
if (prev_command.empty())
continue;
if (!all_prev_commands.insert(prev_command).second)
continue;
starts_after.push_back(prev_command);
stops_before.push_back(prev_command);
}
}
//! Additional entries generated.
inittab_entry(inittab_entry &prev_entry,
std::string identifier,
std::string starting_command,
std::string description)
: inittab_entry{
prev_entry.prev_commands,
prev_entry.all_runlevels,
std::move(identifier),
std::move(starting_command),
std::move(description)
}
{
description=prev_entry.description;
}
//! Convert this inittab entry to YAML.
yaml_write_map create() const;
};
yaml_write_map inittab_entry::create() const
{
// Convert the fields to YAML, one by one.
yaml_map_t unit;
unit.emplace_back(
std::make_shared<yaml_write_scalar>("name"),
std::make_shared<yaml_write_scalar>(identifier)
);
unit.emplace_back(
std::make_shared<yaml_write_scalar>("description"),
std::make_shared<yaml_write_scalar>(description)
);
if (!alternative_group.empty())
unit.emplace_back(
std::make_shared<yaml_write_scalar>(
"alternative-group"
),
std::make_shared<yaml_write_scalar>(
alternative_group
)
);
if (!required_by.empty())
{
unit.emplace_back(
std::make_shared<yaml_write_scalar>("required-by"),
std::make_shared<yaml_write_seq>(
required_by.begin(), required_by.end()
)
);
}
if (!this_requires.empty())
{
unit.emplace_back(
std::make_shared<yaml_write_scalar>("requires"),
std::make_shared<yaml_write_seq>(
this_requires.begin(), this_requires.end()
)
);
}
yaml_map_t starting, stopping;
starting.emplace_back(
std::make_shared<yaml_write_scalar>("type"),
std::make_shared<yaml_write_scalar>(start_type)
);
stopping.emplace_back(
std::make_shared<yaml_write_scalar>("type"),
std::make_shared<yaml_write_scalar>(stop_type)
);
if (!starting_command.empty())
{
starting.emplace_back(
std::make_shared<yaml_write_scalar>("command"),
std::make_shared<yaml_write_scalar>(starting_command)
);
}
if (!starting_timeout.empty())
{
starting.emplace_back(
std::make_shared<yaml_write_scalar>("timeout"),
std::make_shared<yaml_write_scalar>(starting_timeout)
);
}
if (!stopping_command.empty())
stopping.emplace_back(
std::make_shared<yaml_write_scalar>("command"),
std::make_shared<yaml_write_scalar>(stopping_command)
);
if (!starts_after.empty())
starting.emplace_back(
std::make_shared<yaml_write_scalar>("after"),
std::make_shared<yaml_write_seq>(
starts_after.begin(), starts_after.end()
));
if (!starts_before.empty())
starting.emplace_back(
std::make_shared<yaml_write_scalar>("before"),
std::make_shared<yaml_write_seq>(
starts_before.begin(), starts_before.end()
));
if (!stops_before.empty())
stopping.emplace_back(
std::make_shared<yaml_write_scalar>("before"),
std::make_shared<yaml_write_seq>(
stops_before.begin(), stops_before.end()
));
if (!stops_after.empty())
stopping.emplace_back(
std::make_shared<yaml_write_scalar>("after"),
std::make_shared<yaml_write_seq>(
stops_after.begin(), stops_after.end()
));
unit.emplace_back(
std::make_shared<yaml_write_scalar>("starting"),
std::make_shared<yaml_write_map>(
std::move(starting)
)
);
unit.emplace_back(
std::make_shared<yaml_write_scalar>("stopping"),
std::make_shared<yaml_write_map>(
std::move(stopping)
)
);
if (!restarting_command.empty())
{
unit.emplace_back(
std::make_shared<yaml_write_scalar>("restart"),
std::make_shared<yaml_write_scalar>(restarting_command)
);
}
if (!reloading_command.empty())
{
unit.emplace_back(
std::make_shared<yaml_write_scalar>("reload"),
std::make_shared<yaml_write_scalar>(reloading_command)
);
}
for (auto &rl:all_runlevels)
prev_commands[rl]=identifier;
for (auto &[name, value] : x)
{
unit.emplace_back(
std::make_shared<yaml_write_scalar>(name),
std::make_shared<yaml_write_scalar>(value)
);
}
unit.emplace_back(
std::make_shared<yaml_write_scalar>("Version"),
std::make_shared<yaml_write_scalar>("1")
);
return yaml_write_map{std::move(unit)};
}
//! Orderly process for converting /etc/inittab to units
struct convert_inittab {
//! Which directory we'll write the units into
const std::string &unit_directory;
//! Whether an error occured.
bool error=false;
/*
All -start scripts we generated, for each runlevel.
We expect only one per runlevel.
*/
std::map<std::string, inittab_entry> all_start_scripts;
/*
Use the runlevels configuration to map short runlevel
codes, like '4' into log names, like 'multi-user'.
*/
std::unordered_map<std::string, std::string> runlevel_lookup;
// Sanity check: unique identifiers
std::unordered_set<std::string> ids_seen;
std::unordered_map<std::string, std::string> prev_commands;
// Keep track of runlevels that run rc.? scripts
std::set<std::string> all_single_multi_runlevels;
convert_inittab(const std::string &unit_directory,
const runlevels &runlevels)
: unit_directory{unit_directory}
{
// Converted entries in /etc/inittab go here
std::filesystem::create_directory(
unit_directory + "/system/inittab"
);
// Converted entries from /etc/rc.d/rc?.d go here
std::filesystem::create_directory(
unit_directory + "/system/rc"
);
// Scripts sniffed out of /etc/rc.d/rc.M go here
std::filesystem::create_directory(
unit_directory + "/system/rc.M"
);
// Create mapping from legacy init runlevels to descriptive
// runlevel names.
for (const auto &[name, runlevel] : runlevels)
{
for (const auto &alias:runlevel.aliases)
{
runlevel_lookup.emplace(alias, name);
}
}
}
//! Generate targets for starting converted /etc/rc.d units
void start_rc(
//! Identifier from /etc/inittab, the first field
const std::string &identifier,
//! /etc/inittab line number, for error messages
size_t linenum,
//! What to write into the unit specification file.
const std::string &comment,
//! Which runlevels the /etc/rc.d entries are started for
all_runlevels_t &all_runlevels);
//! Generate target for running /etc/rc.d/rc.local
void start_local(const std::string &identifier,
size_t linenum,
const std::string &comment,
all_runlevels_t &all_runlevels);
//! Add an entry from the inittab file.
void add_inittab(const inittab_entry &entry,
const std::string &comment)
{
add(entry, unit_directory + "/system/inittab/"
+ entry.identifier, comment);
}
/*! Add a unit for starting converted RC entries.
** A unit for each runlevel that converted /etc/rc.d units, for that
** run levels, are required-by.
*/
void add_rc(const inittab_entry &entry)
{
add(entry, unit_directory + "/system/" + entry.identifier,
"");
}
/*! Add a unit for starting entries executed by rc.M
** A unit for each script that /etc/rc.d/rc.M runs, if it's
** executable.
*/
void add_rcm(const inittab_entry &entry)
{
add(entry, unit_directory + "/system/rc.M/" + entry.identifier,
"start /etc/rc.d/" + entry.identifier
+ " from /etc/rc.d/rc.M");
}
/*! Add a unit for starting /etc/rc.d/rc?.d entries */
void add_rcd(const inittab_entry &entry)
{
add(entry, unit_directory + "/system/rc/" + entry.identifier,
"start " + entry.identifier);
}
/*! Add an ad-hoc system unit */
void add_adhoc_system(
const inittab_entry &entry,
const std::string &comment
)
{
add(entry, unit_directory + "/system/" + entry.identifier,
comment);
}
private:
//! Keep track of all created unit files.
std::unordered_set<std::string> all_units;
void add(const inittab_entry &entry,
std::string filename,
const std::string &comment)
{
if (!all_units.insert(filename).second)
{
std::cerr << "Attempting to create "
<< filename << " more than once."
<< std::endl;
error=true;
}
// Create the YAML file. Write it out only if its contents
// different from the existing file. This avoids repeated
// thrashing as vera attempts to reload everything, repeatedly.
std::string new_contents;
{
std::ostringstream o;
if (!comment.empty())
o << "#\n# " << comment << "\n#\n\n";
yaml_writer{o}.write(entry.create());
new_contents=o.str();
}
std::ifstream i{filename};
std::string current_contents{
std::istreambuf_iterator<char>{i},
std::istreambuf_iterator<char>{}
};
if (current_contents != new_contents)
{
std::ofstream o{filename + "~"};
o << new_contents;
o.close();
if (o.fail())
{
std::cerr << "Cannot create "
<< filename << std::endl;
error=true;
}
std::error_code ec;
std::filesystem::rename(filename + "~", filename, ec);
if (ec)
{
std::cerr << "Cannot create " << filename
<< ": " << ec.message() << std::endl;
error=true;
}
}
}
public:
void cleanup();
};
//! When done, check for any existing files we did not see, they must be
//! obsolete.
void convert_inittab::cleanup()
{
// Anything in system/inittab that was removed?
for (auto b=std::filesystem::directory_iterator{
unit_directory + "/system/inittab"
}; b != std::filesystem::directory_iterator{}; ++b)
{
std::string s=b->path();
if (all_units.count(s))
continue;
std::filesystem::remove(s);
}
// Any rc.* files that were no longer created?
for (auto b=std::filesystem::directory_iterator{
unit_directory + "/system/"
}; b != std::filesystem::directory_iterator{}; ++b)
{
auto filename=b->path().filename().native();
if (filename == "rc.M")
continue; // This is a directory, see below.
if (filename.substr(0, 3) != "rc.")
continue;
std::string s=b->path();
if (all_units.count(s))
continue;
std::filesystem::remove(s);
}
// Anything in system/rc that was removed?
for (auto b=std::filesystem::directory_iterator{
unit_directory + "/system/rc/"
}; b != std::filesystem::directory_iterator{}; ++b)
{
std::string s=b->path();
if (all_units.count(s))
continue;
std::filesystem::remove(s);
}
// Anything in system/rc.M that was removed?
for (auto b=std::filesystem::directory_iterator{
unit_directory + "/system/rc.M/"
}; b != std::filesystem::directory_iterator{}; ++b)
{
std::string s=b->path();
if (all_units.count(s))
continue;
std::filesystem::remove(s);
}
}
void convert_inittab::start_rc(const std::string &identifier,
size_t linenum,
const std::string &comment,
all_runlevels_t &all_runlevels)
{
// Generate a "start" unit after this one, for
// every runlevel that rc.K and rc.M is in, one
// runlevel per start unit.
//
// Each unit manually runs the "vlad start" command
// to start all the rc units.
//
// The dependencies of these units are that they
// start after rc.K and stop before it.
for (auto &required_by : all_runlevels)
{
all_runlevels_t just_one;
just_one.insert(required_by);
inittab_entry run_rc_start{
prev_commands,
just_one,
identifier + "-start-" + required_by,
"",
identifier + ": start rc.d scripts"};
run_rc_start.start_type="forking";
run_rc_start.stop_type="target";
run_rc_start.required_by_runlevel(required_by);
run_rc_start.starting_command=
"vlad --nowait start system/rc." + required_by;
run_rc_start.stop_type="target";
run_rc_start.starts_before.push_back(
"/system/rc");
run_rc_start.stops_after.push_back(
"/system/rc");
if (!all_start_scripts.insert(
{
required_by, run_rc_start
}).second)
{
std::cerr << "Line "
<< linenum
<< ": duplicate rc script"
<< "invocation detected"
<< std::endl;
error=true;
}
// Generate a "started" unit, which starts after all
// of the start units, and stops before them.
//
// In this manner, the RC units start/stop gets
// book-ended after the corresponding rc.[MK] command.
inittab_entry run_rc_started{
prev_commands,
just_one,
identifier + "-started-" + required_by,
"",
identifier + ": started rc.d scripts"};
run_rc_started.stop_type="target";
run_rc_started.required_by_runlevel(
required_by
);
// The "started" unit starts after all system/rc
// scripts and all the start scripts for this inittab
// unit.
run_rc_started.starts_after.push_back("/system/rc");
run_rc_started.stops_before.push_back("/system/rc");
run_rc_started.description=identifier +
": started rc.d scripts";
add_inittab(run_rc_started,
comment + " (rc started)");
}
all_single_multi_runlevels.insert(
all_runlevels.begin(),
all_runlevels.end()
);
}
void convert_inittab::start_local(const std::string &identifier,
size_t linenum,
const std::string &comment,
all_runlevels_t &all_runlevels)
{
inittab_entry run_rc_local{
prev_commands,
all_runlevels,
identifier + "-run-local",
"test ! -x /etc/rc.d/rc.local.init ||"
" /etc/rc.d/rc.local.init start",
identifier + ": started rc.local"
};
run_rc_local.stopping_command=
"test ! -x /etc/rc.d/rc.local_shutdown.init ||"
" /etc/rc.d/rc.local_shutdown.init stop";
run_rc_local.start_type="forking";
run_rc_local.stop_type="manual";
for (auto &required_by:all_runlevels)
run_rc_local.required_by_runlevel(required_by);
run_rc_local.description=identifier +
": started rc.local";
add_inittab(run_rc_local,
comment + " (rc.local started)");
}
/*
Metadata while parsing /etc/inittab lines.
The physical structure of /etc/inittab is parsed in C, which invokes
a callback with a passthrough void pointer that points to this object.
The C code trampoline invokes the closure that does the real work, and
traps C++ exceptions, which set the error flag.
*/
struct parse_inittab_data {
std::function<void (const char *,
const char *,
const char *, const char *,
const char *)> *cbptr;
bool error;
};
#if 0
{
#endif
}
extern "C" {
/*
** Callback from C parser.
*/
static void parse_inittab_trampoline(
const char *orig_line,
const char *identifier,
const char *runlevels,
const char *action,
const char *command,
void *cbarg)
{
auto *d=reinterpret_cast<parse_inittab_data *>(cbarg);
try {
(*d->cbptr)(orig_line,
identifier,
runlevels,
action,
command);
} catch (const std::exception &e)
{
std::cerr << e.what() << std::endl;
d->error=true;
}
}
}
bool parse_inittab(const std::string &filename,
std::function<void (const char *,
const char *,
const char *, const char *,
const char *)> parser)
{
parse_inittab_data d{&parser, false};
FILE *fp=fopen(filename.c_str(), "r");
if (!fp)
{
std::cerr << filename << ": " << strerror(errno) << std::endl;
return false;
}
parse_inittab(fp, parse_inittab_trampoline, &d);
fclose(fp);
return (!d.error);
}
namespace {
#if 0
}
#endif
struct inittab_converter {
const std::string &unit_dir;
const std::string &pkgdata_dir;
const runlevels &runlevels_config;
std::string rcdir;
std::string &initdefault;
convert_inittab generator{unit_dir, runlevels_config};
std::string s;
size_t linenum=0;
std::unordered_set<std::string> ondemand;
inittab_converter(const std::string &unit_dir,
const std::string &pkgdata_dir,
const runlevels &runlevels_config,
std::string rcdir,
std::string &initdefault)
: unit_dir{unit_dir},
pkgdata_dir{pkgdata_dir},
runlevels_config{runlevels_config},
rcdir{std::move(rcdir)},
initdefault{initdefault},
generator{unit_dir, runlevels_config}
{
}
void operator()(const char *s,
std::string new_entry_identifier,
std::string runlevels,
std::string actions,
std::string starting_command)
{
if (!generator.ids_seen.insert(new_entry_identifier).second)
{
std::cerr << "Line " << linenum
<< ": duplicate identifier \""
<< new_entry_identifier << "\""
<< std::endl;
generator.error=true;
return;
}
if (actions == "off")
return;
if (actions == "initdefault")
{
initdefault=runlevels;
return;
}
if (actions == "sysinit")
return;
std::set<std::string> required_by_runlevel;
const char *start_type=nullptr;
/*
** The inittab's one-line character code gets mapped
** into a list of long-name run levels, via the
** runlevel_lookup mapping.
*/
all_runlevels_t all_runlevels;
/*
** Map certain actions to specific runlevels. The new unit
** declares that it's required-by these runlevels.
*/
if (actions == "ctrlaltdel")
{
required_by_runlevel.insert(SIGINT_UNIT);
}
else if (actions == "powerfail")
{
required_by_runlevel.insert(PWRFAIL_UNIT);
}
else if (actions == "powerwait")
{
start_type="forking";
required_by_runlevel.insert(PWRFAIL_UNIT);
}
else if (actions == "powerok")
{
required_by_runlevel.insert(PWROK_UNIT);
}
else if (actions == "powerokwait")
{
start_type="forking";
required_by_runlevel.insert(PWROK_UNIT);
}
else if (actions == "powerfailnow")
{
required_by_runlevel.insert(PWRFAILNOW_UNIT);
}
else if (actions == "powerfailnowwait")
{
start_type="forking";
required_by_runlevel.insert(PWRFAILNOW_UNIT);
}
else if (actions == "kbrequest")
{
required_by_runlevel.insert(SIGWINCH_UNIT);
}
else if (actions == "boot")
{
required_by_runlevel.insert("boot");
}
else if (actions == "bootwait")
{
required_by_runlevel.insert("boot");
start_type="forking";
}
else
{
// And for other actions we look at the actual
// runlevel declarations, with the action controlling
if (actions == "respawn")
{
start_type="respawn";
}
else if (actions == "wait")
{
start_type="forking";
}
else if (actions == "once")
{
}
else if (actions == "ondemand")
{
// The loop below will put entry into the
// ondemand runlevel.
}
else if (actions == "ondemandwait")
{
// The loop below will put entry into the
// ondemand runlevel.
start_type="forking";
}
for (auto c:runlevels)
{
switch (c) {
case 'a':
case 'A':
generator.all_single_multi_runlevels
.insert("a");
all_runlevels.insert("a");
continue;
case 'b':
case 'B':
generator.all_single_multi_runlevels
.insert("b");
all_runlevels.insert("b");
continue;
case 'c':
case 'C':
generator.all_single_multi_runlevels
.insert("c");
all_runlevels.insert("c");
continue;
}
auto iter=generator.runlevel_lookup.find(
std::string{
&c, &c+1
});
if (iter == generator.runlevel_lookup.end())
{
std::cerr << "Line " << linenum
<< ": unknown runlevel "
<< c << std::endl;
generator.error=true;
}
else
{
all_runlevels.insert(
iter->second);
}
}
for (auto &rl:all_runlevels)
required_by_runlevel.insert(rl);
}