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
|
package modules::any_conf; # $Id: any_conf.pm 215411 2007-04-25 12:26:16Z pixel $
use log;
use common;
sub vnew {
require modules::modprobe_conf;
modules::modprobe_conf->new;
}
sub new {
my ($type) = @_;
bless {}, ref($type) || $type;
}
sub modules {
my ($conf) = @_;
keys %$conf;
}
sub get_alias {
my ($conf, $alias) = @_;
$conf->{$alias}{alias};
}
sub get_options {
my ($conf, $module) = @_;
$module = $conf->mapping($module);
$conf->{$module}{options};
}
sub set_options {
my ($conf, $module, $new_option) = @_;
$module = $conf->mapping($module);
log::explanations(qq(set option "$new_option" for module "$module"));
$conf->{$module}{options} = $new_option;
}
sub get_parameters {
my ($conf, $module) = @_;
$module = $conf->mapping($module);
map { if_(/(.*)=(.*)/, $1 => $2) } split(' ', $conf->get_options($module));
}
sub get_probeall {
my ($conf, $alias) = @_;
$conf->{$alias}{probeall};
}
sub _set_probeall {
my ($conf, $alias, $modules) = @_;
$conf->{$alias}{probeall} = $modules;
log::explanations("setting probeall $alias to $modules");
}
sub add_probeall {
my ($conf, $alias, $module) = @_;
$module = $conf->mapping($module);
my $modules = join(' ', uniq(split(' ', $conf->{$alias}{probeall}), $module));
_set_probeall($conf, $alias, $modules);
}
sub remove_probeall {
my ($conf, $alias, $module) = @_;
$module = $conf->mapping($module);
my $modules = join(' ', grep { $_ ne $module } split(' ', $conf->{$alias}{probeall}));
_set_probeall($conf, $alias, $modules);
}
sub set_alias {
my ($conf, $alias, $module) = @_;
$module =~ /ignore/ and return;
$module = $conf->mapping($module);
/\Q$alias/ && $conf->{$_}{alias} && $conf->{$_}{alias} eq $module and return $_ foreach keys %$conf;
log::explanations("adding alias $alias to $module");
$conf->{$alias}{alias} = $module;
$alias;
}
sub remove_alias {
my ($conf, $name) = @_;
log::explanations(qq(removing alias "$name"));
$conf->remove_alias_regexp("^$name\$");
}
sub remove_alias_regexp {
my ($conf, $aliased) = @_;
log::explanations(qq(removing all aliases that match "$aliased"));
foreach (keys %$conf) {
delete $conf->{$_}{alias} if /$aliased/;
}
}
sub remove_alias_regexp_byname {
my ($conf, $name) = @_;
log::explanations(qq(removing all aliases which names match "$name"));
foreach (keys %$conf) {
delete $conf->{$_} if /$name/;
}
}
sub remove_module {
my ($conf, $module) = @_;
return if !$module;
$module = $conf->mapping($module);
foreach my $file ("$::prefix/etc/modules", "$::prefix/etc/modprobe.preload") {
substInFile {
undef $_ if /^$module/;
} $file;
}
$conf->remove_alias($module);
log::explanations("removing module $module");
delete $conf->{$module};
0;
}
sub set_sound_slot {
my ($conf, $alias, $module) = @_;
$module = $conf->mapping($module);
if (my $old = $conf->get_alias($alias)) {
$conf->set_above($old, undef);
}
$conf->set_alias($alias, $module);
$conf->set_above($module, 'snd-pcm-oss') if $module =~ /^snd-/;
}
sub read {
my (undef, $o_file) = @_;
my $conf = vnew();
$conf->read($o_file);
}
sub write {
my ($conf, $o_file) = @_;
my $file = $o_file || $::prefix . $conf->file;
my %written;
#- Substitute new config (if config has changed)
substInFile {
my ($type, $module, $val) = split(' ', chomp_($_), 3);
if (member($type, $conf->handled_fields)) {
my $new_val = $conf->{$module}{$type};
if (!$new_val) {
$_ = '';
} elsif ($new_val ne $val) {
$_ = "$type $module $new_val\n";
}
}
$written{$module}{$type} = 1;
} $file;
my $to_add;
while (my ($module, $h) = each %$conf) {
while (my ($type, $v) = each %$h) {
if ($v && !$written{$module}{$type}) {
$to_add .= "$type $module $v\n";
}
}
}
append_to_file($file, $to_add);
modules::write_preload_conf($conf);
}
sub merge_into {
my ($conf, $conf2) = @_;
if (ref($conf) eq ref($conf2)) {
log::l("merging " . ref($conf));
add2hash($conf, $conf2);
} else {
log::l("not merging modules_conf " . ref($conf2) . " into " . ref($conf));
}
}
################################################################################
sub read_handled {
my ($conf, $o_file) = @_;
my $file = $o_file || $::prefix . $conf->file;
my $raw_conf = read_raw($file);
foreach my $module (keys %$raw_conf) {
my $raw = $raw_conf->{$module};
my $keep = $conf->{$module} = {};
foreach ($conf->handled_fields) {
$keep->{$_} = $raw->{$_} if $raw->{$_};
}
}
$conf;
}
sub read_raw {
my ($file) = @_;
my %c;
foreach (cat_($file)) {
next if /^\s*#/;
s/#.*$//;
s/\s+$//;
# Fix upgrade from ALSA < 0.9.0:
s/\b(snd-card-)/snd-/g;
# Fix upgrade for unified VIA driver:
s/\b(snd-via686|snd-via8233)\b/snd-via82xx/g;
my ($type, $module, $val) = split(' ', $_, 3) or next;
$c{$module}{$type} = $val;
}
#- NB: not copying alias options to the module anymore, hopefully not useful :)
\%c;
}
1;
|