chiark / gitweb /
[PATCH] provide temporary device node for callouts to access the device
[elogind.git] / udev_utils.c
index 5b0355d0e9986722d3b32f348ab9035a61b53ac0..ca46258def32d2059430c9f75f04586886f7f312 100644 (file)
@@ -112,6 +112,31 @@ int create_path(const char *path)
        return mkdir(p, 0755);
 }
 
+/* Reset permissions on the device node, before unlinking it to make sure,
+ * that permisions of possible hard links will be removed to.
+ */
+int unlink_secure(const char *filename)
+{
+       int retval;
+
+       retval = chown(filename, 0, 0);
+       if (retval)
+               dbg("chown(%s, 0, 0) failed with error '%s'", filename, strerror(errno));
+
+       retval = chmod(filename, 0000);
+       if (retval)
+               dbg("chmod(%s, 0000) failed with error '%s'", filename, strerror(errno));
+
+       retval = unlink(filename);
+       if (errno == ENOENT)
+               retval = 0;
+
+       if (retval)
+               dbg("unlink(%s) failed with error '%s'", filename, strerror(errno));
+
+       return retval;
+}
+
 int parse_get_pair(char **orig_string, char **left, char **right)
 {
        char *temp;