const char* first, const char* second);
const char* pakfire_path_relpath(const char* root, const char* path);
+int pakfire_touch(const char* path, mode_t mode);
int pakfire_mkparentdir(const char* path, mode_t mode);
int pakfire_mkdir(const char* path, mode_t mode);
FILE* pakfire_mktemp(char* path);
dev_t dev = makedev(devnode->major, devnode->minor);
r = mknod(path, devnode->mode, dev);
+
+ // Continue if mknod was successful
+ if (r == 0)
+ continue;
+
+ // If we could not create the device node because of permission issues,
+ // it might be likely that we are running in a user namespace where creating
+ // device nodes is not permitted. Try bind-mounting them.
+ if (errno == EPERM)
+ goto MOUNT;
+
+ // Otherwise log an error and end
+ ERROR(pakfire, "Could not create %s: %m\n", devnode->path);
+ return r;
+
+MOUNT:
+ // Create an empty file
+ r = pakfire_touch(path, 0444);
if (r) {
- ERROR(pakfire, "Could not create %s: %m\n", devnode->path);
+ ERROR(pakfire, "Could not create %s: %m\n", path);
return r;
}
+
+ // Create a bind-mount over the file
+ r = pakfire_mount(pakfire, path, devnode->path, "bind", MS_BIND, NULL);
+ if (r)
+ return r;
}
// Create symlinks
return 0;
}
+int pakfire_touch(const char* path, mode_t mode) {
+ FILE* f = fopen(path, "w");
+ if (!f)
+ return 1;
+
+ return fclose(f);
+}
+
int pakfire_mkparentdir(const char* path, mode_t mode) {
int r;