winlin

support change work_dir for oryx.

@@ -343,6 +343,7 @@ Remark: @@ -343,6 +343,7 @@ Remark:
343 343
344 ## History 344 ## History
345 345
  346 +* v2.0, 2016-09-23, support change work_dir for oryx.
346 * v2.0, 2016-09-15, fix #640, typo for rtmp type. 2.0.217 347 * v2.0, 2016-09-15, fix #640, typo for rtmp type. 2.0.217
347 * v2.0, 2016-09-12, fix fast stream error bug. 2.0.216 348 * v2.0, 2016-09-12, fix fast stream error bug. 2.0.216
348 * <strong>v2.0, 2016-09-09, [2.0 beta1(2.0.215)][r2.0b1] released. 89941 lines.</strong> 349 * <strong>v2.0, 2016-09-09, [2.0 beta1(2.0.215)][r2.0b1] released. 89941 lines.</strong>
@@ -50,6 +50,12 @@ daemon on; @@ -50,6 +50,12 @@ daemon on;
50 # default: off 50 # default: off
51 utc_time off; 51 utc_time off;
52 52
  53 +# the work dir for server, to chdir(work_dir) when not empty or "./"
  54 +# user can config this directory to change the dir.
  55 +# @reamrk do not support reload.
  56 +# default: ./
  57 +work_dir ./;
  58 +
53 ############################################################################################# 59 #############################################################################################
54 # heartbeat/stats sections 60 # heartbeat/stats sections
55 ############################################################################################# 61 #############################################################################################
@@ -1567,7 +1567,7 @@ int SrsConfig::check_config() @@ -1567,7 +1567,7 @@ int SrsConfig::check_config()
1567 && n != "max_connections" && n != "daemon" && n != "heartbeat" 1567 && n != "max_connections" && n != "daemon" && n != "heartbeat"
1568 && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms" 1568 && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"
1569 && n != "http_stream" && n != "http_server" && n != "stream_caster" 1569 && n != "http_stream" && n != "http_server" && n != "stream_caster"
1570 - && n != "utc_time" 1570 + && n != "utc_time" && n != "work_dir"
1571 ) { 1571 ) {
1572 ret = ERROR_SYSTEM_CONFIG_INVALID; 1572 ret = ERROR_SYSTEM_CONFIG_INVALID;
1573 srs_error("unsupported directive %s, ret=%d", n.c_str(), ret); 1573 srs_error("unsupported directive %s, ret=%d", n.c_str(), ret);
@@ -2172,6 +2172,17 @@ bool SrsConfig::get_utc_time() @@ -2172,6 +2172,17 @@ bool SrsConfig::get_utc_time()
2172 return SRS_CONF_PERFER_FALSE(conf->arg0()); 2172 return SRS_CONF_PERFER_FALSE(conf->arg0());
2173 } 2173 }
2174 2174
  2175 +string SrsConfig::get_work_dir() {
  2176 + static string DEFAULT = "./";
  2177 +
  2178 + SrsConfDirective* conf = root->get("work_dir");
  2179 + if( !conf || conf->arg0().empty()) {
  2180 + return DEFAULT;
  2181 + }
  2182 +
  2183 + return conf->arg0();
  2184 +}
  2185 +
2175 vector<SrsConfDirective*> SrsConfig::get_stream_casters() 2186 vector<SrsConfDirective*> SrsConfig::get_stream_casters()
2176 { 2187 {
2177 srs_assert(root); 2188 srs_assert(root);
@@ -374,6 +374,11 @@ public: @@ -374,6 +374,11 @@ public:
374 * whether use utc-time to format the time. 374 * whether use utc-time to format the time.
375 */ 375 */
376 virtual bool get_utc_time(); 376 virtual bool get_utc_time();
  377 + /**
  378 + * get the configed work dir.
  379 + * ignore if empty string.
  380 + */
  381 + virtual std::string get_work_dir();
377 // stream_caster section 382 // stream_caster section
378 public: 383 public:
379 /** 384 /**
@@ -282,6 +282,13 @@ int main(int argc, char** argv) @@ -282,6 +282,13 @@ int main(int argc, char** argv)
282 return ret; 282 return ret;
283 } 283 }
284 284
  285 + // change the work dir and set cwd.
  286 + std::string cwd = _srs_config->get_work_dir();
  287 + if (!cwd.empty() && cwd != "./" && (ret = chdir(cwd.c_str())) != ERROR_SUCCESS) {
  288 + srs_error("change cwd to %s failed. ret=%d", cwd.c_str(), ret);
  289 + return ret;
  290 + }
  291 +
285 // config parsed, initialize log. 292 // config parsed, initialize log.
286 if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) { 293 if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) {
287 return ret; 294 return ret;