]>
Commit | Line | Data |
---|---|---|
50df544c WB |
1 | #!/usr/bin/perl |
2 | ||
50df544c WB |
3 | use strict; |
4 | use warnings; | |
5 | ||
6 | exit 0 if $ENV{LXC_NAME} && $ENV{LXC_NAME} !~ /^\d+$/; | |
7 | ||
8 | use PVE::Tools; | |
9 | ||
10 | my $vmid = $ENV{LXC_NAME}; | |
11 | my $root = $ENV{LXC_ROOTFS_MOUNT}; | |
12 | ||
13 | if (@ARGV != 3 || $ARGV[1] ne 'lxc' || $ARGV[2] ne 'autodev') { | |
14 | die "invalid usage, this is an LXC autodev hook\n"; | |
15 | } | |
16 | ||
17 | if ($vmid ne $ARGV[0]) { | |
18 | die "got wrong name: $ARGV[0] while LXC_NAME=$vmid\n"; | |
19 | } | |
20 | ||
21 | my $devlist_file = "/var/lib/lxc/$vmid/devices"; | |
22 | ||
23 | open my $fd, '<', $devlist_file; | |
24 | if (!$fd) { | |
25 | exit 0 if $!{ENOENT}; # If the list is empty the file might not exist. | |
26 | die "failed to open device list: $!\n"; | |
27 | } | |
28 | ||
29 | while (defined(my $line = <$fd>)) { | |
30 | if ($line !~ m@^(b):(\d+):(\d+):/dev/(\S+)\s*$@) { | |
31 | warn "invalid .pve-devices entry: $line\n"; | |
32 | } | |
33 | my ($type, $major, $minor, $dev) = ($1, $2, $3, $4); | |
34 | ||
35 | # Don't break out of $root/dev/ | |
36 | if ($dev =~ /\.\./) { | |
37 | warn "skipping illegal device node entry: $dev\n"; | |
38 | next; | |
39 | } | |
40 | ||
41 | # Never expose /dev/loop-control | |
42 | if ($major == 10 && $minor == 237) { | |
43 | warn "skipping illegal device entry (loop-control) for: $dev\n"; | |
44 | next; | |
45 | } | |
46 | ||
47 | PVE::Tools::run_command(['mknod', '-m', '666', "$root/dev/$dev", | |
48 | $type, $major, $minor]); | |
49 | } | |
50 | close $fd; | |
f067e7ba WB |
51 | |
52 | exit 0; |