osEnv.c 2.8 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"

S
config  
Shengliang Guan 已提交
19 20
extern void taosWinSocketInit();

S
os env  
Shengliang Guan 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
char       configDir[PATH_MAX] = {0};
char       tsDataDir[PATH_MAX];
char       tsLogDir[PATH_MAX];
char       tsTempDir[PATH_MAX];
SDiskSpace tsDataSpace;
SDiskSpace tsLogSpace;
SDiskSpace tsTempSpace;
char       tsOsName[16];
char       tsTimezone[TD_TIMEZONE_LEN];
char       tsLocale[TD_LOCALE_LEN];
char       tsCharset[TD_CHARSET_LEN];
int8_t     tsDaylight;
bool       tsEnableCoreFile;
int64_t    tsPageSize;
int64_t    tsOpenMax;
int64_t    tsStreamMax;
int32_t    tsNumOfCores;
int32_t    tsTotalMemoryMB;
S
Shengliang Guan 已提交
39

S
Shengliang Guan 已提交
40
void osInit() {
S
os env  
Shengliang Guan 已提交
41
  srand(taosSafeRand());
S
os env  
Shengliang Guan 已提交
42 43 44
  taosGetSystemLocale(tsLocale, tsCharset);
  taosGetSystemTimezone(tsTimezone);
  taosSetSystemTimezone(tsTimezone, tsTimezone, &tsDaylight);
S
Shengliang Guan 已提交
45
  taosGetSystemInfo();
S
config  
Shengliang Guan 已提交
46 47

#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
S
Shengliang Guan 已提交
48 49 50 51 52 53 54
  taosWinSocketInit();

  const char *tmpDir = getenv("tmp");
  if (tmpDir == NULL) {
    tmpDir = getenv("temp");
  }
  if (tmpDir != NULL) {
S
os env  
Shengliang Guan 已提交
55
    strcpy(tsTempDir, tmpDir);
S
Shengliang Guan 已提交
56
  }
S
os env  
Shengliang Guan 已提交
57

S
Shengliang Guan 已提交
58 59 60
  if (configDir[0] == 0) {
    strcpy(configDir, "C:\\TDengine\\cfg");
  }
S
os env  
Shengliang Guan 已提交
61 62 63 64
  strcpy(tsDataDir, "C:\\TDengine\\data");
  strcpy(tsLogDir, "C:\\TDengine\\log");
  strcpy(tsTempDir, "C:\\Windows\\Temp");
  strcpy(tsOsName, "Windows");
S
Shengliang Guan 已提交
65 66

#elif defined(_TD_DARWIN_64)
S
Shengliang Guan 已提交
67 68 69
  if (configDir[0] == 0) {
    strcpy(configDir, "/tmp/taosd");
  }
S
os env  
Shengliang Guan 已提交
70 71 72 73
  strcpy(tsDataDir, "/usr/local/var/lib/taos");
  strcpy(tsLogDir, "/usr/local/var/log/taos");
  strcpy(tsTempDir, "/usr/local/etc/taos");
  strcpy(tsOsName, "Darwin");
S
Shengliang Guan 已提交
74

S
config  
Shengliang Guan 已提交
75
#else
S
Shengliang Guan 已提交
76 77 78
  if (configDir[0] == 0) {
    strcpy(configDir, "/etc/taos");
  }
S
os env  
Shengliang Guan 已提交
79 80 81 82
  strcpy(tsDataDir, "/var/lib/taos");
  strcpy(tsLogDir, "/var/log/taos");
  strcpy(tsTempDir, "/tmp");
  strcpy(tsOsName, "Linux");
S
Shengliang Guan 已提交
83

S
config  
Shengliang Guan 已提交
84
#endif
S
os env  
Shengliang Guan 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
}

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);
  }
}

bool osLogSpaceAvailable() { return tsLogSpace.reserved <= tsLogSpace.size.avail; }

void osSetTimezone(const char *timezone) { taosSetSystemTimezone(tsTimezone, tsTimezone, &tsDaylight); }