osEnv.c 3.5 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#define _DEFAULT_SOURCE
S
Shengliang Guan 已提交
17 18
#include "osEnv.h"

wafwerar's avatar
wafwerar 已提交
19 20 21 22 23 24 25 26 27
char            configDir[PATH_MAX] = {0};
char            tsDataDir[PATH_MAX] = {0};
char            tsLogDir[PATH_MAX] = {0};
char            tsTempDir[PATH_MAX] = {0};
SDiskSpace      tsDataSpace = {0};
SDiskSpace      tsLogSpace = {0};
SDiskSpace      tsTempSpace = {0};
char            tsOsName[16] = {0};
char            tsTimezoneStr[TD_TIMEZONE_LEN] = {0};
wafwerar's avatar
wafwerar 已提交
28
enum TdTimezone tsTimezone = TdZeroZone;
wafwerar's avatar
wafwerar 已提交
29 30 31 32 33 34 35 36 37
char            tsLocale[TD_LOCALE_LEN] = {0};
char            tsCharset[TD_CHARSET_LEN] = {0};
int8_t          tsDaylight = 0;
bool            tsEnableCoreFile = 0;
int64_t         tsPageSizeKB = 0;
int64_t         tsOpenMax = 0;
int64_t         tsStreamMax = 0;
float           tsNumOfCores = 0;
int64_t         tsTotalMemoryKB = 0;
H
Hongze Cheng 已提交
38
char           *tsProcPath = NULL;
wafwerar's avatar
wafwerar 已提交
39

H
Haojun Liao 已提交
40 41 42 43 44 45
char            tsSIMDEnable = 0;
char            tsSSE42Enable = 0;
char            tsAVXEnable = 0;
char            tsAVX2Enable = 0;
char            tsFMAEnable = 0;

wafwerar's avatar
wafwerar 已提交
46
void osDefaultInit() {
wafwerar's avatar
wafwerar 已提交
47
  taosSeedRand(taosSafeRand());
S
os env  
Shengliang Guan 已提交
48
  taosGetSystemLocale(tsLocale, tsCharset);
wafwerar's avatar
wafwerar 已提交
49 50
  taosGetSystemTimezone(tsTimezoneStr, &tsTimezone);
  taosSetSystemTimezone(tsTimezoneStr, tsTimezoneStr, &tsDaylight, &tsTimezone);
S
Shengliang Guan 已提交
51
  taosGetSystemInfo();
S
config  
Shengliang Guan 已提交
52

S
Shengliang Guan 已提交
53 54 55 56 57
  // deadlock in query
  if (tsNumOfCores < 2) {
    tsNumOfCores = 2;
  }

wafwerar's avatar
wafwerar 已提交
58
#ifdef WINDOWS
S
Shengliang Guan 已提交
59 60 61 62 63 64 65
  taosWinSocketInit();

  const char *tmpDir = getenv("tmp");
  if (tmpDir == NULL) {
    tmpDir = getenv("temp");
  }
  if (tmpDir != NULL) {
S
os env  
Shengliang Guan 已提交
66
    strcpy(tsTempDir, tmpDir);
S
Shengliang Guan 已提交
67
  }
S
os env  
Shengliang Guan 已提交
68
  strcpy(tsOsName, "Windows");
S
Shengliang Guan 已提交
69
#elif defined(_TD_DARWIN_64)
S
os env  
Shengliang Guan 已提交
70
  strcpy(tsOsName, "Darwin");
S
config  
Shengliang Guan 已提交
71
#else
S
os env  
Shengliang Guan 已提交
72
  strcpy(tsOsName, "Linux");
S
config  
Shengliang Guan 已提交
73
#endif
wafwerar's avatar
wafwerar 已提交
74 75 76 77 78 79
  if (configDir[0] == 0) {
    strcpy(configDir, TD_CFG_DIR_PATH);
  }
  strcpy(tsDataDir, TD_DATA_DIR_PATH);
  strcpy(tsLogDir, TD_LOG_DIR_PATH);
  strcpy(tsTempDir, TD_TMP_DIR_PATH);
S
os env  
Shengliang Guan 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93
}

void osUpdate() {
  if (tsLogDir[0] != 0) {
    taosGetDiskSize(tsLogDir, &tsLogSpace.size);
  }
  if (tsDataDir[0] != 0) {
    taosGetDiskSize(tsDataDir, &tsDataSpace.size);
  }
  if (tsTempDir[0] != 0) {
    taosGetDiskSize(tsTempDir, &tsTempSpace.size);
  }
}

S
shm  
Shengliang Guan 已提交
94 95
void osCleanup() {}

96
bool osLogSpaceAvailable() { return tsLogSpace.size.avail > 0; }
S
os env  
Shengliang Guan 已提交
97

98
bool osDataSpaceAvailable() { return tsDataSpace.size.avail > 0; }
wafwerar's avatar
wafwerar 已提交
99

100 101 102 103 104 105 106
bool osTempSpaceAvailable() { return tsTempSpace.size.avail > 0; }

bool osLogSpaceSufficient() { return tsLogSpace.size.avail > tsLogSpace.reserved; }

bool osDataSpaceSufficient() { return tsDataSpace.size.avail > tsDataSpace.reserved; }

bool osTempSpaceSufficient() { return tsTempSpace.size.avail > tsTempSpace.reserved; }
wafwerar's avatar
wafwerar 已提交
107

H
Haojun Liao 已提交
108
void osSetTimezone(const char *tz) { taosSetSystemTimezone(tz, tsTimezoneStr, &tsDaylight, &tsTimezone); }
wafwerar's avatar
wafwerar 已提交
109 110 111 112 113

void osSetSystemLocale(const char *inLocale, const char *inCharSet) {
  memcpy(tsLocale, inLocale, strlen(inLocale) + 1);
  memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1);
}
114 115

void osSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; }