From b3b33f858651308c27b340ed94bf8eb4e82accfc Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 12 Jun 2014 16:44:07 +0200 Subject: [PATCH] modem-lib.pl: Check if character device exists before trying to connect to it. --- config/cfgroot/modem-lib.pl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/config/cfgroot/modem-lib.pl b/config/cfgroot/modem-lib.pl index 51b6d68e9c..5d43cc176e 100644 --- a/config/cfgroot/modem-lib.pl +++ b/config/cfgroot/modem-lib.pl @@ -33,7 +33,10 @@ sub new() { bless $self, $class; # Initialize the connetion to the modem. - $self->_initialize($port, $baud); + my $ret = $self->_initialize($port, $baud); + if ($ret) { + return undef; + } if ($self->_is_working()) { return $self; @@ -54,9 +57,16 @@ sub DESTROY() { sub _initialize() { my ($self, $port, $baud) = @_; + # Check if the character device actually exists. + if (! -c $port) { + return 1; + } + # Establish connection to the modem. $self->{modem} = new Device::Modem(port => $port); $self->{modem}->connect(baudrate => $baud); + + return 0; } sub _is_working() { -- 2.39.5