Log manager no longer creates files when checking if they exist.

This commit is contained in:
Markus Makela
2015-02-15 20:10:09 +02:00
parent 691eefe0de
commit 678fbb4646

View File

@ -2335,7 +2335,6 @@ static bool check_file_and_path(
bool* writable, bool* writable,
bool do_log) bool do_log)
{ {
int fd;
bool exists; bool exists;
if (filename == NULL) if (filename == NULL)
@ -2349,111 +2348,54 @@ static bool check_file_and_path(
} }
else else
{ {
fd = open(filename, O_CREAT|O_EXCL, S_IRWXU); if(access(filename,F_OK) == 0)
{
if (fd == -1) exists = true;
{
/** File exists, check permission to read/write */
if (errno == EEXIST)
{
/** Open file */
fd = open(filename, O_CREAT|O_RDWR, S_IRWXU|S_IRWXG);
if (fd == -1) if(access(filename,W_OK) == 0)
{ {
if (do_log && file_is_symlink(filename)) if(writable)
{ {
fprintf(stderr, *writable = true;
"*\n* Error : Can't access " }
"file pointed to by %s due " }
"to %s.\n", else
filename, {
strerror(errno));
}
else if (do_log)
{
fprintf(stderr,
"*\n* Error : Can't access %s due "
"to %s.\n",
filename,
strerror(errno));
}
if (writable)
{
*writable = false;
}
}
else
{
if (writable)
{
if (access(filename,W_OK) == 0)
{
*writable = true;
}
else
{
if (do_log &&
file_is_symlink(filename))
{
fprintf(stderr,
"*\n* Error : Can't write to "
"file pointed to by %s due to "
"%s.\n",
filename,
strerror(errno));
}
else if (do_log)
{
fprintf(stderr,
"*\n* Error : Can't write to "
"%s due to %s.\n",
filename,
strerror(errno));
}
*writable = false;
}
}
close(fd);
}
exists = true;
}
else
{
if (do_log && file_is_symlink(filename))
{
fprintf(stderr,
"*\n* Error : Can't access the file "
"pointed to by %s due to %s.\n",
filename,
strerror(errno));
}
else if (do_log)
{
fprintf(stderr,
"*\n* Error : Can't access %s due to %s.\n",
filename,
strerror(errno));
}
exists = false;
if (writable) if (do_log && file_is_symlink(filename))
{ {
*writable = false; fprintf(stderr,
} "*\n* Error : Can't access "
} "file pointed to by %s due "
} "to %s.\n",
else filename,
{ strerror(errno));
close(fd); }
unlink(filename); else if (do_log)
exists = false; {
fprintf(stderr,
"*\n* Error : Can't access %s due "
"to %s.\n",
filename,
strerror(errno));
}
if (writable) if(writable)
{ {
*writable = true; *writable = false;
} }
} }
}
else
{
exists = false;
if(writable)
{
*writable = true;
}
}
} }
return exists; return exists;
} }