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

config

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