1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

SRS5: Config: Support better env name for prefixed with srs (#3370)

* Actions: Fix github action warnings.

* Forward: Bind the context id of source or stream.

* Config: Support better env names.

PICK a4e7427433

Co-authored-by: pengfei.ma <pengfei.ma@ctechm.com>
Co-authored-by: Haibo Chen <495810242@qq.com>
This commit is contained in:
Winlin 2023-01-11 10:39:05 +08:00 committed by winlin
parent f46231cf3e
commit 498ce72af8
8 changed files with 53 additions and 13 deletions

View file

@ -1919,7 +1919,7 @@ srs_error_t SrsConfig::parse_options(int argc, char** argv)
// If use env only, we set change to daemon(off) and console log.
if (env_only_) {
if (!getenv("SRS_DAEMON")) setenv("SRS_DAEMON", "off", 1);
if (!getenv("SRS_SRS_LOG_TANK")) setenv("SRS_SRS_LOG_TANK", "console", 1);
if (!getenv("SRS_SRS_LOG_TANK") && !getenv("SRS_LOG_TANK")) setenv("SRS_SRS_LOG_TANK", "console", 1);
if (root->directives.empty()) root->get_or_create("vhost", "__defaultVhost__");
}
@ -6340,9 +6340,12 @@ extern bool _srs_in_docker;
bool SrsConfig::get_log_tank_file()
{
if (!srs_getenv("srs.srs_log_tank").empty()) { // SRS_
if (!srs_getenv("srs.srs_log_tank").empty()) { // SRS_SRS_LOG_TANK
return srs_getenv("srs.srs_log_tank") != "console";
}
if (!srs_getenv("srs.log_tank").empty()) { // SRS_LOG_TANK
return srs_getenv("srs.log_tank") != "console";
}
static bool DEFAULT = true;
@ -6361,6 +6364,7 @@ bool SrsConfig::get_log_tank_file()
string SrsConfig::get_log_level()
{
SRS_OVERWRITE_BY_ENV_STRING("srs.srs_log_level"); // SRS_SRS_LOG_LEVEL
SRS_OVERWRITE_BY_ENV_STRING("srs.log_level"); // SRS_LOG_LEVEL
static string DEFAULT = "trace";
@ -6375,6 +6379,7 @@ string SrsConfig::get_log_level()
string SrsConfig::get_log_level_v2()
{
SRS_OVERWRITE_BY_ENV_STRING("srs.srs_log_level_v2"); // SRS_SRS_LOG_LEVEL_V2
SRS_OVERWRITE_BY_ENV_STRING("srs.log_level_v2"); // SRS_LOG_LEVEL_V2
static string DEFAULT = "";
@ -6389,6 +6394,7 @@ string SrsConfig::get_log_level_v2()
string SrsConfig::get_log_file()
{
SRS_OVERWRITE_BY_ENV_STRING("srs.srs_log_file"); // SRS_SRS_LOG_FILE
SRS_OVERWRITE_BY_ENV_STRING("srs.log_file"); // SRS_LOG_FILE
static string DEFAULT = "./objs/srs.log";

View file

@ -66,6 +66,9 @@ srs_error_t SrsForwarder::initialize(SrsRequest* r, string ep)
// the ep(endpoint) to forward to
ep_forward = ep;
// Remember the source context id.
source_cid_ = _srs_context->get_id();
return err;
}
@ -164,7 +167,10 @@ srs_error_t SrsForwarder::on_video(SrsSharedPtrMessage* shared_video)
srs_error_t SrsForwarder::cycle()
{
srs_error_t err = srs_success;
srs_trace("Forwarder: Start forward %s of source=[%s] to %s",
req->get_stream_url().c_str(), source_cid_.c_str(), ep_forward.c_str());
while (true) {
// We always check status first.
// @see https://github.com/ossrs/srs/issues/1634#issuecomment-597571561

View file

@ -32,6 +32,9 @@ private:
// The ep to forward, server[:port].
std::string ep_forward;
SrsRequest* req;
private:
// The source or stream context id to bind to.
SrsContextId source_cid_;
private:
SrsCoroutine* trd;
private:

View file

@ -3943,6 +3943,9 @@ VOID TEST(ConfigEnvTest, CheckEnvValuesGlobal)
SrsSetEnvConfig(pid, "SRS_PID", "xxx");
EXPECT_STREQ("xxx", conf.get_pid_file().c_str());
SrsSetEnvConfig(log_tank, "SRS_SRS_LOG_TANK", "console");
EXPECT_FALSE(conf.get_log_tank_file());
SrsSetEnvConfig(log_file, "SRS_SRS_LOG_FILE", "xxx2");
EXPECT_STREQ("xxx2", conf.get_log_file().c_str());
@ -3956,6 +3959,28 @@ VOID TEST(ConfigEnvTest, CheckEnvValuesGlobal)
EXPECT_STREQ("xxx5", conf.get_work_dir().c_str());
}
if (true) {
MockSrsConfig conf;
SrsSetEnvConfig(pid, "SRS_PID", "xxx");
EXPECT_STREQ("xxx", conf.get_pid_file().c_str());
SrsSetEnvConfig(log_tank, "SRS_LOG_TANK", "console");
EXPECT_FALSE(conf.get_log_tank_file());
SrsSetEnvConfig(log_file, "SRS_LOG_FILE", "xxx2");
EXPECT_STREQ("xxx2", conf.get_log_file().c_str());
SrsSetEnvConfig(log_level, "SRS_LOG_LEVEL", "xxx3");
EXPECT_STREQ("xxx3", conf.get_log_level().c_str());
SrsSetEnvConfig(log_level_v2, "SRS_LOG_LEVEL_V2", "xxx4");
EXPECT_STREQ("xxx4", conf.get_log_level_v2().c_str());
SrsSetEnvConfig(work_dir, "SRS_WORK_DIR", "xxx5");
EXPECT_STREQ("xxx5", conf.get_work_dir().c_str());
}
if (true) {
MockSrsConfig conf;

View file

@ -356,7 +356,7 @@ VOID TEST(KernelFileWriterTest, RealfileTest)
{
srs_error_t err;
string filename = "./test-realfile.log";
string filename = _srs_tmp_file_prefix + "test-realfile.log";
MockFileRemover disposer(filename);
if (true) {