From 3e213d31149603ee309aaf5acc53b7c8d0ee0fbb Mon Sep 17 00:00:00 2001 From: Stelian Ionescu Date: Tue, 8 Jun 2021 22:54:35 -0400 Subject: [PATCH] Ignore non-existent /etc/hosts Fixes #64 --- src/sockets/namedb/hosts.lisp | 5 +++-- tests/sockets.lisp | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sockets/namedb/hosts.lisp b/src/sockets/namedb/hosts.lisp index fccb8d55..f2c0cdd5 100644 --- a/src/sockets/namedb/hosts.lisp +++ b/src/sockets/namedb/hosts.lisp @@ -52,8 +52,9 @@ (destructuring-bind (address cname &rest aliases) tokens (push (make-host cname (ensure-address address) aliases) hosts)))) - (map-etc-file (lambda (tokens) (ignore-errors (parse-one-line tokens))) - file) + (alexandria:ignore-some-conditions (file-error) + (map-etc-file (lambda (tokens) (ignore-errors (parse-one-line tokens))) + file)) (nreverse hosts)))) (defun search-host-by-name (name ipv6) diff --git a/tests/sockets.lisp b/tests/sockets.lisp index fd9b8e09..06cd8333 100644 --- a/tests/sockets.lisp +++ b/tests/sockets.lisp @@ -187,6 +187,9 @@ (defparameter *google-ns* (list #/ip/8.8.8.8 #/ip/8.8.4.4)) +(test (missing-hosts-file :compile-at :definition-time) + (is-false (iolib/sockets::parse-/etc/hosts "/foo/no-such-file"))) + #-no-internet-available (test (lookup-hostname.1 :compile-at :definition-time) (is (equalp (multiple-value-bind (address addresses truename)