int init_config_file(void) { int fd, ret; check_tmp_config(); fd = open(config_path, O_RDONLY); if (fd < 0) { if (errno != ENOENT) { sd_eprintf("failed to read config file, %m"); return -1; } goto create; } ret = xread(fd, &config, sizeof(config)); if (ret == 0) { close(fd); goto create; } if (ret < 0) { sd_eprintf("failed to read config file, %m"); goto out; } if (config.version != SD_FORMAT_VERSION) { sd_eprintf("This sheep version is not compatible with" " the existing data layout, %d", config.version); if (sys->upgrade) { /* upgrade sheep store */ ret = sd_migrate_store(config.version, SD_FORMAT_VERSION); if (ret == 0) { /* reload config file */ ret = xpread(fd, &config, sizeof(config), 0); if (ret != sizeof(config)) { sd_eprintf("failed to reload config" " file, %m"); ret = -1; } else ret = 0; } goto out; } sd_eprintf("use '-u' option to upgrade sheep store"); ret = -1; goto out; } ret = 0; out: close(fd); return ret; create: config.version = SD_FORMAT_VERSION; if (write_config() != SD_RES_SUCCESS) return -1; return 0; }
int init_config_file(void) { int fd, ret = 0; check_tmp_config(); fd = open(config_path, O_RDONLY); if (fd < 0) { if (errno != ENOENT) { sd_err("failed to read config file, %m"); return -1; } goto create; } ret = xread(fd, &config, sizeof(config)); if (ret == 0) { close(fd); goto create; } if (ret < 0) { sd_err("failed to read config file, %m"); goto out; } if (config.version != SD_FORMAT_VERSION) { sd_err("This sheep version is not compatible with" " the existing data layout, %d", config.version); if (sys->upgrade) { /* upgrade sheep store */ ret = sd_migrate_store(config.version, SD_FORMAT_VERSION); if (ret == 0) { /* reload config file */ ret = xpread(fd, &config, sizeof(config), 0); if (ret != sizeof(config)) { sd_err("failed to reload config file," " %m"); ret = -1; } else { ret = 0; goto reload; } } goto out; } sd_err("use '-u' option to upgrade sheep store"); ret = -1; goto out; } reload: if ((config.flags & SD_CLUSTER_FLAG_AUTO_VNODES) != (sys->cinfo.flags & SD_CLUSTER_FLAG_AUTO_VNODES) && !sys->gateway_only && config.ctime > 0) { sd_err("Designation of before a restart and a vnodes option is different."); return -1; } ret = 0; get_cluster_config(&sys->cinfo); if ((config.flags & SD_CLUSTER_FLAG_DISKMODE) != (sys->cinfo.flags & SD_CLUSTER_FLAG_DISKMODE)) { sd_err("This sheep can't run because " "exists data format mismatch"); return -1; } create: config.version = SD_FORMAT_VERSION; if (write_config() != SD_RES_SUCCESS) return -1; out: close(fd); return ret; }