]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/udev/udev-node.c
util-lib: move a number of fs operations into fs-util.[ch]
[thirdparty/systemd.git] / src / udev / udev-node.c
index f105fa28e2c5b254e7ee787ddb901db47dd882ed..afdeb0a21beabb65dd0d9ec84d406d6f9680a58d 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <stdbool.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <grp.h>
 #include <dirent.h>
-#include <sys/time.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
 #include <sys/stat.h>
-#include <sys/types.h>
+#include <unistd.h>
 
-#include "udev.h"
+#include "formats-util.h"
+#include "fs-util.h"
+#include "selinux-util.h"
 #include "smack-util.h"
+#include "string-util.h"
+#include "udev.h"
 
 static int node_symlink(struct udev_device *dev, const char *node, const char *slink) {
         struct stat stats;
@@ -112,12 +112,12 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s
                 mac_selinux_create_file_clear();
         } while (err == -ENOENT);
         if (err != 0) {
-                log_error("symlink '%s' '%s' failed: %m", target, slink_tmp);
+                log_error_errno(errno, "symlink '%s' '%s' failed: %m", target, slink_tmp);
                 goto exit;
         }
         err = rename(slink_tmp, slink);
         if (err != 0) {
-                log_error("rename '%s' '%s' failed: %m", slink_tmp, slink);
+                log_error_errno(errno, "rename '%s' '%s' failed: %m", slink_tmp, slink);
                 unlink(slink_tmp);
         }
 exit:
@@ -264,7 +264,7 @@ static int node_permissions_apply(struct udev_device *dev, bool apply,
 
         if (lstat(devnode, &stats) != 0) {
                 err = -errno;
-                log_debug("can not stat() node '%s' (%m)", devnode);
+                log_debug_errno(errno, "can not stat() node '%s' (%m)", devnode);
                 goto out;
         }
 
@@ -283,10 +283,10 @@ static int node_permissions_apply(struct udev_device *dev, bool apply,
                         log_debug("set permissions %s, %#o, uid=%u, gid=%u", devnode, mode, uid, gid);
                         err = chmod(devnode, mode);
                         if (err < 0)
-                                log_warning("setting mode of %s to %#o failed: %m", devnode, mode);
+                                log_warning_errno(errno, "setting mode of %s to %#o failed: %m", devnode, mode);
                         err = chown(devnode, uid, gid);
                         if (err < 0)
-                                log_warning("setting owner of %s to uid=%u, gid=%u failed: %m", devnode, uid, gid);
+                                log_warning_errno(errno, "setting owner of %s to uid=%u, gid=%u failed: %m", devnode, uid, gid);
                 } else {
                         log_debug("preserve permissions %s, %#o, uid=%u, gid=%u", devnode, mode, uid, gid);
                 }
@@ -304,16 +304,16 @@ static int node_permissions_apply(struct udev_device *dev, bool apply,
 
                                 r = mac_selinux_apply(devnode, label);
                                 if (r < 0)
-                                        log_error_errno(-r, "SECLABEL: failed to set SELinux label '%s': %m", label);
+                                        log_error_errno(r, "SECLABEL: failed to set SELinux label '%s': %m", label);
                                 else
                                         log_debug("SECLABEL: set SELinux label '%s'", label);
 
                         } else if (streq(name, "smack")) {
                                 smack = true;
 
-                                r = mac_smack_apply(devnode, label);
+                                r = mac_smack_apply(devnode, SMACK_ATTR_ACCESS, label);
                                 if (r < 0)
-                                        log_error_errno(-r, "SECLABEL: failed to set SMACK label '%s': %m", label);
+                                        log_error_errno(r, "SECLABEL: failed to set SMACK label '%s': %m", label);
                                 else
                                         log_debug("SECLABEL: set SMACK label '%s'", label);
 
@@ -325,7 +325,7 @@ static int node_permissions_apply(struct udev_device *dev, bool apply,
                 if (!selinux)
                         mac_selinux_fix(devnode, true, false);
                 if (!smack)
-                        mac_smack_apply(devnode, NULL);
+                        mac_smack_apply(devnode, SMACK_ATTR_ACCESS, NULL);
         }
 
         /* always update timestamp when we re-use the node, like on media change events */
@@ -340,7 +340,7 @@ void udev_node_add(struct udev_device *dev, bool apply,
         char filename[UTIL_PATH_SIZE];
         struct udev_list_entry *list_entry;
 
-        log_debug("handling device node '%s', devnum=%s, mode=%#o, uid=%d, gid=%d",
+        log_debug("handling device node '%s', devnum=%s, mode=%#o, uid="UID_FMT", gid="GID_FMT,
                   udev_device_get_devnode(dev), udev_device_get_id_filename(dev), mode, uid, gid);
 
         if (node_permissions_apply(dev, apply, mode, uid, gid, seclabel_list) < 0)