Merge pull request #22458 from taosdata/fix/TD-25719
fix: fix non-root users cannot create log files even if they have write
This commit is contained in:
commit
b00aa1a992
|
@ -83,7 +83,7 @@ void taosRemoveDir(const char *dirname);
|
||||||
bool taosDirExist(const char *dirname);
|
bool taosDirExist(const char *dirname);
|
||||||
int32_t taosMkDir(const char *dirname);
|
int32_t taosMkDir(const char *dirname);
|
||||||
int32_t taosMulMkDir(const char *dirname);
|
int32_t taosMulMkDir(const char *dirname);
|
||||||
int32_t taosMulModeMkDir(const char *dirname, int mode);
|
int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess);
|
||||||
void taosRemoveOldFiles(const 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, char *realPath, int32_t maxlen);
|
int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen);
|
||||||
|
|
|
@ -1434,7 +1434,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
||||||
|
|
||||||
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32, false);
|
taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32, false);
|
||||||
|
|
||||||
if (taosMulModeMkDir(tsLogDir, 0777) != 0) {
|
if (taosMulModeMkDir(tsLogDir, 0777, true) != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
printf("failed to create dir:%s since %s", tsLogDir, terrstr());
|
printf("failed to create dir:%s since %s", tsLogDir, terrstr());
|
||||||
cfgCleanup(pCfg);
|
cfgCleanup(pCfg);
|
||||||
|
|
|
@ -52,7 +52,7 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF
|
||||||
memset(streamPath, 0, len);
|
memset(streamPath, 0, len);
|
||||||
|
|
||||||
sprintf(streamPath, "%s/%s", pMeta->path, "checkpoints");
|
sprintf(streamPath, "%s/%s", pMeta->path, "checkpoints");
|
||||||
code = taosMulModeMkDir(streamPath, 0755);
|
code = taosMulModeMkDir(streamPath, 0755, false);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
terrno = TAOS_SYSTEM_ERROR(code);
|
||||||
goto _err;
|
goto _err;
|
||||||
|
@ -90,7 +90,7 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF
|
||||||
|
|
||||||
memset(streamPath, 0, len);
|
memset(streamPath, 0, len);
|
||||||
sprintf(streamPath, "%s/%s", pMeta->path, "state");
|
sprintf(streamPath, "%s/%s", pMeta->path, "state");
|
||||||
code = taosMulModeMkDir(streamPath, 0755);
|
code = taosMulModeMkDir(streamPath, 0755, false);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
terrno = TAOS_SYSTEM_ERROR(code);
|
||||||
goto _err;
|
goto _err;
|
||||||
|
|
|
@ -169,7 +169,7 @@ SStreamState* streamStateOpen(char* path, void* pTask, bool specPath, int32_t sz
|
||||||
sscanf(cfg, "%d\n%d\n", &szPage, &pages);
|
sscanf(cfg, "%d\n%d\n", &szPage, &pages);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int32_t code = taosMulModeMkDir(statePath, 0755);
|
int32_t code = taosMulModeMkDir(statePath, 0755, false);
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
pCfgFile = taosOpenFile(cfgPath, TD_FILE_WRITE | TD_FILE_CREATE);
|
pCfgFile = taosOpenFile(cfgPath, TD_FILE_WRITE | TD_FILE_CREATE);
|
||||||
sprintf(cfg, "%d\n%d\n", szPage, pages);
|
sprintf(cfg, "%d\n%d\n", szPage, pages);
|
||||||
|
|
|
@ -62,7 +62,7 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb, i
|
||||||
}
|
}
|
||||||
memset(pDb->pgrHash, 0, tsize);
|
memset(pDb->pgrHash, 0, tsize);
|
||||||
|
|
||||||
ret = taosMulModeMkDir(dbname, 0755);
|
ret = taosMulModeMkDir(dbname, 0755, false);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,7 +193,7 @@ int32_t taosMulMkDir(const char *dirname) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosMulModeMkDir(const char *dirname, int mode) {
|
int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
|
||||||
if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return -1;
|
if (dirname == NULL || strlen(dirname) >= TDDIRMAXLEN) return -1;
|
||||||
char temp[TDDIRMAXLEN];
|
char temp[TDDIRMAXLEN];
|
||||||
char *pos = temp;
|
char *pos = temp;
|
||||||
|
@ -206,6 +206,9 @@ int32_t taosMulModeMkDir(const char *dirname, int mode) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (taosDirExist(temp)) {
|
if (taosDirExist(temp)) {
|
||||||
|
if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return chmod(temp, mode);
|
return chmod(temp, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,6 +251,9 @@ int32_t taosMulModeMkDir(const char *dirname, int mode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code < 0 && errno == EEXIST) {
|
if (code < 0 && errno == EEXIST) {
|
||||||
|
if (checkAccess && taosCheckAccessFile(temp, TD_FILE_ACCESS_EXIST_OK | TD_FILE_ACCESS_READ_OK | TD_FILE_ACCESS_WRITE_OK)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return chmod(temp, mode);
|
return chmod(temp, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue