+ session->metadata_fd = -1;
+ session->uid = euid;
+ session->gid = egid;
+ strncpy(session->root_shm_path, root_shm_path,
+ sizeof(session->root_shm_path));
+ session->root_shm_path[sizeof(session->root_shm_path) - 1] = '\0';
+ if (shm_path[0]) {
+ strncpy(session->shm_path, shm_path,
+ sizeof(session->shm_path));
+ session->shm_path[sizeof(session->shm_path) - 1] = '\0';
+ strncpy(session->metadata_path, shm_path,
+ sizeof(session->metadata_path));
+ session->metadata_path[sizeof(session->metadata_path) - 1] = '\0';
+ strncat(session->metadata_path, "/metadata",
+ sizeof(session->metadata_path)
+ - strlen(session->metadata_path) - 1);
+ }
+ if (session->shm_path[0]) {
+ ret = run_as_mkdir_recursive(session->shm_path,
+ S_IRWXU | S_IRWXG,
+ euid, egid);
+ if (ret) {
+ errno = -ret;
+ PERROR("run_as_mkdir_recursive");
+ goto error;
+ }
+ }
+ if (session->metadata_path[0]) {
+ /* Create metadata file */
+ ret = run_as_open(session->metadata_path,
+ O_WRONLY | O_CREAT | O_EXCL,
+ S_IRUSR | S_IWUSR, euid, egid);
+ if (ret < 0) {
+ errno = -ret;
+ PERROR("Opening metadata file");
+ goto error;
+ }
+ session->metadata_fd = ret;
+ }