提交 0d0841d1 编写于 作者: S Shengliang Guan

config

上级 77788309
......@@ -23,7 +23,7 @@ extern "C" {
void taosRemoveDir(const char *dirname);
int32_t taosDirExist(char *dirname);
int32_t taosMkDir(const char *dirname);
void taosRemoveOldFiles(char *dirname, int32_t keepDays);
void taosRemoveOldFiles(const char *dirname, int32_t keepDays);
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen);
int32_t taosRealPath(char *dirname, int32_t maxlen);
......
......@@ -22,36 +22,31 @@
extern "C" {
#endif
typedef struct SOsEnv {
char dataDir[PATH_MAX];
char logDir[PATH_MAX];
char tempDir[PATH_MAX];
SDiskSpace dataSpace;
SDiskSpace logSpace;
SDiskSpace tempSpace;
char osName[16];
char timezone[TD_TIMEZONE_LEN];
char locale[TD_LOCALE_LEN];
char charset[TD_CHARSET_LEN];
int8_t daylight;
} SOsEnv;
typedef struct SOsEnv SOsEnv;
extern char configDir[];
void osInit();
SOsEnv *osEnv();
void osUpdate();
bool osLogSpaceAvailable();
char *osLogDir();
char *osTempDir();
char *osDataDir();
char *osName();
char *osTimezone();
int8_t osDaylight();
char *osLocale();
char *osCharset();
void osSetTimezone(const char*timezone);
void osInit();
void osUpdate();
bool osLogSpaceAvailable();
int8_t osDaylight();
const char *osLogDir();
const char *osTempDir();
const char *osDataDir();
const char *osName();
const char *osTimezone();
const char *osLocale();
const char *osCharset();
void osSetLogDir(const char *logDir);
void osSetTempDir(const char *tempDir);
void osSetDataDir(const char *dataDir);
void osSetLogReservedSpace(float sizeInGB);
void osSetTempReservedSpace(float sizeInGB);
void osSetDataReservedSpace(float sizeInGB);
void osSetTimezone(const char *timezone);
#ifdef __cplusplus
}
......
......@@ -67,7 +67,7 @@ static int32_t tscAddLogCfg(SConfig *pCfg) {
}
static int32_t tscSetLogCfg(SConfig *pCfg) {
tstrncpy(osLogDir(), cfgGetItem(pCfg, "logDir")->str, PATH_MAX);
osSetLogDir(cfgGetItem(pCfg, "logDir")->str);
tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval;
tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32;
tsLogKeepDays = cfgGetItem(pCfg, "logKeepDays")->i32;
......
......@@ -46,11 +46,10 @@ static int32_t dmnAddDirCfg(SConfig *pCfg) {
}
static int32_t dmnCheckDirCfg(SConfig *pCfg) {
SOsEnv *pEnv = osEnv();
tstrncpy(pEnv->dataDir, cfgGetItem(pCfg, "dataDir")->str, PATH_MAX);
tstrncpy(pEnv->tempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX);
pEnv->dataSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval;
pEnv->tempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval;
osSetDataDir(cfgGetItem(pCfg, "dataDir")->str);
osSetTempDir(cfgGetItem(pCfg, "tempDir")->str);
osSetTempReservedSpace(cfgGetItem(pCfg, "minimalDataDirGB")->fval);
osSetDataReservedSpace(cfgGetItem(pCfg, "minimalTempDirGB")->fval);
return 0;
}
......
......@@ -41,9 +41,8 @@ int32_t dmnAddLogCfg(SConfig *pCfg) {
}
int32_t dmnSetLogCfg(SConfig *pCfg) {
SOsEnv *pEnv = osEnv();
tstrncpy(pEnv->logDir, cfgGetItem(pCfg, "logDir")->str, PATH_MAX);
pEnv->logSpace.reserved = cfgGetItem(pCfg, "minimalLogDirGB")->fval;
osSetLogDir(cfgGetItem(pCfg, "logDir")->str);
osSetLogReservedSpace(cfgGetItem(pCfg, "minimalLogDirGB")->fval);
tsAsyncLog = cfgGetItem(pCfg, "asyncLog")->bval;
tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32;
tsLogKeepDays = cfgGetItem(pCfg, "logKeepDays")->i32;
......
......@@ -33,7 +33,7 @@ void Testbase::InitLog(const char* path) {
taosRemoveDir(path);
taosMkDir(path);
tstrncpy(osLogDir(), path, PATH_MAX);
osSetLogDir(path);
if (taosInitLog("taosdlog", 1) != 0) {
printf("failed to init log file\n");
}
......
......@@ -30,7 +30,7 @@ static void EnvInit() {
taosRemoveDir(path.c_str());
taosMkDir(path.c_str());
// init log file
tstrncpy(osLogDir(), path.c_str(), PATH_MAX);
osSetLogDir( path.c_str());
if (taosInitLog("tindex.idx", 1) != 0) {
printf("failed to init log");
}
......
......@@ -155,7 +155,7 @@ class TransObj {
taosRemoveDir(path.c_str());
taosMkDir(path.c_str());
tstrncpy(osLogDir(), path.c_str(), PATH_MAX);
osSetLogDir(path.c_str());
if (taosInitLog("taosdlog", 1) != 0) {
printf("failed to init log file\n");
}
......
......@@ -71,7 +71,7 @@ int32_t taosMkDir(const char *dirname) {
return code;
}
void taosRemoveOldFiles(char *dirname, int32_t keepDays) {
void taosRemoveOldFiles(const char *dirname, int32_t keepDays) {
DIR *dir = opendir(dirname);
if (dir == NULL) return;
......
......@@ -16,8 +16,24 @@
#define _DEFAULT_SOURCE
#include "osEnv.h"
SOsEnv env = {0};
char configDir[PATH_MAX] = {0};
extern void taosWinSocketInit();
char configDir[PATH_MAX] = {0};
typedef struct SOsEnv {
char dataDir[PATH_MAX];
char logDir[PATH_MAX];
char tempDir[PATH_MAX];
SDiskSpace dataSpace;
SDiskSpace logSpace;
SDiskSpace tempSpace;
char osName[16];
char timezone[TD_TIMEZONE_LEN];
char locale[TD_LOCALE_LEN];
char charset[TD_CHARSET_LEN];
int8_t daylight;
} SOsEnv;
static SOsEnv env = {0};
SOsEnv *osEnv() { return &env; }
......@@ -39,26 +55,29 @@ void osUpdate() {
}
}
bool osLogSpaceAvailable() { return env.logSpace.reserved < env.logSpace.size.avail; }
char *osLogDir() { return env.logDir; }
char *osTempDir() { return env.tempDir; }
char *osDataDir() { return env.dataDir; }
char *osName() { return env.osName; }
char *osTimezone() { return env.timezone; }
char *osLocale() { return env.locale; }
char *osCharset() { return env.charset; }
bool osLogSpaceAvailable() { return env.logSpace.reserved <= env.logSpace.size.avail; }
int8_t osDaylight() { return env.daylight; }
const char *osLogDir() { return env.logDir; }
const char *osTempDir() { return env.tempDir; }
const char *osDataDir() { return env.dataDir; }
const char *osName() { return env.osName; }
const char *osTimezone() { return env.timezone; }
const char *osLocale() { return env.locale; }
const char *osCharset() { return env.charset; }
void osSetLogDir(const char *logDir) { tstrncpy(env.logDir, logDir, PATH_MAX); }
void osSetTempDir(const char *tempDir) { tstrncpy(env.tempDir, tempDir, PATH_MAX); }
void osSetDataDir(const char *dataDir) { tstrncpy(env.dataDir, dataDir, PATH_MAX); }
void osSetLogReservedSpace(float sizeInGB) { env.logSpace.reserved = sizeInGB; }
void osSetTempReservedSpace(float sizeInGB) { env.tempSpace.reserved = sizeInGB; }
void osSetDataReservedSpace(float sizeInGB) { env.dataSpace.reserved = sizeInGB; }
void osSetTimezone(const char *timezone) { taosSetSystemTimezone(timezone, env.timezone, &env.daylight); }
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
extern taosWinSocketInit();
void osInit() {
srand(taosSafeRand());
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
taosWinSocketInit();
const char *tmpDir = getenv("tmp");
......@@ -74,27 +93,20 @@ void osInit() {
strcpy(env.logDir, "C:\\TDengine\\log");
strcpy(env.tempDir, "C:\\Windows\\Temp");
strcpy(env.osName, "Windows");
}
#elif defined(_TD_DARWIN_64)
void osInit() {
srand(taosSafeRand());
strcpy(configDir, "/tmp/taosd");
strcpy(env.dataDir, "/usr/local/var/lib/taos");
strcpy(env.logDir, "/usr/local/var/log/taos");
strcpy(env.tempDir, "/usr/local/etc/taos");
strcpy(env.osName, "Darwin");
}
#else
void osInit() {
srand(taosSafeRand());
#else
strcpy(configDir, "/etc/taos");
strcpy(env.dataDir, "/var/lib/taos");
strcpy(env.logDir, "/var/log/taos");
strcpy(env.tempDir, "/tmp");
strcpy(env.osName, "Linux");
}
#endif
\ No newline at end of file
#endif
}
\ No newline at end of file
......@@ -184,7 +184,6 @@ static void parse_args(
for (int i = 1; i < argc; i++) {
if ((strncmp(argv[i], "-p", 2) == 0)
|| (strncmp(argv[i], "--password", 10) == 0)) {
strcpy(osName(), "Linux");
printf(LINUXCLIENT_VERSION, osName(), taos_get_client_info());
if ((strlen(argv[i]) == 2)
|| (strncmp(argv[i], "--password", 10) == 0)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册