From 1203b5f7c95b5a90d4d8c04121e4ea65f713e946 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 16 Apr 2011 13:44:39 +0000 Subject: file modes can now be configured diff --git a/src/options.c b/src/options.c index e30e149..0ad0844 100644 --- a/src/options.c +++ b/src/options.c @@ -44,12 +44,12 @@ else if(!strcmp(str,SHORT) || !strcmp(str,LONG)) \ VALUE = 0; -#define PARSE_INT_PARAM(SHORT, LONG, VALUE) \ +#define PARSE_INT_PARAM(SHORT, LONG, VALUE, BASE) \ else if(!strcmp(str,SHORT) || !strcmp(str,LONG)) \ { \ if(argc < 1) \ return i; \ - VALUE = atoi(argv[i+1]); \ + VALUE = strtol(argv[i+1], (char **)NULL, BASE); \ argc--; \ i++; \ } @@ -199,8 +199,9 @@ int options_parse(options_t* opt, int argc, char* argv[]) PARSE_STRING_PARAM("-s","--source", opt->src_bin_desc_) PARSE_STRING_PARAM("-d","--output-dir", opt->output_dir_) PARSE_STRING_PARAM("-f","--name-format", opt->name_format_) - PARSE_INT_PARAM("-i","--interval", opt->interval_) - PARSE_INT_PARAM("-o","--offset", opt->offset_) + PARSE_INT_PARAM("-m","--mode", opt->mode_, 8) + PARSE_INT_PARAM("-i","--interval", opt->interval_, 10) + PARSE_INT_PARAM("-o","--offset", opt->offset_, 10) else return i; } @@ -244,6 +245,7 @@ void options_default(options_t* opt) opt->src_bin_desc_ = NULL; opt->output_dir_ = strdup("/srv/archiv"); opt->name_format_ = strdup("%Y-%m-%d-%H00.ogg"); + opt->mode_ = 0644; opt->interval_ = 50; opt->offset_ = 0; } @@ -289,6 +291,7 @@ void options_print_usage() printf(" as data source, see gst-launch man-page for syntax\n"); printf(" [-d|--output-dir] path to the output directory\n"); printf(" [-f|--name-format] the file name format, see manpage of strftime for the syntax\n"); + printf(" [-m|--mode] ocatl represantion of the file permission mode\n"); printf(" [-i|--interval] interval for time checks in ms\n"); printf(" [-o|--offset] time offset for recordings in ms\n"); } @@ -316,6 +319,7 @@ void options_print(options_t* opt) printf("src_bin_desc: >>%s<<\n", opt->src_bin_desc_); printf("output_dir: '%s'\n", opt->output_dir_); printf("name_format: '%s'\n", opt->name_format_); + printf("mode: %04o\n", (int)opt->mode_); printf("interval: %d\n", opt->interval_); printf("offset: %d\n", opt->offset_); } diff --git a/src/options.h b/src/options.h index aaad77a..e74218e 100644 --- a/src/options.h +++ b/src/options.h @@ -28,6 +28,7 @@ #ifndef RHARCHIVE_options_h_INCLUDED #define RHARCHIVE_options_h_INCLUDED +#include #include "string_list.h" #include "datatypes.h" @@ -43,6 +44,7 @@ struct options_struct { char* src_bin_desc_; char* output_dir_; char* name_format_; + mode_t mode_; int interval_; int offset_; }; diff --git a/src/rharchive.c b/src/rharchive.c index 03f549d..1744118 100644 --- a/src/rharchive.c +++ b/src/rharchive.c @@ -94,7 +94,7 @@ int main_loop(options_t* opt) return -1; } - int ret = writer_init(&writer, loop, opt->name_format_, opt->output_dir_, opt->interval_, opt->offset_); + int ret = writer_init(&writer, loop, opt->name_format_, opt->mode_, opt->output_dir_, opt->interval_, opt->offset_); 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 12ca9f3..d4a36ab 100644 --- a/src/writer.c +++ b/src/writer.c @@ -61,6 +61,7 @@ static int init_time_boundaries(writer_t* writer) } log_printf(INFO, "current filename is: %s(.?)", writer->current_.path_); writer->current_.fd_ = -1; + writer->current_.mode_ = writer->mode_; bd_time.tm_sec = 0; bd_time.tm_min = 0; @@ -80,6 +81,7 @@ static int init_time_boundaries(writer_t* writer) } log_printf(INFO, "next filename will be: %s(.?)", writer->next_.path_); writer->next_.fd_ = -1; + writer->next_.mode_ = writer->mode_; struct timespec b = { T, 0 }; writer->next_boundary_ = b; @@ -87,7 +89,7 @@ static int init_time_boundaries(writer_t* writer) return 0; } -int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, const char* output_dir, int interval, int offset) +int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, mode_t mode, const char* output_dir, int interval, int offset) { if(!writer) return -1; @@ -104,13 +106,14 @@ int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, cons return -1; } writer->name_format_ = name_format; + writer->mode_ = mode; writer->output_dir_ = output_dir; writer->interval_ = interval * GST_MSECOND; writer->offset_ = offset * GST_MSECOND; writer->current_.path_ = NULL; writer->next_.path_ = NULL; - writer->clock_id_ = 0; // TODO: NULL vs. 0 - writer->thread_ = 0; // TODO: NULL vs. 0 + writer->clock_id_ = NULL; + writer->thread_ = NULL; return init_time_boundaries(writer); } @@ -119,7 +122,7 @@ static 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, S_IRUSR | S_IWUSR | S_IRGRP); // make mode configurable + file->fd_ = open(file->path_, O_WRONLY | O_CREAT | O_EXCL, file->mode_); if(file->fd_ < 0) { if(errno != EEXIST) { // TODO: thread safe strerror @@ -141,6 +144,7 @@ static int open_file(file_t* file) free(file->path_); file->path_ = tmp; } + fchmod(file->fd_, file->mode_); } while(file->fd_ < 0); @@ -184,6 +188,10 @@ int writer_start(writer_t* writer) return ret; writer->clock_id_ = gst_clock_new_periodic_id(writer->clock_, 0, writer->interval_); + if(!writer->clock_id_) { + log_printf(ERROR, "clock id could not be created"); + return -1; + } writer->thread_ = g_thread_create(writer_thread_func, writer, TRUE, NULL); if(!writer->thread_) { log_printf(ERROR, "writer thread could not be started"); diff --git a/src/writer.h b/src/writer.h index 9e21dd3..1e1b236 100644 --- a/src/writer.h +++ b/src/writer.h @@ -31,10 +31,12 @@ #include #include #include +#include struct file_struct { int fd_; char* path_; + mode_t mode_; }; typedef struct file_struct file_t; @@ -46,6 +48,7 @@ struct writer_struct { GThread* thread_; const char* name_format_; const char* output_dir_; + mode_t mode_; GstClockTime interval_; GstClockTime offset_; file_t current_; @@ -54,7 +57,7 @@ struct writer_struct { }; typedef struct writer_struct writer_t; -int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, const char* output_dir, int interval, int offset); +int writer_init(writer_t* writer, GMainLoop *loop, const char* name_format, mode_t mode, const char* output_dir, int interval, int offset); int writer_start(writer_t* writer); void writer_stop(writer_t* writer); -- cgit v0.10.2