mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
udevd: at startup create /dev/null, /dev/console, /dev/kmsg
This commit is contained in:
parent
ccc87b0e99
commit
540f46698d
@ -22,7 +22,7 @@
|
||||
#include "libudev.h"
|
||||
#include "libudev-private.h"
|
||||
|
||||
/* last known version with this wire protocol */
|
||||
/* wire protocol magic must match */
|
||||
#define UDEV_CTRL_MAGIC 0xdead1dea
|
||||
|
||||
enum udev_ctrl_msg_type {
|
||||
|
@ -68,7 +68,7 @@ static int name_index(struct udev *udev, const char *devpath, const char *name,
|
||||
int udev_node_mknod(struct udev_device *dev, const char *file, dev_t devnum, mode_t mode, uid_t uid, gid_t gid)
|
||||
{
|
||||
struct udev *udev = udev_device_get_udev(dev);
|
||||
char file_tmp[UTIL_PATH_SIZE + sizeof(TMP_FILE_EXT)];
|
||||
char filename[UTIL_PATH_SIZE];
|
||||
struct stat stats;
|
||||
int preserve = 0;
|
||||
int err = 0;
|
||||
@ -81,8 +81,14 @@ int udev_node_mknod(struct udev_device *dev, const char *file, dev_t devnum, mod
|
||||
else
|
||||
mode |= S_IFCHR;
|
||||
|
||||
if (file == NULL)
|
||||
if (file == NULL) {
|
||||
file = udev_device_get_devnode(dev);
|
||||
} else if (file[0] != '/') {
|
||||
util_strlcpy(filename, udev_get_dev_path(udev), sizeof(filename));
|
||||
util_strlcat(filename, "/", sizeof(filename));
|
||||
util_strlcat(filename, file, sizeof(filename));
|
||||
file = filename;
|
||||
}
|
||||
|
||||
if (lstat(file, &stats) == 0) {
|
||||
if (((stats.st_mode & S_IFMT) == (mode & S_IFMT)) && (stats.st_rdev == devnum)) {
|
||||
@ -90,6 +96,8 @@ int udev_node_mknod(struct udev_device *dev, const char *file, dev_t devnum, mod
|
||||
preserve = 1;
|
||||
udev_selinux_lsetfilecon(udev, file, mode);
|
||||
} else {
|
||||
char file_tmp[UTIL_PATH_SIZE + sizeof(TMP_FILE_EXT)];
|
||||
|
||||
info(udev, "atomically replace existing file '%s'\n", file);
|
||||
util_strlcpy(file_tmp, file, sizeof(file_tmp));
|
||||
util_strlcat(file_tmp, TMP_FILE_EXT, sizeof(file_tmp));
|
||||
|
24
udev/udevd.c
24
udev/udevd.c
@ -708,6 +708,28 @@ static void export_initial_seqnum(struct udev *udev)
|
||||
}
|
||||
}
|
||||
|
||||
/* create the nodes the we depend on to properly start up */
|
||||
static void setup_initial_nodes(struct udev *udev)
|
||||
{
|
||||
struct udev_device *dev;
|
||||
|
||||
dev = udev_device_new_from_subsystem_sysname(udev, "mem", "null");
|
||||
if (dev != NULL) {
|
||||
udev_node_mknod(dev, "null", makedev(0,0), 0666, 0, 0);
|
||||
udev_device_unref(dev);
|
||||
}
|
||||
dev = udev_device_new_from_subsystem_sysname(udev, "mem", "kmsg");
|
||||
if (dev != NULL) {
|
||||
udev_node_mknod(dev, "kmsg", makedev(0,0), 0660, 0, 0);
|
||||
udev_device_unref(dev);
|
||||
}
|
||||
dev = udev_device_new_from_subsystem_sysname(udev, "tty", "console");
|
||||
if (dev != NULL) {
|
||||
udev_node_mknod(dev, "console", makedev(0,0), 0600, 0, 0);
|
||||
udev_device_unref(dev);
|
||||
}
|
||||
}
|
||||
|
||||
static void startup_log(struct udev *udev)
|
||||
{
|
||||
FILE *f;
|
||||
@ -814,6 +836,8 @@ int main(int argc, char *argv[])
|
||||
goto exit;
|
||||
}
|
||||
|
||||
setup_initial_nodes(udev);
|
||||
|
||||
/* make sure std{in,out,err} fd's are in a sane state */
|
||||
fd = open("/dev/null", O_RDWR);
|
||||
if (fd < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user