Added O_TMPFILE support for uwac tempfile generation.

This commit is contained in:
Armin Novak
2019-01-25 15:46:55 +01:00
parent 34adfd5714
commit 52ef8079ea

View File

@@ -212,11 +212,11 @@ static int create_tmpfile_cloexec(char* tmpname)
int uwac_create_anonymous_file(off_t size)
{
static const char template[] = "/weston-shared-XXXXXX";
const char* path;
size_t length;
char* name;
const char* path;
int fd;
int ret;
size_t length;
path = getenv("XDG_RUNTIME_DIR");
if (!path)
@@ -225,15 +225,20 @@ int uwac_create_anonymous_file(off_t size)
return -1;
}
length = strlen(path) + sizeof(template);
name = malloc(length);
fd = open(path, O_TMPFILE | O_RDWR | O_EXCL, 0600);
if (!name)
return -1;
if (fd < 0)
{
length = strlen(path) + sizeof(template);
name = malloc(length);
snprintf(name, length, "%s%s", path, template);
fd = create_tmpfile_cloexec(name);
free(name);
if (!name)
return -1;
snprintf(name, length, "%s%s", path, template);
fd = create_tmpfile_cloexec(name);
free(name);
}
if (fd < 0)
return -1;