X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=devices%2Fudev-helper.c;h=a55d3780906e15d5274fec996b2bf6ce8906bd5d;hb=aab818c10b1fa68b968cabc852680f8ec0fe1360;hp=661fb08b4ef9c2021984109b78d2d3af68fe9943;hpb=7d7c328016aca3e14aee6268a2e7881d3440e226;p=petitboot diff --git a/devices/udev-helper.c b/devices/udev-helper.c index 661fb08..a55d378 100644 --- a/devices/udev-helper.c +++ b/devices/udev-helper.c @@ -19,6 +19,7 @@ #include #include "parser.h" +#include "paths.h" #include "petitboot-paths.h" /* Define below to operate without the frontend */ @@ -183,69 +184,6 @@ int connect_to_socket() #endif } -struct device_map { - char *dev, *mnt; -}; - -#define DEVICE_MAP_SIZE 32 -static struct device_map device_map[DEVICE_MAP_SIZE]; - -const char *mountpoint_for_device(const char *dev_path) -{ - int i; - const char *basename; - - /* shorten '/dev/foo' to 'foo' */ - basename = strrchr(dev_path, '/'); - if (basename) - basename++; - else - basename = dev_path; - - /* check existing entries in the map */ - for (i = 0; (i < DEVICE_MAP_SIZE) && device_map[i].dev; i++) - if (!strcmp(device_map[i].dev, basename)) - return device_map[i].mnt; - - if (i == DEVICE_MAP_SIZE) - return NULL; - - device_map[i].dev = strdup(dev_path); - asprintf(&device_map[i].mnt, "%s/%s", TMP_DIR, basename); - return device_map[i].mnt; -} - -/** - * Resolve a path given in a config file, to a path in the local filesystem. - * Paths may be of the form: - * device:path (eg /dev/sda:/boot/vmlinux) - * - * or just a path: - * /boot/vmlinux - * - in this case, the default mountpoint is used. - * - * Returns a newly-allocated string containing a full path to the file in path - */ -char *resolve_path(const char *path, const char *default_mountpoint) -{ - char *ret; - const char *devpath, *sep; - - sep = strchr(path, ':'); - if (!sep) { - devpath = default_mountpoint; - asprintf(&ret, "%s/%s", devpath, path); - } else { - /* copy just the device name into tmp */ - char *dev = strndup(path, sep - path); - devpath = mountpoint_for_device(dev); - asprintf(&ret, "%s/%s", devpath, sep + 1); - free(dev); - } - - return ret; -} - int mount_device(const char *dev_path) { const char *dir; @@ -551,7 +489,7 @@ int main(int argc, char **argv) action = getenv("ACTION"); - logf = fopen("/var/tmp/petitboot-udev-helpers.log", "a"); + logf = fopen("/var/log/petitboot-udev-helpers.log", "a"); if (!logf) logf = stdout; pb_log("%d started\n", getpid()); @@ -562,6 +500,8 @@ int main(int argc, char **argv) return EXIT_FAILURE; } + set_mount_base(TMP_DIR); + if (connect_to_socket()) return EXIT_FAILURE;