static int __init make_umid_setup(void) { /* one function with the ordering we need ... */ make_uml_dir(); make_umid(printf); return create_pid_file(); }
static int __init make_umid(void) { int fd, err; char tmp[256]; if (umid_setup) return 0; make_uml_dir(); if (*umid == '\0') { strlcpy(tmp, uml_dir, sizeof(tmp)); strlcat(tmp, "XXXXXX", sizeof(tmp)); fd = mkstemp(tmp); if (fd < 0) { printk(UM_KERN_ERR "make_umid - mkstemp(%s) failed: " "%s\n", tmp, strerror(errno)); err = -errno; goto err; } close(fd); set_umid(&tmp[strlen(uml_dir)]); /* * There's a nice tiny little race between this unlink and * the mkdir below. It'd be nice if there were a mkstemp * for directories. */ if (unlink(tmp)) { err = -errno; goto err; } } snprintf(tmp, sizeof(tmp), "%s%s", uml_dir, umid); err = mkdir(tmp, 0777); if (err < 0) { err = -errno; if (err != -EEXIST) goto err; if (umdir_take_if_dead(tmp) < 0) goto err; err = mkdir(tmp, 0777); } if (err) { err = -errno; printk(UM_KERN_ERR "Failed to create '%s' - err = %d\n", umid, errno); goto err; } umid_setup = 1; create_pid_file(); err = 0; err: return err; }
int __init make_umid(void) { int fd, err; char tmp[256]; if(umid_setup) return 0; make_uml_dir(); if(*umid == '\0'){ strlcpy(tmp, uml_dir, sizeof(tmp)); strlcat(tmp, "XXXXXX", sizeof(tmp)); fd = mkstemp(tmp); if(fd < 0){ printk("make_umid - mkstemp(%s) failed: %s\n", tmp, strerror(errno)); err = -errno; goto err; } close(fd); set_umid(&tmp[strlen(uml_dir)]); /* There's a nice tiny little race between this unlink and * the mkdir below. It'd be nice if there were a mkstemp * for directories. */ if(unlink(tmp)){ err = -errno; goto err; } } snprintf(tmp, sizeof(tmp), "%s%s", uml_dir, umid); err = mkdir(tmp, 0777); if(err < 0){ err = -errno; if(err != -EEXIST) goto err; /* 1 -> this umid is already in use * < 0 -> we couldn't remove the umid directory * In either case, we can't use this umid, so return -EEXIST. */ if(not_dead_yet(tmp) != 0) goto err; err = mkdir(tmp, 0777); } if(err){ err = -errno; printk("Failed to create '%s' - err = %d\n", umid, -errno); goto err; } umid_setup = 1; create_pid_file(); err = 0; err: return err; }