osEnv.c 2.3 KB
Newer Older
S
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * 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
#include "os.h"
S
Shengliang Guan 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31
#include "osEnv.h"
#include "osSysinfo.h"

SDiskSpace tsLogSpace;
SDiskSpace tsTempSpace;
SDiskSpace tsDataSpace;

void taosUpdateLogSpace() { taosGetDiskSize(tsLogDir, &tsLogSpace.size); }

void taosUpdateTempSpace() { taosGetDiskSize(tsTempDir, &tsTempSpace.size); }

void taosUpdateDataSpace() { taosGetDiskSize(tsDataDir, &tsDataSpace.size); }

S
version  
Shengliang Guan 已提交
32
bool taosLogSpaceAvailable() { return tsLogSpace.reserved < tsLogSpace.size.avail; }
S
Shengliang Guan 已提交
33

S
version  
Shengliang Guan 已提交
34
bool taosTempSpaceAvailable() { return tsTempSpace.reserved < tsTempSpace.size.avail; }
S
Shengliang Guan 已提交
35

S
version  
Shengliang Guan 已提交
36
bool taosDataSpaceAvailable() { return tsDataSpace.reserved < tsDataSpace.size.avail; }
S
Shengliang Guan 已提交
37 38 39 40 41 42

void taosUpdateAllSpace() {
  taosUpdateLogSpace();
  taosUpdateTempSpace();
  taosUpdateDataSpace();
}
S
Shengliang Guan 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)

char tsOsName[10] = "Windows";
char configDir[PATH_MAX] = "C:/TDengine/cfg";
char tsDataDir[PATH_MAX] = "C:/TDengine/data";
char tsLogDir[PATH_MAX] = "C:/TDengine/log";
char tsTempDir[PATH_MAX] = "C:\\Windows\\Temp";

extern taosWinSocketInit();

void osInit() {
  taosWinSocketInit();

  const char *tmpDir = getenv("tmp");
  if (tmpDir == NULL) {
    tmpDir = getenv("temp");
  }

  if (tmpDir != NULL) {
    strcpy(tsTempDir, tmpDir);
  }
}

#elif defined(_TD_DARWIN_64)

char tsOsName[10] = "Darwin";
char configDir[PATH_MAX] = "/usr/local/etc/taos";
char tsDataDir[PATH_MAX] = "/usr/local/var/lib/taos";
char tsLogDir[PATH_MAX] = "/usr/local/var/log/taos";
char tsTempDir[PATH_MAX] = "/tmp/taosd";

void osInit() {}

#else

char tsOsName[10] = "Linux";
char configDir[PATH_MAX] = "/etc/taos";
char tsDataDir[PATH_MAX] = "/var/lib/taos";
char tsLogDir[PATH_MAX] = "/var/log/taos";
char tsTempDir[PATH_MAX] = "/tmp/";

void osInit() {}

#endif