File: notify.pl

package info (click to toggle)
uml-utilities 20070815.4-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 752 kB
  • sloc: ansic: 3,392; perl: 1,277; makefile: 239; exp: 129; sh: 122
file content (42 lines) | stat: -rw-r--r-- 1,219 bytes parent folder | download | duplicates (9)
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
use Socket;
use strict;

my $MCONSOLE_SOCKET = 0;
my $MCONSOLE_PANIC = 1;
my $MCONSOLE_HANG = 2;
my $MCONSOLE_USER_NOTIFY = 3;

my @types = ( "socket", "panic", "hang", "user notification" );

!defined(socket(SOCK, AF_UNIX, SOCK_DGRAM, 0)) and 
    die "socket() failed : $!\n";

# XXX the -u causes mktemp to unlink the file - this is needed because
# we don't want a normal file, we want a socket.

my $file = `mktemp -u /tmp/mconsole.XXXXXX`;
$? != 0 and die "mktemp failed with status $?\n";
chomp $file;

print "The notification socket is '$file'\n";

!defined(bind(SOCK, sockaddr_un($file))) and 
    die "binding '$file' failed : $!\n";

print "Run UML with\n\tmconsole=notify:$file\non the command line.\n";
print "Then, inside UML, write messages into /proc/mconsole\n";

while(1){
    my $data;

    !defined(recv(SOCK, $data, 4096, 0)) and 
	die "recv from '$file' failed : $!";

    my ($magic, $version, $type, $len, $message) = unpack("LiiiA*", $data);
    print "Received message -\n";
    printf "\tmagic = 0x%x\n", $magic;
    print "\tversion = $version\n";
    print "\tmessage type = $type (" . $types[$type] . ")\n";
    print "\tmessage length = $len\n";
    print "\tmessage = '$message'\n\n";
}