Skip to content

Commit

Permalink
Don't fail when it wasn't possible to fetch the interface name.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
twasilczyk committed Jan 15, 2019
1 parent 2328c6c commit af93051
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions slcand.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,13 @@ int main(int argc, char *argv[])

/* retrieve the name of the created CAN netdevice */
if (ioctl(fd, SIOCGIFNAME, buf) < 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(buf, sizeof(buf), "<unknown>");
}
}

syslogger(LOG_NOTICE, "attached TTY %s to netdevice %s\n", ttypath, buf);
Expand Down

0 comments on commit af93051

Please sign in to comment.