]> git.proxmox.com Git - pve-container.git/blame - src/lxc-pve-autodev-hook
bump version to 1.0-46
[pve-container.git] / src / lxc-pve-autodev-hook
CommitLineData
50df544c
WB
1#!/usr/bin/perl
2
50df544c
WB
3use strict;
4use warnings;
5
6exit 0 if $ENV{LXC_NAME} && $ENV{LXC_NAME} !~ /^\d+$/;
7
8use PVE::Tools;
9
10my $vmid = $ENV{LXC_NAME};
11my $root = $ENV{LXC_ROOTFS_MOUNT};
12
13if (@ARGV != 3 || $ARGV[1] ne 'lxc' || $ARGV[2] ne 'autodev') {
14 die "invalid usage, this is an LXC autodev hook\n";
15}
16
17if ($vmid ne $ARGV[0]) {
18 die "got wrong name: $ARGV[0] while LXC_NAME=$vmid\n";
19}
20
21my $devlist_file = "/var/lib/lxc/$vmid/devices";
22
23open my $fd, '<', $devlist_file;
24if (!$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
29while (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}
50close $fd;
f067e7ba
WB
51
52exit 0;