- Store result from mkstemp so we don't leak file descriptor
- No need to chmod, as we set correct umask before createing file
- Use fdopen to open file from file descriptor, not from path
{
char path[PATH_MAX];
FILE *log;
+ int fd;
mode_t um;
strcpy(path, "/tmp/efreetd_XXXXXX");
- um = umask(0077);
- if (mkstemp(path) < 0)
- {
- perror("mkstemp");
- umask(um);
- return 1;
- }
+ um = umask(S_IRWXG|S_IRWXO);
+ fd = mkstemp(path);
umask(um);
- if (chmod(path, 0700) < 0)
+ if (fd < 0)
{
- perror("chmod");
+ perror("mkstemp");
return 1;
}
- log = fopen(path, "wb");
+ log = fdopen(fd, "wb");
if (!log) return 1;
if (!eina_init()) return 1;