From: Michael Tremer Date: Tue, 28 Jan 2014 16:22:56 +0000 (+0100) Subject: Catch exception when the hardware serial number cannot be read. X-Git-Tag: v2.1.8~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7890c77581f4494dbf6550ef60a7185d8e5ad5f6;p=oddments%2Ffireinfo.git Catch exception when the hardware serial number cannot be read. --- diff --git a/src/_fireinfo/fireinfo.c b/src/_fireinfo/fireinfo.c index 08d714b..4ab2bfa 100644 --- a/src/_fireinfo/fireinfo.c +++ b/src/_fireinfo/fireinfo.c @@ -197,13 +197,15 @@ do_get_harddisk_serial(PyObject *o, PyObject *args) { */ static struct hd_driveid hd; int fd; - char *device; + const char *device = NULL; if (!PyArg_ParseTuple(args, "s", &device)) return NULL; - if ((fd = open(device, O_RDONLY | O_NONBLOCK)) < 0) + if ((fd = open(device, O_RDONLY | O_NONBLOCK)) < 0) { + PyErr_Format(PyExc_OSError, "Could not open block device: %s", device); return NULL; + } if (!ioctl(fd, HDIO_GET_IDENTITY, &hd)) { char serial[21]; diff --git a/src/fireinfo/system.py b/src/fireinfo/system.py index 9db536b..800032e 100644 --- a/src/fireinfo/system.py +++ b/src/fireinfo/system.py @@ -397,7 +397,10 @@ class System(object): """ Return the serial number of the root disk (if any). """ - serial = _fireinfo.get_harddisk_serial("/dev/%s" % self.root_disk) + try: + serial = _fireinfo.get_harddisk_serial("/dev/%s" % self.root_disk) + except OSError: + return if serial: # Strip all spaces