]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
Catch exception when the hardware serial number cannot be read.
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Jan 2014 16:22:56 +0000 (17:22 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Jan 2014 16:50:11 +0000 (17:50 +0100)
src/_fireinfo/fireinfo.c
src/fireinfo/system.py

index 08d714bd2b72a2c3fd3f446bc5302fcdf5b3fec3..4ab2bfad7083aa61275037c3d5b55cc36766626f 100644 (file)
@@ -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];
index 9db536b2136d4de9c9a131eeeb9e06ccdf451a2a..800032ee8932023bdd293302ecada44100080e27 100644 (file)
@@ -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