forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinittab-lib.pl
executable file
·107 lines (99 loc) · 2.68 KB
/
inittab-lib.pl
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
#!/usr/local/bin/perl
BEGIN { push(@INC, ".."); };
use WebminCore;
&init_config();
# parse_inittab()
# Returns a list of entries from the /etc/inittab file
sub parse_inittab
{
local @rv;
local $lnum = 0;
open(INITTAB, $config{'inittab_file'});
while(<INITTAB>) {
s/\r|\n//g;
#s/#.*$//g;
s/\/\/.*$//g;
if ($gconfig{'os_type'} eq 'aix') {
# A leading : indicates a comment on AIX
s/^:.*$//g;
}
next if (/^\s*#\s*\$Header/i); # CVS header
local $sline = $lnum;
# Join \ lines
while(/\\$/) {
local $nl = <INITTAB>;
s/\\$//;
$nl =~ s/^\s+//;
$_ .= $nl;
$lnum++;
}
if (/^(#*)\s*\$Id/ || /^(#*)\s*\/etc/ || /^(#*)\s*<id>/) {
# Skip this line
}
elsif (/^(#*)\s*([^:]+):([^:]*):([^:]+):([^:]*)/) {
push(@rv, { 'id' => $2,
'action' => $4,
'process' => $5,
'comment' => $1 ne '',
'levels' => [ split(//, $3) ],
'line' => $sline,
'eline' => $lnum,
'index' => scalar(@rv) });
}
$lnum++;
}
close(INITTAB);
return @rv;
}
# create_inittab(&inittab)
# Adds an entry to /etc/inittab
sub create_inittab
{
&open_tempfile(INITTAB, ">>$config{'inittab_file'}");
&print_tempfile(INITTAB, $_[0]->{'comment'} ? "# " : "",
join(":", $_[0]->{'id'}, join("", @{$_[0]->{'levels'}}),
$_[0]->{'action'}, $_[0]->{'process'}),"\n");
&close_tempfile(INITTAB);
}
# modify_inittab(&inittab)
# Replaces an /etc/inittab entry
sub modify_inittab
{
local $lref = &read_file_lines($config{'inittab_file'});
splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1,
($_[0]->{'comment'} ? "# " : "").
join(":", $_[0]->{'id'}, join("", @{$_[0]->{'levels'}}),
$_[0]->{'action'}, $_[0]->{'process'}));
&flush_file_lines();
}
# delete_inittab(&inittab)
# Delete a single /etc/inittab entry
sub delete_inittab
{
local $lref = &read_file_lines($config{'inittab_file'});
splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1);
&flush_file_lines();
}
sub list_runlevels
{
return ( 0..6, "a", "b", "c" );
}
sub list_actions
{
return ( [ "respawn", $text{ 'inittab_respawn' } ],
[ "wait", $text{ 'inittab_wait' } ],
[ "once", $text{ 'inittab_once' } ],
[ "ondemand", $text{ 'inittab_ondemand' } ],
[ "initdefault", $text{ 'inittab_initdefault' } ],
[ "sysinit", $text{ 'inittab_sysinit' } ],
[ "powerwait", $text{ 'inittab_powerwait' } ],
[ "powerfail", $text{ 'inittab_powerfail' } ],
[ "powerokwait", $text{ 'inittab_powerokwait' } ],
[ "powerfailnow", $text{ 'inittab_powerfailnow' } ],
[ "ctrlaltdel", $text{ 'inittab_ctrlaltdel' } ],
[ "kbdrequest", $text{ 'inittab_kbdrequest' } ],
[ "bootwait", $text{'inittab_bootwait'} ],
[ "boot", $text{'inittab_boot'} ],
[ "off", $text{'inittab_off'} ],
);
}