summaryrefslogtreecommitdiffstats
path: root/emergencyd.pl
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-02-22 15:03:47 +0100
committerDavid A. Madore <david+git@madore.org>2010-02-22 15:03:47 +0100
commit11c4e8510a0de2850f5ee637ae846980fcabe759 (patch)
tree121aeee197b139fff06fa5d640c8ce62c9ee00b8 /emergencyd.pl
parentd1ae14233a8a106aff4bfaf61080cef916d48632 (diff)
downloademergency-11c4e8510a0de2850f5ee637ae846980fcabe759.tar.gz
emergency-11c4e8510a0de2850f5ee637ae846980fcabe759.tar.bz2
emergency-11c4e8510a0de2850f5ee637ae846980fcabe759.zip
Implement LOGM command (write a message to syslog).
Diffstat (limited to 'emergencyd.pl')
-rwxr-xr-xemergencyd.pl29
1 files changed, 24 insertions, 5 deletions
diff --git a/emergencyd.pl b/emergencyd.pl
index fe21de6..0668110 100755
--- a/emergencyd.pl
+++ b/emergencyd.pl
@@ -33,10 +33,13 @@
# quit. The RKEY command causes the daemon to reread its key file:
# the server responds either DONE or !ERR in case of error, in which
# case the next line in the response is a human-readable error line.
-# The SYRQ command is followed by whitespace and then by data to be
-# written to /proc/sysrq-trigger: the server responds either DONE or
-# !ERR in case of error, in which case the next line in the response
-# is a human-readable error line.
+# The LOGM command is followed by whitespace, an optional priority (as
+# in the LOG_* syslog macros: WARNING, DEBUG, etc.; again followed by
+# whitespace), and a message to be written to syslog: the server
+# responds DONE. The SYRQ command is followed by whitespace and then
+# by data to be written to /proc/sysrq-trigger: the server responds
+# either DONE or !ERR in case of error, in which case the next line in
+# the response is a human-readable error line.
# *** The emergency daemon itself ***
#
@@ -60,10 +63,12 @@ use Digest::SHA qw(hmac_sha256_hex);
use Socket;
use Socket6;
use POSIX ();
+use Sys::Syslog qw(:standard :macros);
use Getopt::Std;
use constant {
- DEFAULT_PORT => 911
+ DEFAULT_PORT => 911,
+ SYSLOG_IDENT => "emergencyd.pl"
};
my %opts;
@@ -103,6 +108,8 @@ if ( defined(*IPV6_V6ONLY{CODE}) ) {
}
bind $socket, sockaddr_in6($port, in6addr_any) or die "Can't bind socket: $!";
+openlog(SYSLOG_IDENT, "ndelay,pid", LOG_DAEMON);
+
if ( $opts{f} ) {
chdir("/");
open STDIN, "/dev/null";
@@ -177,6 +184,18 @@ while (1) {
$resp = "!ERR\n$@";
}
send $socket, $resp, 0, $sender;
+ } elsif ( $command =~ /^LOGM\s+(.*)$/ ) {
+ my $s = $1;
+ my $level = LOG_NOTICE;
+ my %levels = ("EMERG"=>LOG_EMERG, "ALERT"=>LOG_ALERT,
+ "CRIT"=>LOG_CRIT, "ERR"=>LOG_ERR, "WARNING"=>LOG_WARNING,
+ "NOTICE"=>LOG_NOTICE, "INFO"=>LOG_INFO, "DEBUG"=>LOG_DEBUG);
+ if ( $s =~ /^([A-Z0-9]*)\s+(.*)/ && exists($levels{$1}) ) {
+ $level = $levels{$1};
+ $s = $2;
+ }
+ syslog $level, $s;
+ send $socket, "DONE\n", 0, $sender;
} elsif ( $command =~ /^SYRQ\s+(.*)$/ ) {
my $s = $1;
my $resp = "DONE\n";