Subject: | [patch] please add support for mpd on a Unix socket |
Since mpd 0.14 (2008) it has been possible for mpd to listen on an AF_UNIX socket. Access is controlled by Unix filesystem permissions, making a password unnecessary.
The convention seems to be to set MPD_HOST to the absolute path to the socket, e.g. "/home/me/.cache/mpd.socket", ignoring MPD_PORT; and to recognise these connections via the leading "/".
The attached patch adds support for this, and seems to be enough to enable mpd-dynamic to work in this configuration.
Subject: | 0001-Recognise-MPD_HOST-.-as-a-Unix-socket.patch |
From ffb8b89ca45ca1984b780e81ea77cf8957c308e8 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@debian.org>
Date: Thu, 23 Oct 2014 21:32:19 +0100
Subject: [PATCH] Recognise MPD_HOST="/..." as a Unix socket
---
lib/Audio/MPD.pm | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/lib/Audio/MPD.pm b/lib/Audio/MPD.pm
index 530ef29..ffab9fc 100644
--- a/lib/Audio/MPD.pm
+++ b/lib/Audio/MPD.pm
@@ -38,7 +38,7 @@ has collection => ( ro, lazy_build, isa=>'Audio::MPD::Collection' );
has playlist => ( ro, lazy_build, isa=>'Audio::MPD::Playlist' );
has version => ( rw );
-has _socket => ( rw, isa=>'IO::Socket::IP' );
+has _socket => ( rw, isa=>'IO::Socket' );
#--
@@ -93,11 +93,21 @@ sub _connect_to_mpd_server {
my ($self) = @_;
# try to connect to mpd.
- my $socket = IO::Socket::IP->new(
- PeerAddr => $self->host,
- PeerPort => $self->port,
- )
- or die "Could not create socket: $!\n";
+ my $socket;
+
+ if ($self->host =~ m{^/}) {
+ eval q{use IO::Socket::UNIX qw(); 1}
+ or die "Could not load IO::Socket::UNIX: $@\n";
+ $socket = IO::Socket::UNIX->new($self->host)
+ or die "Could not create socket: $!\n";
+ }
+ else {
+ $socket = IO::Socket::IP->new(
+ PeerAddr => $self->host,
+ PeerPort => $self->port,
+ )
+ or die "Could not create socket: $!\n";
+ }
# parse version information.
my $line = $socket->getline;
--
2.1.1