From 7a318636e779cd68e00d56452ee8fe5f406b7dd5 Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Tue, 15 Jan 2019 14:22:01 -0800 Subject: [PATCH] slcand: Don't fail when it wasn't possible to fetch the interface name. On some systems SIOCGIFNAME may fail with ENOTTY, but the actual slcanX interface gets properly configured. Instead of crashing hard on such case, let's gracefuly degrade and just not display the interface name. --- slcand.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/slcand.c b/slcand.c index 3f8898b..29f47a1 100644 --- a/slcand.c +++ b/slcand.c @@ -370,8 +370,13 @@ int main(int argc, char *argv[]) /* retrieve the name of the created CAN netdevice */ if (ioctl(fd, SIOCGIFNAME, ifr.ifr_name) < 0) { - perror("ioctl SIOCGIFNAME"); - exit(EXIT_FAILURE); + if (name) { + perror("ioctl SIOCGIFNAME"); + exit(EXIT_FAILURE); + } else { + /* Graceful degradation: we only needed the name for display. */ + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), ""); + } } syslogger(LOG_NOTICE, "attached TTY %s to netdevice %s\n", ttypath, ifr.ifr_name);