Merge anthm's "-t" flag (with minor mods) (bug #2380)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3735 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.0
Mark Spencer 21 years ago
parent 0da197d593
commit 24e902d2a4

@ -371,6 +371,7 @@ bininstall: all
mkdir -p $(DESTDIR)$(ASTSBINDIR)
mkdir -p $(DESTDIR)$(ASTVARRUNDIR)
mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/voicemail
mkdir -p $(DESTDIR)$(ASTSPOOLDIR)/tmp
install -m 755 asterisk $(DESTDIR)$(ASTSBINDIR)/
install -m 755 contrib/scripts/astgenkey $(DESTDIR)$(ASTSBINDIR)/
if [ ! -f $(DESTDIR)$(ASTSBINDIR)/safe_asterisk ]; then \

@ -76,9 +76,11 @@ int option_exec=0;
int option_initcrypto=0;
int option_nocolor;
int option_dumpcore = 0;
int option_cache_record_files = 0;
int option_overrideconfig = 0;
int option_reconnect = 0;
int fully_booted = 0;
char record_cache_dir[AST_CACHE_DIR_LEN] = "/var/spool/asterisk/tmp";
static int ast_socket = -1; /* UNIX Socket for allowing remote control */
static int ast_consock = -1; /* UNIX Socket for controlling another asterisk */
@ -1473,6 +1475,7 @@ static int show_cli_help(void) {
printf(" -q Quiet mode (supress output)\n");
printf(" -r Connect to Asterisk on this machine\n");
printf(" -R Connect to Asterisk, and attempt to reconnect if disconnected\n");
printf(" -t Record soundfiles in /tmp and move them where they belong after they are done.\n");
printf(" -v Increase verbosity (multiple v's = more verbose)\n");
printf(" -x <cmd> Execute command <cmd> (only valid with -r)\n");
printf("\n");
@ -1531,6 +1534,33 @@ static void ast_readconfig(void) {
}
v = v->next;
}
v = ast_variable_browse(cfg, "options");
while(v) {
if(!strcasecmp(v->name, "verbose")) {
option_verbose= atoi(v->value);
} else if (!strcasecmp(v->name, "debug")) {
option_debug= ast_true(v->value);
} else if (!strcasecmp(v->name, "nofork")) {
option_nofork = ast_true(v->value);
} else if (!strcasecmp(v->name, "quiet")) {
option_quiet = ast_true(v->value);
} else if (!strcasecmp(v->name, "console")) {
option_console = ast_true(v->value);
} else if (!strcasecmp(v->name, "highpriority")) {
option_highpriority = ast_true(v->value);
} else if (!strcasecmp(v->name, "initcrypto")) {
option_initcrypto = ast_true(v->value);
} else if (!strcasecmp(v->name, "nocolor")) {
option_nocolor = ast_true(v->value);
} else if (!strcasecmp(v->name, "dumpcore")) {
option_dumpcore = ast_true(v->value);
} else if (!strcasecmp(v->name, "cache_record_files")) {
option_cache_record_files = ast_true(v->value);
} else if (!strcasecmp(v->name, "record_cache_dir")) {
strncpy(record_cache_dir,v->value,AST_CACHE_DIR_LEN);
}
v = v->next;
}
ast_destroy(cfg);
}
@ -1580,7 +1610,7 @@ int main(int argc, char *argv[])
}
*/
/* Check for options */
while((c=getopt(argc, argv, "hfdvVqprRgcinx:U:G:C:")) != -1) {
while((c=getopt(argc, argv, "thfdvVqprRgcinx:U:G:C:")) != -1) {
switch(c) {
case 'd':
option_debug++;
@ -1615,6 +1645,9 @@ int main(int argc, char *argv[])
case 'q':
option_quiet++;
break;
case 't':
option_cache_record_files++;
break;
case 'x':
option_exec++;
xarg = optarg;
@ -1822,8 +1855,13 @@ int main(int argc, char *argv[])
printf(term_quit());
exit(1);
}
/* reload logger in case a custom config handler binded to logger.conf*/
/* sync cust config and reload some internals in case a custom config handler binded to them */
read_ast_cust_config();
reload_logger(0);
reload_manager();
ast_enum_reload();
ast_rtp_reload();
/* We might have the option of showing a console, but for now just
do nothing... */

@ -22,6 +22,7 @@
#include <asterisk/translate.h>
#include <asterisk/utils.h>
#include <asterisk/lock.h>
#include <asterisk/app.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
@ -71,6 +72,7 @@ struct ast_filestream {
int flags;
mode_t mode;
char *filename;
char *realfilename;
/* Video file stream */
struct ast_filestream *vfs;
/* Transparently translate from another format -- just once */
@ -649,6 +651,8 @@ int ast_stream_rewind(struct ast_filestream *fs, long ms)
int ast_closestream(struct ast_filestream *f)
{
char *cmd = NULL;
size_t size = 0;
/* Stop a running stream if there is one */
if (f->owner) {
if (f->fmt->format < AST_FORMAT_MAX_AUDIO) {
@ -671,10 +675,24 @@ int ast_closestream(struct ast_filestream *f)
ast_translator_free_path(f->trans);
f->trans = NULL;
}
if (f->filename)
free(f->filename);
f->filename = NULL;
if (f->realfilename && f->filename) {
size = strlen(f->filename) + strlen(f->realfilename) + 15;
cmd = alloca(size);
memset(cmd,0,size);
snprintf(cmd,size,"/bin/mv -f %s %s",f->filename,f->realfilename);
ast_safe_system(cmd);
}
f->fmt->close(f);
if (f->filename) {
free(f->filename);
f->filename = NULL;
}
if (f->realfilename) {
free(f->realfilename);
f->realfilename = NULL;
}
return 0;
}
@ -816,8 +834,11 @@ struct ast_filestream *ast_writefile(char *filename, char *type, char *comment,
int fd,myflags = 0;
struct ast_format *f;
struct ast_filestream *fs=NULL;
char *fn;
char *fn,*orig_fn=NULL;
char *ext;
char *buf=NULL;
size_t size = 0;
if (ast_mutex_lock(&formatlock)) {
ast_log(LOG_WARNING, "Unable to lock format list\n");
return NULL;
@ -833,11 +854,31 @@ struct ast_filestream *ast_writefile(char *filename, char *type, char *comment,
if (exts_compare(f->exts, type)) {
char *stringp=NULL;
/* XXX Implement check XXX */
ext = strdup(f->exts);
ext = ast_strdupa(f->exts);
stringp=ext;
ext = strsep(&stringp, "|");
fn = build_filename(filename, ext);
fd = open(fn, flags | myflags, mode);
if (option_cache_record_files && fd >= 0) {
close(fd);
/*
We touch orig_fn just as a place-holder so other things (like vmail) see the file is there.
What we are really doing is writing to record_cache_dir until we are done then we will mv the file into place.
*/
orig_fn = ast_strdupa(fn);
for (size=0;size<strlen(fn);size++)
if (fn[size] == '/')
fn[size] = '_';
size += (strlen(record_cache_dir) + 10);
buf = alloca(size);
memset(buf,0,size);
snprintf(buf,size,"%s/%s",record_cache_dir,fn);
free(fn);
fn=buf;
fd = open(fn, flags | myflags, mode);
}
if (fd >= 0) {
errno = 0;
if ((fs = f->rewrite(fd, comment))) {
@ -845,17 +886,30 @@ struct ast_filestream *ast_writefile(char *filename, char *type, char *comment,
fs->fmt = f;
fs->flags = flags;
fs->mode = mode;
fs->filename = strdup(filename);
if (option_cache_record_files) {
fs->realfilename = build_filename(filename, ext);
fs->filename = strdup(fn);
}
else {
fs->realfilename = NULL;
fs->filename = strdup(filename);
}
fs->vfs = NULL;
} else {
ast_log(LOG_WARNING, "Unable to rewrite %s\n", fn);
close(fd);
unlink(fn);
if (orig_fn)
unlink(orig_fn);
}
} else if (errno != EEXIST)
} else if (errno != EEXIST) {
ast_log(LOG_WARNING, "Unable to open file %s: %s\n", fn, strerror(errno));
free(fn);
free(ext);
if(orig_fn)
unlink(orig_fn);
}
if (!buf) /* if buf != NULL then fn is already free and pointing to it */
free(fn);
break;
}
f = f->next;

@ -18,6 +18,8 @@
extern "C" {
#endif
#define AST_CACHE_DIR_LEN 512
extern int option_verbose;
extern int option_debug;
extern int option_nofork;
@ -26,10 +28,12 @@ extern int option_console;
extern int option_initcrypto;
extern int option_nocolor;
extern int fully_booted;
extern int option_cache_record_files;
extern char defaultlanguage[];
extern time_t ast_startuptime;
extern time_t ast_lastreloadtime;
extern int ast_mainpid;
extern char record_cache_dir[AST_CACHE_DIR_LEN];
#define VERBOSE_PREFIX_1 " "
#define VERBOSE_PREFIX_2 " == "

Loading…
Cancel
Save