+
+ if (ret < 0)
+ if (matchpathcon(file, mode, &scontext) < 0) {
+ err("matchpathcon(%s) failed\n", file);
+ return;
+ }
+
+ if (lsetfilecon(file, scontext) < 0)
+ err("setfilecon %s failed: %s\n", file, strerror(errno));
+
+ freecon(scontext);
+ }
+}
+
+void selinux_setfscreatecon(const char *file, const char *devname, unsigned int mode)
+{
+ if (is_selinux_running()) {
+ security_context_t scontext = NULL;
+ char *media;
+ int ret = -1;
+
+ if (devname) {
+ media = get_media(devname, mode);
+ if (media) {
+ ret = matchmediacon(media, &scontext);
+ free(media);
+ }
+ }
+
+ if (ret < 0)
+ if (matchpathcon(file, mode, &scontext) < 0) {
+ err("matchpathcon(%s) failed\n", file);
+ return;
+ }
+
+ if (setfscreatecon(scontext) < 0)
+ err("setfscreatecon %s failed: %s\n", file, strerror(errno));
+
+ freecon(scontext);