mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-09-22 04:15:54 -04:00
Feature: Support limiting dumpfiles by size and time
This adds two new mount options: * <dump-file-time-limit /> * <dump-file-size-limit /> Closes: #2173
This commit is contained in:
parent
801b315d1d
commit
054d45bf3b
@ -1737,6 +1737,14 @@ static void _parse_mount(xmlDocPtr doc,
|
|||||||
} else if (xmlStrcmp(node->name, XMLSTR("dump-file")) == 0) {
|
} else if (xmlStrcmp(node->name, XMLSTR("dump-file")) == 0) {
|
||||||
mount->dumpfile = (char *)xmlNodeListGetString(doc,
|
mount->dumpfile = (char *)xmlNodeListGetString(doc,
|
||||||
node->xmlChildrenNode, 1);
|
node->xmlChildrenNode, 1);
|
||||||
|
} else if (xmlStrcmp(node->name, XMLSTR("dump-file-size-limit")) == 0) {
|
||||||
|
unsigned int val = mount->dumpfile_size_limit;
|
||||||
|
__read_unsigned_int(configuration, doc, node, &val, 0, UINT_MAX);
|
||||||
|
mount->dumpfile_size_limit = val;
|
||||||
|
} else if (xmlStrcmp(node->name, XMLSTR("dump-file-time-limit")) == 0) {
|
||||||
|
unsigned int val = mount->dumpfile_time_limit;
|
||||||
|
__read_unsigned_int(configuration, doc, node, &val, 0, UINT_MAX);
|
||||||
|
mount->dumpfile_time_limit = val;
|
||||||
} else if (xmlStrcmp(node->name, XMLSTR("intro")) == 0) {
|
} else if (xmlStrcmp(node->name, XMLSTR("intro")) == 0) {
|
||||||
mount->intro_filename = (char *)xmlNodeListGetString(doc,
|
mount->intro_filename = (char *)xmlNodeListGetString(doc,
|
||||||
node->xmlChildrenNode, 1);
|
node->xmlChildrenNode, 1);
|
||||||
@ -2989,6 +2997,10 @@ static void merge_mounts(mount_proxy * dst, mount_proxy * src)
|
|||||||
|
|
||||||
if (!dst->dumpfile)
|
if (!dst->dumpfile)
|
||||||
dst->dumpfile = (char*)xmlStrdup((xmlChar*)src->dumpfile);
|
dst->dumpfile = (char*)xmlStrdup((xmlChar*)src->dumpfile);
|
||||||
|
if (!dst->dumpfile_size_limit)
|
||||||
|
dst->dumpfile_size_limit = src->dumpfile_size_limit;
|
||||||
|
if (!dst->dumpfile_time_limit)
|
||||||
|
dst->dumpfile_time_limit = src->dumpfile_time_limit;
|
||||||
if (!dst->intro_filename)
|
if (!dst->intro_filename)
|
||||||
dst->intro_filename = (char*)xmlStrdup((xmlChar*)src->intro_filename);
|
dst->intro_filename = (char*)xmlStrdup((xmlChar*)src->intro_filename);
|
||||||
if (!dst->fallback_when_full)
|
if (!dst->fallback_when_full)
|
||||||
|
@ -88,6 +88,8 @@ typedef struct _mount_proxy {
|
|||||||
* NULL to not dump.
|
* NULL to not dump.
|
||||||
*/
|
*/
|
||||||
char *dumpfile;
|
char *dumpfile;
|
||||||
|
uint64_t dumpfile_size_limit;
|
||||||
|
unsigned int dumpfile_time_limit;
|
||||||
/* Send contents of file to client before the stream */
|
/* Send contents of file to client before the stream */
|
||||||
char *intro_filename;
|
char *intro_filename;
|
||||||
/* Switch new listener to fallback source when max listeners reached */
|
/* Switch new listener to fallback source when max listeners reached */
|
||||||
|
25
src/source.c
25
src/source.c
@ -1183,13 +1183,27 @@ static void source_apply_mount (ice_config_t *config, source_t *source, mount_pr
|
|||||||
source->fallback_mount = NULL;
|
source->fallback_mount = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Dumpfile settings */
|
||||||
if (mountinfo && mountinfo->dumpfile) {
|
if (mountinfo && mountinfo->dumpfile) {
|
||||||
util_replace_string(&(source->dumpfilename), mountinfo->dumpfile);
|
util_replace_string(&(source->dumpfilename), mountinfo->dumpfile);
|
||||||
} else {
|
} else {
|
||||||
free(source->dumpfilename);
|
free(source->dumpfilename);
|
||||||
source->dumpfilename = NULL;
|
source->dumpfilename = NULL;
|
||||||
|
if (source->dumpfile) {
|
||||||
|
ICECAST_LOG_INFO("Stopping dumpfile as it is now de-configured for source %p at mountpoint %#H.", source, source->mount);
|
||||||
|
source_kill_dumpfile(source);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mountinfo) {
|
||||||
|
source->dumpfile_size_limit = mountinfo->dumpfile_size_limit;
|
||||||
|
source->dumpfile_time_limit = mountinfo->dumpfile_time_limit;
|
||||||
|
} else {
|
||||||
|
source->dumpfile_size_limit = 0;
|
||||||
|
source->dumpfile_time_limit = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (source->intro_file)
|
if (source->intro_file)
|
||||||
{
|
{
|
||||||
fclose (source->intro_file);
|
fclose (source->intro_file);
|
||||||
@ -1483,6 +1497,17 @@ bool source_write_dumpfile(source_t *source, const void *buffer, size_t len)
|
|||||||
|
|
||||||
source->dumpfile_written += len;
|
source->dumpfile_written += len;
|
||||||
|
|
||||||
|
if (source->dumpfile_size_limit && source->dumpfile_written > source->dumpfile_size_limit) {
|
||||||
|
ICECAST_LOG_INFO("Dumpfile for source %p at mountpoint %#H reached size limit. Dumpfile will be disabled.", source, source->mount);
|
||||||
|
source_kill_dumpfile(source);
|
||||||
|
} else if (source->dumpfile_time_limit) {
|
||||||
|
time_t now = time(NULL);
|
||||||
|
if (now > (source->dumpfile_start + source->dumpfile_time_limit)) {
|
||||||
|
ICECAST_LOG_INFO("Dumpfile for source %p at mountpoint %#H reached time limit. Dumpfile will be disabled.", source, source->mount);
|
||||||
|
source_kill_dumpfile(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,8 @@ struct source_tag {
|
|||||||
/* Dumpfile related data */
|
/* Dumpfile related data */
|
||||||
/* Config */
|
/* Config */
|
||||||
char *dumpfilename; /* Name of a file to dump incoming stream to */
|
char *dumpfilename; /* Name of a file to dump incoming stream to */
|
||||||
|
uint64_t dumpfile_size_limit;
|
||||||
|
unsigned int dumpfile_time_limit;
|
||||||
/* Runtime */
|
/* Runtime */
|
||||||
FILE *dumpfile;
|
FILE *dumpfile;
|
||||||
time_t dumpfile_start;
|
time_t dumpfile_start;
|
||||||
|
Loading…
Reference in New Issue
Block a user