2022-05-09 Mark Wielaard <mark@klomp.org>
+ * debuginfod-client.c (debuginfod_config_cache): Always open with
+ O_CREATE first, then use fstat, only write the cache_config_default_s
+ value if st_size == 0, otherwise read value from file.
+
+2022-05-09 Mark Wielaard <mark@klomp.org>
+
* debuginfod.cxx (conninfo): Always provide servname to getnameinfo.
2022-05-09 Mark Wielaard <mark@klomp.org>
long cache_config_default_s,
struct stat *st)
{
- int fd;
- /* if the config file doesn't exist, create one with DEFFILEMODE*/
- if(stat(config_path, st) == -1)
+ int fd = open(config_path, O_CREAT | O_RDWR, DEFFILEMODE);
+ if (fd < 0)
+ return -errno;
+
+ if (fstat (fd, st) < 0)
{
- fd = open(config_path, O_CREAT | O_RDWR, DEFFILEMODE);
- if (fd < 0)
- return -errno;
+ int ret = -errno;
+ close (fd);
+ return ret;
+ }
+ if (st->st_size == 0)
+ {
if (dprintf(fd, "%ld", cache_config_default_s) < 0)
{
int ret = -errno;
}
close (fd);
+ return cache_config_default_s;
}
long cache_config;
- FILE *config_file = fopen(config_path, "r");
+ FILE *config_file = fdopen(fd, "r");
if (config_file)
{
if (fscanf(config_file, "%ld", &cache_config) != 1)
else
cache_config = cache_config_default_s;
+ close (fd);
return cache_config;
}