~ubuntu-branches/ubuntu/raring/uml-utilities/raring

« back to all changes in this revision

Viewing changes to mconsole/notify.pl

  • Committer: Bazaar Package Importer
  • Author(s): Matt Zimmerman
  • Date: 2004-04-14 17:59:45 UTC
  • mto: (4.1.3 hardy)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040414175945-yluoug8v60dnwmvu
Tags: upstream-20040406
ImportĀ upstreamĀ versionĀ 20040406

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use Socket;
 
2
use strict;
 
3
 
 
4
my $MCONSOLE_SOCKET = 0;
 
5
my $MCONSOLE_PANIC = 1;
 
6
my $MCONSOLE_HANG = 2;
 
7
my $MCONSOLE_USER_NOTIFY = 3;
 
8
 
 
9
my @types = ( "socket", "panic", "hang", "user notification" );
 
10
 
 
11
!defined(socket(SOCK, AF_UNIX, SOCK_DGRAM, 0)) and 
 
12
    die "socket() failed : $!\n";
 
13
 
 
14
# XXX the -u causes mktemp to unlink the file - this is needed because
 
15
# we don't want a normal file, we want a socket.
 
16
 
 
17
my $file = `mktemp -u /tmp/mconsole.XXXXXX`;
 
18
$? != 0 and die "mktemp failed with status $?\n";
 
19
chomp $file;
 
20
 
 
21
print "The notification socket is '$file'\n";
 
22
 
 
23
!defined(bind(SOCK, sockaddr_un($file))) and 
 
24
    die "binding '$file' failed : $!\n";
 
25
 
 
26
print "Run UML with\n\tmconsole=notify:$file\non the command line.\n";
 
27
print "Then, inside UML, write messages into /proc/mconsole\n";
 
28
 
 
29
while(1){
 
30
    my $data;
 
31
 
 
32
    !defined(recv(SOCK, $data, 4096, 0)) and 
 
33
        die "recv from '$file' failed : $!";
 
34
 
 
35
    my ($magic, $version, $type, $len, $message) = unpack("LiiiA*", $data);
 
36
    print "Received message -\n";
 
37
    printf "\tmagic = 0x%x\n", $magic;
 
38
    print "\tversion = $version\n";
 
39
    print "\tmessage type = $type (" . $types[$type] . ")\n";
 
40
    print "\tmessage length = $len\n";
 
41
    print "\tmessage = '$message'\n\n";
 
42
}