chiark / gitweb /
[PATCH] add IGNORE rule type
[elogind.git] / udevdb.c
index ec67a079627df09cec9cdf5a1733d99e87139051..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>
@@ -54,36 +55,29 @@ int udevdb_add_dev(const char *path, const struct udevice *dev)
        strcpy(keystr, path);
        key.dptr = keystr;
        key.dsize = strlen(keystr) + 1;
-       
+
        data.dptr = (void *)dev;
        data.dsize = sizeof(*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;
+               return -ENODEV;
 
-       dev = malloc(sizeof(*dev));
-       if (dev == NULL)
-               goto exit;
-       
        memcpy(dev, data.dptr, sizeof(*dev));
-exit:
-       free(data.dptr);
-       return dev;
+       return 0;
 }
 
 int udevdb_delete_dev(const char *path)
@@ -99,7 +93,7 @@ int udevdb_delete_dev(const char *path)
 
        key.dptr = keystr;
        key.dsize = strlen(keystr) + 1;
-       
+
        return tdb_delete(udevdb, key);
 }
 
@@ -116,8 +110,8 @@ void udevdb_exit(void)
 
 /**
  * udevdb_init: initializes database
- * @init_flag: database can either be in memory - UDEVDB_INTERNAL - or
- *     written to a file with UDEVDB_DEFAULT.
+ * @init_flag: UDEVDB_INTERNAL - database stays in memory
+ *            UDEVDB_DEFAULT - database is written to a file
  */
 int udevdb_init(int init_flag)
 {
@@ -127,9 +121,22 @@ int udevdb_init(int init_flag)
        udevdb = tdb_open(udev_db_filename, 0, init_flag, O_RDWR | O_CREAT, 0644);
        if (udevdb == NULL) {
                if (init_flag == UDEVDB_INTERNAL)
-                       dbg("Unable to initialize in-memory database");
+                       dbg("unable to initialize in-memory database");
                else
-                       dbg("Unable to initialize database at %s", udev_db_filename);
+                       dbg("unable to initialize database at '%s'", udev_db_filename);
+               return -EINVAL;
+       }
+       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;