chiark / gitweb /
[PATCH] move the config files to etc/udev to clean up main directory a bit.
[elogind.git] / udevdb.c
index e0bd39e84bb9a15529e3f945ab61e756fa0e5e54..ca9e63c97e61d4376f0d9593b2c54b3a4b936bcf 100644 (file)
--- a/udevdb.c
+++ b/udevdb.c
@@ -24,6 +24,7 @@
 /*
  * udev database library
  */
+#define _KLIBC_HAS_ARCH_SIG_ATOMIC_T
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
@@ -61,29 +62,22 @@ int udevdb_add_dev(const char *path, const struct udevice *dev)
        return tdb_store(udevdb, key, data, TDB_REPLACE); 
 }
 
-struct udevice *udevdb_get_dev(const char *path)
+int udevdb_get_dev(const char *path, struct udevice *dev)
 {
        TDB_DATA key, data;
-       struct udevice *dev;
 
        if (path == NULL)
-               return NULL;
+               return -ENODEV;
 
        key.dptr = (void *)path;
        key.dsize = strlen(path) + 1;
 
        data = tdb_fetch(udevdb, key);
        if (data.dptr == NULL || data.dsize == 0)
-               return NULL;
-
-       dev = malloc(sizeof(*dev));
-       if (dev == NULL)
-               goto exit;
+               return -ENODEV;
 
        memcpy(dev, data.dptr, sizeof(*dev));
-exit:
-       free(data.dptr);
-       return dev;
+       return 0;
 }
 
 int udevdb_delete_dev(const char *path)
@@ -134,3 +128,16 @@ int udevdb_init(int init_flag)
        }
        return 0;
 }
+
+/**
+ * udevdb_open_ro: open database for reading
+ */
+int udevdb_open_ro(void)
+{
+       udevdb = tdb_open(udev_db_filename, 0, 0, O_RDONLY, 0);
+       if (udevdb == NULL) {
+               dbg("unable to open database at '%s'", udev_db_filename);
+               return -EINVAL;
+       }
+       return 0;
+}