chiark / gitweb /
util: generalize code that checks whether PIDs are alive or unwaited for
[elogind.git] / src / shared / label.c
index 1fe4574633ef888089d3fbb4ea612f7badb84a0c..4a26ba9c5d1393a5a14d6981980473a6e2f5db9e 100644 (file)
@@ -20,7 +20,6 @@
 ***/
 
 #include <errno.h>
-#include <sys/stat.h>
 #include <unistd.h>
 #include <malloc.h>
 #include <sys/socket.h>
@@ -257,14 +256,14 @@ void label_free(const char *label) {
 #endif
 }
 
-int label_mkdir(const char *path, mode_t mode, bool apply) {
+int label_mkdir(const char *path, mode_t mode) {
 
         /* Creates a directory and labels it according to the SELinux policy */
 #ifdef HAVE_SELINUX
         int r;
         security_context_t fcon = NULL;
 
-        if (!apply || !use_selinux() || !label_hnd)
+        if (!use_selinux() || !label_hnd)
                 goto skipped;
 
         if (path_is_absolute(path))
@@ -384,3 +383,15 @@ skipped:
 #endif
         return bind(fd, addr, addrlen) < 0 ? -errno : 0;
 }
+
+int label_apply(const char *path, const char *label) {
+        int r = 0;
+
+#ifdef HAVE_SELINUX
+        if (!use_selinux())
+                return 0;
+
+        r = setfilecon(path, (char *)label);
+#endif
+        return r;
+}