static int create_conf(const char *spec) { char *devname, *unitname, *confpath, *p; int ret; devname = evaluate_spec(spec); if (!devname) { error("Cannot convert '%s' to device name: %s", spec, strerror(errno)); return -1; } unitname = path_escape(devname); if (!unitname) { error("Cannot convert '%s' to systemd unit name: %s", devname, strerror(errno)); free(devname); return -1; } free(devname); confpath = malloc(unitdirlen + 1 + strlen(unitname) + sizeof(".device.d/timeout.conf")); if (!confpath) { error("Cannot allocate path for '%s': %s", unitname, strerror(errno)); free(unitname); return -1; } p = stpcpy(confpath, unitdir); *p++ = '/'; p = stpcpy(p, unitname); p = stpcpy(p, ".device.d"); free(unitname); if (mkdir(confpath, S_IRWXU | S_IRWXG | S_IRWXO) && errno != EEXIST) { error("Cannot create directory '%s': %s", confpath, strerror(errno)); free(confpath); return -1; } p = stpcpy(p, "/timeout.conf"); ret = write_conf(confpath); free(confpath); return ret; }
static JSBool js_httpEscape(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { const char *str; char *r; if (!JS_ConvertArguments(cx, argc, argv, "s", &str)) return JS_FALSE; size_t l = strlen(str); r = malloc((l * 3) + 1); path_escape(r, l * 3, str); *rval = STRING_TO_JSVAL(JS_NewString(cx, r, strlen(r))); return JS_TRUE; }
static char* ctl_makepath(const char* name, const char* ext) { char* res; char *file; file = strrchr(name, '/'); if (!file) { BWPRINTF("invalid name %s\n", name); return NULL; } if (asprintf(&res, BLKTAP_CTRL_DIR "/log_%s.%s", file, ext) < 0) { BWPRINTF("could not allocate path"); return NULL; } path_escape(res + strlen(BLKTAP_CTRL_DIR) + 5, strlen(file)); return res; }
static int shmem_open(struct tdlog_state* s, const char* name) { int i, l, fd; /* device name -> path */ if (asprintf(&s->shmpath, "/log_%s.wlog", name) < 0) { BWPRINTF("could not allocate shm path"); return -1; } path_escape(s->shmpath + 5, strlen(name)); if ((fd = shm_open(s->shmpath, O_CREAT|O_RDWR, 0750)) < 0) { BWPRINTF("could not open shared memory file %s: %s", s->shmpath, strerror(errno)); goto err; } if (ftruncate(fd, SHMSIZE) < 0) { BWPRINTF("error truncating shmem to size %u", SHMSIZE); close(fd); goto err; } s->shm = mmap(NULL, SHMSIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); close(fd); if (s->shm == MAP_FAILED) { BWPRINTF("could not mmap write log shm: %s", strerror(errno)); goto err; } return 0; err: s->shm = NULL; free(s->shmpath); s->shmpath = NULL; return -1; }