]> git.ipfire.org Git - people/stevee/guardian.git/blobdiff - modules/Socket.pm
Adjust Parser and Socket module outputs.
[people/stevee/guardian.git] / modules / Socket.pm
index cdcca0016d35fbb14c6c222cb08f43af32543e48..9c1985c924bc253a5a2af06e918a9a3f352258eb 100644 (file)
@@ -4,7 +4,7 @@ use warnings;
 
 use Exporter qw(import);
 
-our @EXPORT_OK = qw(Server Client Message_Parser);
+our @EXPORT_OK = qw(Server Client Message_Parser RemoveSocketFile);
 
 use IO::Socket::UNIX qw( SOCK_STREAM SOMAXCONN );
 
@@ -33,13 +33,13 @@ sub Server () {
        # If the path for the socketfile does not exist, try to
        # create it.
        unless (-d "$socketpath") {
-               mkdir("$socketpath") or die "Could not create $socketpath: $!\n";
+               mkdir("$socketpath") or die "Could not create $socketpath: $!";
        }
 
        # Delete an existing socket file.
        if (-e "$socketfile") {
                unlink $socketfile
-               or die "Could not release existing socket file: $!\n";
+               or die "Could not release existing socket file: $!";
        }
 
        # Create a new UNIX socket.
@@ -47,7 +47,7 @@ sub Server () {
                Local => $socketfile,
                Listen => SOMAXCONN,
                Type => SOCK_STREAM,
-       ) or die "Could not create socket: $!\n";
+       ) or die "Could not create socket: $!";
 
        # Return the server object.
        return $server;
@@ -102,7 +102,7 @@ sub Message_Parser ($) {
                if ($optarg) {
                        # The message is valid, return the event and
                        # the optional argument.
-                       return "$supported_commands{$command} $optarg";
+                       return "$supported_commands{$command} $optarg Socket User-requested action.";
                } else {
                        # Only return the event for the recieved command.
                        return "$supported_commands{$command}";
@@ -114,4 +114,17 @@ sub Message_Parser ($) {
        return undef;
 }
 
+#
+## RemoveSocketFile function.
+#
+## A tiny function which just removes an existing Socket file.
+#
+sub RemoveSocketFile () {
+       # Check if a socketfile exists.
+       if (-e $socketfile) {
+               # Delete the socket file.
+               unlink($socketfile);
+       }
+}
+
 1;