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

Support include empty config file. v5.0.173 v6.0.68 (#3768)

SRS supports including another configuration in the include package.
When generating configurations, we can only generate the changed
configurations, while the unchanged configurations are in the fixed
files, for example:

```nginx
listen 1935;
include server.conf;
```

In `server.conf`, we can manage the changing configurations with the
program:

```nginx
http_api { enabled on; }
```

However, during system initialization, we often create an empty
`server.conf`, and the content is generated only after the program
starts, so `server.conf` might be an empty file. This also makes it
convenient to use a script to confirm the existence of this file:

```bash
touch server.conf
```

Currently, SRS does not support empty configurations and will report an
error. This PR is to solve this problem, making it more convenient to
use include.

`TRANS_BY_GPT4`

---------

Co-authored-by: Haibo Chen <495810242@qq.com>
This commit is contained in:
Winlin 2023-08-28 10:28:23 +08:00 committed by winlin
parent b5347e19f7
commit cf46dae80f
9 changed files with 124 additions and 22 deletions

View file

@ -123,6 +123,8 @@ namespace srs_internal
// read all.
int filesize = (int)reader.filesize();
// Ignore if empty file.
if (filesize <= 0) return err;
// create buffer
srs_freepa(start);
@ -1068,6 +1070,9 @@ SrsJsonAny* SrsConfDirective::dumps_arg0_to_boolean()
srs_error_t SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveContext ctx, SrsConfig* conf)
{
srs_error_t err = srs_success;
// Ignore empty config file.
if (ctx == SrsDirectiveContextFile && buffer->empty()) return err;
while (true) {
std::vector<string> args;
@ -1127,7 +1132,7 @@ srs_error_t SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveCo
}
if ((err = parse_conf(include_file_buffer, SrsDirectiveContextFile, conf)) != srs_success) {
return srs_error_wrap(err, "parse include buffer");
return srs_error_wrap(err, "parse include buffer %s", file.c_str());
}
}
}
@ -2197,11 +2202,11 @@ srs_error_t SrsConfig::parse_file(const char* filename)
SrsConfigBuffer* buffer = NULL;
SrsAutoFree(SrsConfigBuffer, buffer);
if ((err = build_buffer(config_file, &buffer)) != srs_success) {
return srs_error_wrap(err, "buffer fullfill %s", config_file.c_str());
return srs_error_wrap(err, "buffer fullfill %s", filename);
}
if ((err = parse_buffer(buffer)) != srs_success) {
return srs_error_wrap(err, "parse buffer");
return srs_error_wrap(err, "parse buffer %s", filename);
}
return err;