chiark / gitweb /
[PATCH] support SUBSYSTEM as a rule key
[elogind.git] / test / udevd-test / udev-log-script.pl
1 #!/usr/bin/perl -w
2 #
3 # udev-log-script
4 #
5 # Copyright (C) Intel Corp, 2004
6 #
7 # Author: Yin Hu <hu.yin@intel.com> 
8 #
9 # This is a script for replacing udev binary during udevsend/udevd testing.
10 # It just simply logs the event information sent by udved in order to
11 # test script udevd-test.pl can analyze whether udved execute as we expected.
12 # You should not execute this script directly because it will be invoked by
13 # udevd automatically.
14 #
15 # Before you run your test please modify $log_file to designate where the udev
16 # log file should be placed, in fact, the default value is ok.
17 #
18
19 #       This program is free software; you can redistribute it and/or modify it
20 #       under the terms of the GNU General Public License as published by the
21 #       Free Software Foundation version 2 of the License.
22 #  
23 #       This program is distributed in the hope that it will be useful, but
24 #       WITHOUT ANY WARRANTY; without even the implied warranty of
25 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26 #       General Public License for more details.
27 #
28 #       You should have received a copy of the GNU General Public License along
29 #       with this program; if not, write to the Free Software Foundation, Inc.,
30 #       675 Mass Ave, Cambridge, MA 02139, USA.
31 #
32
33 use warnings;
34 use strict;
35
36 # modifiable settings
37 my $log_file  = "/tmp/udev_log.txt";
38
39 # global variables
40 my $devpath;
41 my $action;
42 my $subsystem;
43
44 # common functions
45 sub getDate {
46         # Get current date/time
47         # If we want GTM time, simply pass GMT as first argument to this function.
48         my $format = @_;
49         my $date;
50
51         if( $format =~ /GMT/i ) {
52                 $date = gmtime() . " GMT";
53         } else {
54                 $date = localtime();
55         }
56         return $date;
57 }
58
59 # main program
60 if ($ARGV[0]) {
61         # prepare
62         $subsystem = $ARGV[0];
63         $devpath = $ENV{DEVPATH};
64         $action = $ENV{ACTION};
65
66         # Get current system date
67         my $time = getDate();
68
69         # Logging
70         if (open(LOGF, ">>$log_file")) {
71                 print LOGF "$devpath,$action,$subsystem,$time\n";
72         } else {
73                 print "File open failed. \n";
74                 exit 1;
75         }
76         close(LOGF);
77
78         exit 0;
79 } else {
80         print "Too less argument count.\n";
81         exit 1;
82 }