diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/file_list.c | 8 | ||||
-rw-r--r-- | src/file_list.h | 3 | ||||
-rw-r--r-- | src/options.c | 4 | ||||
-rw-r--r-- | src/options.h | 1 | ||||
-rw-r--r-- | src/rharchive.c | 2 | ||||
-rw-r--r-- | src/writer.c | 9 | ||||
-rw-r--r-- | src/writer.h | 3 |
7 files changed, 21 insertions, 9 deletions
diff --git a/src/file_list.c b/src/file_list.c index deb6337..cd7e697 100644 --- a/src/file_list.c +++ b/src/file_list.c @@ -63,7 +63,7 @@ void file_list_clear(file_list_t* list) g_mutex_unlock(&(list->mutex_)); } -file_t* file_list_add(file_list_t* list, struct tm* time, const char* type, const char* format, const char* dir, mode_t mode) +file_t* file_list_add(file_list_t* list, struct tm* time, const char* type, const char* format, const char* dir, mode_t mode, int nocache) { if(!list || !(&(list->mutex_))) return NULL; @@ -85,6 +85,7 @@ file_t* file_list_add(file_list_t* list, struct tm* time, const char* type, cons log_printf(INFO, "%s filename is: %s(.?)", type, tmp->path_); tmp->fd_ = FILE_CLOSED; tmp->mode_ = mode; + tmp->nocache_ = nocache; tmp->pp_child_ = NULL; g_mutex_lock(&(list->mutex_)); @@ -177,7 +178,10 @@ int open_file(file_t* file) char* orig_path = file->path_; int cnt = 0; do { - file->fd_ = open(file->path_, O_WRONLY | O_CREAT | O_EXCL, file->mode_); + int flags = O_WRONLY | O_CREAT | O_EXCL; + if(file->nocache_) + flags |= O_DIRECT; + file->fd_ = open(file->path_, flags, file->mode_); if(file->fd_ < 0) { if(errno != EEXIST) { // TODO: thread safe strerror diff --git a/src/file_list.h b/src/file_list.h index 82931a9..45be1cf 100644 --- a/src/file_list.h +++ b/src/file_list.h @@ -40,6 +40,7 @@ struct file_struct { int fd_; char* path_; mode_t mode_; + int nocache_; child_t* pp_child_; }; typedef struct file_struct file_t; @@ -52,7 +53,7 @@ typedef struct file_list_struct file_list_t; int file_list_init(file_list_t* list); void file_list_clear(file_list_t* list); -file_t* file_list_add(file_list_t* list, struct tm* time, const char* type, const char* format, const char* dir, mode_t mode); +file_t* file_list_add(file_list_t* list, struct tm* time, const char* type, const char* format, const char* dir, mode_t mode, int nocache); int file_list_remove(file_list_t* list, int fd); int file_list_call_post_process(file_list_t* list, int fd, char* script); int file_list_waitpid(file_list_t* list); diff --git a/src/options.c b/src/options.c index f8a42d8..71015f8 100644 --- a/src/options.c +++ b/src/options.c @@ -197,6 +197,7 @@ int options_parse(options_t* opt, int argc, char* argv[]) PARSE_STRING_PARAM("-d","--output-dir", opt->output_dir_) PARSE_STRING_PARAM("-f","--name-format", opt->name_format_) PARSE_INT_PARAM("-m","--mode", opt->mode_, 8) + PARSE_BOOL_PARAM("-n", "--nocache", opt->nocache_) PARSE_INT_PARAM("-i","--interval", opt->interval_, 10) PARSE_INT_PARAM("-o","--offset", opt->offset_, 10) PARSE_STRING_PARAM("-x","--post-process", opt->post_process_) @@ -244,6 +245,7 @@ void options_default(options_t* opt) opt->output_dir_ = strdup("/srv/archiv"); opt->name_format_ = strdup("%Y-%m-%d-%H00.ogg"); opt->mode_ = 0644; + opt->nocache_ = 0; opt->interval_ = 50; opt->offset_ = 0; opt->post_process_ = NULL; @@ -293,6 +295,7 @@ void options_print_usage() printf(" [-d|--output-dir] <path> path to the output directory\n"); printf(" [-f|--name-format] <format> the file name format, see manpage of strftime for the syntax\n"); printf(" [-m|--mode] <value> octal representation of the file permission mode\n"); + printf(" [-n|--nocache] Use O_DIRECT for recorded files\n"); printf(" [-i|--interval] <value> interval for time checks in ms\n"); printf(" [-o|--offset] <value> time offset for recordings in ms\n"); printf(" [-x|--post-process] <script> call script when file is finished\n"); @@ -322,6 +325,7 @@ void options_print(options_t* opt) printf("output_dir: '%s'\n", opt->output_dir_); printf("name_format: '%s'\n", opt->name_format_); printf("mode: %04o\n", (int)opt->mode_); + printf("nocache: %s\n", !opt->nocache_ ? "false" : "true"); printf("interval: %d\n", opt->interval_); printf("offset: %d\n", opt->offset_); printf("post_process: '%s'\n", opt->post_process_); diff --git a/src/options.h b/src/options.h index a91cd86..a529d9c 100644 --- a/src/options.h +++ b/src/options.h @@ -42,6 +42,7 @@ struct options_struct { char* output_dir_; char* name_format_; mode_t mode_; + int nocache_; int interval_; int offset_; char* post_process_; diff --git a/src/rharchive.c b/src/rharchive.c index 6d6bb7d..3bfca27 100644 --- a/src/rharchive.c +++ b/src/rharchive.c @@ -92,7 +92,7 @@ int main_loop(options_t* opt) return -1; } - int ret = writer_init(&writer, loop, opt->name_format_, opt->mode_, opt->output_dir_, opt->interval_, opt->offset_, opt->post_process_); + int ret = writer_init(&writer, loop, opt->name_format_, opt->mode_, opt->nocache_, opt->output_dir_, opt->interval_, opt->offset_, opt->post_process_); if(ret) { gst_object_unref(GST_OBJECT(pipeline)); gst_object_unref(GST_OBJECT(loop)); diff --git a/src/writer.c b/src/writer.c index d7875de..95d12ed 100644 --- a/src/writer.c +++ b/src/writer.c @@ -47,7 +47,7 @@ static int init_time_boundaries(writer_t* writer) struct tm bd_time; localtime_r(&(now.tv_sec), &bd_time); - writer->current_ = file_list_add(&(writer->files_), &bd_time, "current", writer->name_format_, writer->output_dir_, writer->mode_); + writer->current_ = file_list_add(&(writer->files_), &bd_time, "current", writer->name_format_, writer->output_dir_, writer->mode_, writer->nocache_); if(writer->current_ == NULL) return -2; bd_time.tm_sec = 0; @@ -59,7 +59,7 @@ static int init_time_boundaries(writer_t* writer) struct timespec b = { T, 0 }; writer->next_boundary_ = b; - writer->next_ = file_list_add(&(writer->files_), &bd_time, "next", writer->name_format_, writer->output_dir_, writer->mode_); + writer->next_ = file_list_add(&(writer->files_), &bd_time, "next", writer->name_format_, writer->output_dir_, writer->mode_, writer->nocache_); if(writer->next_ == NULL) return -2; return 0; @@ -92,7 +92,7 @@ static void fdremoved_cb(GstElement* sink, gint fd, gpointer data) file_list_remove(&(writer->files_), fd); } -int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, mode_t mode, const char* output_dir, int interval, int offset, char* post_process) +int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, mode_t mode, int nocache, const char* output_dir, int interval, int offset, char* post_process) { if(!writer) return -1; @@ -116,6 +116,7 @@ int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, mode } writer->name_format_ = name_format; writer->mode_ = mode; + writer->nocache_ = nocache; writer->output_dir_ = output_dir; writer->interval_ = interval * GST_MSECOND; writer->offset_ = offset * GST_MSECOND; @@ -164,7 +165,7 @@ static int check_boundaries(writer_t* writer) struct tm bd_time; localtime_r(&(writer->next_boundary_.tv_sec), &bd_time); - writer->next_ = file_list_add(&(writer->files_), &bd_time, "next", writer->name_format_, writer->output_dir_, writer->mode_); + writer->next_ = file_list_add(&(writer->files_), &bd_time, "next", writer->name_format_, writer->output_dir_, writer->mode_, writer->nocache_); if(writer->next_ == NULL) return -2; } diff --git a/src/writer.h b/src/writer.h index 8e012a9..9ee98a8 100644 --- a/src/writer.h +++ b/src/writer.h @@ -41,6 +41,7 @@ struct writer_struct { const char* name_format_; const char* output_dir_; mode_t mode_; + int nocache_; GstClockTime interval_; GstClockTime offset_; char* post_process_; @@ -51,7 +52,7 @@ struct writer_struct { }; typedef struct writer_struct writer_t; -int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, mode_t mode, const char* output_dir, int interval, int offset, char* post_process); +int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, mode_t mode, int nocache, const char* output_dir, int interval, int offset, char* post_process); int writer_start(writer_t* writer); void writer_stop(writer_t* writer); |