+#endif
+#ifdef HAVE_SMACK
+#include <sys/xattr.h>
+#include <string.h>
+#define FLOOR_LABEL "_"
+#define STAR_LABEL "*"
+
+static void smack_relabel_in_dev(const char *path) {
+ struct stat sb;
+ const char *label;
+ int r;
+
+ /*
+ * Path must be in /dev and must exist
+ */
+ if (!path_equal(path, "/dev") &&
+ !path_startswith(path, "/dev"))
+ return;
+
+ r = lstat(path, &sb);
+ if (r < 0)
+ return;
+
+ /*
+ * Label directories and character devices "*".
+ * Label symlinks "_".
+ * Don't change anything else.
+ */
+ if (S_ISDIR(sb.st_mode))
+ label = STAR_LABEL;
+ else if (S_ISLNK(sb.st_mode))
+ label = FLOOR_LABEL;
+ else if (S_ISCHR(sb.st_mode))
+ label = STAR_LABEL;
+ else
+ return;
+
+ r = setxattr(path, "security.SMACK64", label, strlen(label), 0);
+ if (r < 0)
+ log_error("Smack relabeling \"%s\" %s", path, strerror(errno));
+ return;
+}