diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2000-07-28 13:44:31 +0200 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2000-07-28 13:44:31 +0200 |
commit | 92096e097a5cb6b90fb982d90b16012682d67ccf (patch) | |
tree | 132e337d98f7dbfec9d81c234d32171abd9d3fdc | |
parent | 7ac97639da8b6428e2a17464bddea0280f032321 (diff) | |
download | vdr-92096e097a5cb6b90fb982d90b16012682d67ccf.tar.gz vdr-92096e097a5cb6b90fb982d90b16012682d67ccf.tar.bz2 |
Added command line option '-v'
-rw-r--r-- | HISTORY | 1 | ||||
-rw-r--r-- | recording.c | 12 | ||||
-rw-r--r-- | recording.h | 4 | ||||
-rw-r--r-- | tools.c | 20 | ||||
-rw-r--r-- | tools.h | 3 | ||||
-rw-r--r-- | vdr.c | 27 |
6 files changed, 51 insertions, 16 deletions
@@ -105,3 +105,4 @@ Video Disk Recorder Revision History - When scrolling through a list it now moves a full page up or down when the cursor reaches the top or bottom of the menu (thanks to Heino Goldenstein!). - Added missing '#include <sys/stat.h>' to recording.c. +- The video directory can now be defined with the command line option -v. diff --git a/recording.c b/recording.c index 067ce68a..277b9114 100644 --- a/recording.c +++ b/recording.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: recording.c 1.13 2000/07/27 20:01:05 kls Exp $ + * $Id: recording.c 1.14 2000/07/28 12:47:54 kls Exp $ */ #define _GNU_SOURCE @@ -32,14 +32,14 @@ #define DISKCHECKDELTA 300 // seconds between checks for free disk space -const char *BaseDir = "/video"; +const char *VideoDirectory = "/video"; static bool LowDiskSpace(void) { //TODO Find a simpler way to determine the amount of free disk space! bool result = true; char *cmd = NULL; - asprintf(&cmd, DFCMD, BaseDir); + asprintf(&cmd, DFCMD, VideoDirectory); FILE *p = popen(cmd, "r"); if (p) { char *s; @@ -124,7 +124,7 @@ cRecording::cRecording(const char *FileName) { titleBuffer = NULL; fileName = strdup(FileName); - FileName += strlen(BaseDir) + 1; + FileName += strlen(VideoDirectory) + 1; char *p = strrchr(FileName, '/'); name = NULL; @@ -190,7 +190,7 @@ const char *cRecording::FileName(void) { if (!fileName) { struct tm *t = localtime(&start); - asprintf(&fileName, NAMEFORMAT, BaseDir, name, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, priority, lifetime); + asprintf(&fileName, NAMEFORMAT, VideoDirectory, name, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, priority, lifetime); if (fileName) strreplace(fileName, ' ', '_'); } @@ -262,7 +262,7 @@ bool cRecordings::Load(bool Deleted) Clear(); bool result = false; char *cmd = NULL; - asprintf(&cmd, FINDCMD, BaseDir, Deleted ? "*" DELEXT : "*" RECEXT); + asprintf(&cmd, FINDCMD, VideoDirectory, Deleted ? "*" DELEXT : "*" RECEXT); FILE *p = popen(cmd, "r"); if (p) { char *s; diff --git a/recording.h b/recording.h index e501af82..ae17cd3c 100644 --- a/recording.h +++ b/recording.h @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: recording.h 1.7 2000/07/23 19:06:14 kls Exp $ + * $Id: recording.h 1.8 2000/07/28 12:48:06 kls Exp $ */ #ifndef __RECORDING_H @@ -14,6 +14,8 @@ #include "config.h" #include "tools.h" +extern const char *VideoDirectory; + void AssertFreeDiskSpace(void); class cRecording : public cListObject { @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.10 2000/07/23 13:16:54 kls Exp $ + * $Id: tools.c 1.11 2000/07/28 13:22:10 kls Exp $ */ #define _GNU_SOURCE @@ -145,6 +145,24 @@ bool isnumber(const char *s) return true; } +bool DirectoryOk(const char *DirName) +{ + struct stat ds; + if (stat(DirName, &ds) == 0) { + if (S_ISDIR(ds.st_mode)) { + if (access(DirName, R_OK | W_OK | X_OK) == 0) + return true; + else + esyslog(LOG_ERR, "ERROR: can't access %s", DirName); + } + else + esyslog(LOG_ERR, "ERROR: %s is not a directory", DirName); + } + else + LOG_ERROR_STR(DirName); + return false; +} + bool MakeDirs(const char *FileName, bool IsDirectory) { bool result = true; @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.h 1.10 2000/07/23 13:16:37 kls Exp $ + * $Id: tools.h 1.11 2000/07/28 13:02:05 kls Exp $ */ #ifndef __TOOLS_H @@ -43,6 +43,7 @@ char *skipspace(char *s); int time_ms(void); void delay_ms(int ms); bool isnumber(const char *s); +bool DirectoryOk(const char *DirName); bool MakeDirs(const char *FileName, bool IsDirectory = false); bool RemoveFileOrDir(const char *FileName); bool CheckProcess(pid_t pid); @@ -22,7 +22,7 @@ * * The project's page is at http://www.cadsoft.de/people/kls/vdr * - * $Id: vdr.c 1.23 2000/07/23 15:36:43 kls Exp $ + * $Id: vdr.c 1.24 2000/07/28 13:14:19 kls Exp $ */ #include <getopt.h> @@ -65,20 +65,24 @@ int main(int argc, char *argv[]) { "daemon", no_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, { "port", required_argument, NULL, 'p' }, + { "video", required_argument, NULL, 'v' }, { 0 } }; int c; int option_index = 0; - while ((c = getopt_long(argc, argv, "dhp:", long_options, &option_index)) != -1) { + while ((c = getopt_long(argc, argv, "dhp:v:", long_options, &option_index)) != -1) { switch (c) { case 'd': DaemonMode = true; break; case 'h': printf("Usage: vdr [OPTION]\n\n" " -h, --help display this help and exit\n" " -d, --daemon run in daemon mode\n" - " -p PORT, --port=PORT use PORT for SVDRP ('0' turns off SVDRP)\n" + " -p PORT, --port=PORT use PORT for SVDRP (default: %d, '0' turns off SVDRP)\n" + " -v DIR, --video=DIR use DIR as video directory (default is %s)\n" "\n" - "Report bugs to <vdr-bugs@cadsoft.de>\n" + "Report bugs to <vdr-bugs@cadsoft.de>\n", + DEFAULTSVDRPPORT, + VideoDirectory ); return 0; break; @@ -86,9 +90,11 @@ int main(int argc, char *argv[]) SVDRPport = strtol(optarg, NULL, 10); else { fprintf(stderr, "vdr: invalid port number: %s\n", optarg); - return 1; + abort(); } break; + case 'v': VideoDirectory = optarg; + break; default: abort(); } } @@ -97,6 +103,13 @@ int main(int argc, char *argv[]) openlog("vdr", LOG_PID | LOG_CONS, LOG_USER); + // Check the video directory: + + if (!DirectoryOk(VideoDirectory)) { + fprintf(stderr, "vdr: can't access video directory %s\n", VideoDirectory); + abort(); + } + // Daemon mode: if (DaemonMode) { @@ -105,7 +118,7 @@ int main(int argc, char *argv[]) if (pid < 0) { fprintf(stderr, "%s\n", strerror(errno)); esyslog(LOG_ERR, strerror(errno)); - return 1; + abort(); } if (pid != 0) return 0; // initial program immediately returns @@ -122,7 +135,7 @@ int main(int argc, char *argv[]) // DVB interfaces: if (!cDvbApi::Init()) - return 1; + abort(); // Configuration data: |