1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Added command line option '-v'

This commit is contained in:
Klaus Schmidinger 2000-07-28 13:44:31 +02:00
parent 7ac97639da
commit 92096e097a
6 changed files with 51 additions and 16 deletions

View File

@ -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 - 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!). cursor reaches the top or bottom of the menu (thanks to Heino Goldenstein!).
- Added missing '#include <sys/stat.h>' to recording.c. - Added missing '#include <sys/stat.h>' to recording.c.
- The video directory can now be defined with the command line option -v.

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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 #define _GNU_SOURCE
@ -32,14 +32,14 @@
#define DISKCHECKDELTA 300 // seconds between checks for free disk space #define DISKCHECKDELTA 300 // seconds between checks for free disk space
const char *BaseDir = "/video"; const char *VideoDirectory = "/video";
static bool LowDiskSpace(void) static bool LowDiskSpace(void)
{ {
//TODO Find a simpler way to determine the amount of free disk space! //TODO Find a simpler way to determine the amount of free disk space!
bool result = true; bool result = true;
char *cmd = NULL; char *cmd = NULL;
asprintf(&cmd, DFCMD, BaseDir); asprintf(&cmd, DFCMD, VideoDirectory);
FILE *p = popen(cmd, "r"); FILE *p = popen(cmd, "r");
if (p) { if (p) {
char *s; char *s;
@ -124,7 +124,7 @@ cRecording::cRecording(const char *FileName)
{ {
titleBuffer = NULL; titleBuffer = NULL;
fileName = strdup(FileName); fileName = strdup(FileName);
FileName += strlen(BaseDir) + 1; FileName += strlen(VideoDirectory) + 1;
char *p = strrchr(FileName, '/'); char *p = strrchr(FileName, '/');
name = NULL; name = NULL;
@ -190,7 +190,7 @@ const char *cRecording::FileName(void)
{ {
if (!fileName) { if (!fileName) {
struct tm *t = localtime(&start); 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) if (fileName)
strreplace(fileName, ' ', '_'); strreplace(fileName, ' ', '_');
} }
@ -262,7 +262,7 @@ bool cRecordings::Load(bool Deleted)
Clear(); Clear();
bool result = false; bool result = false;
char *cmd = NULL; char *cmd = NULL;
asprintf(&cmd, FINDCMD, BaseDir, Deleted ? "*" DELEXT : "*" RECEXT); asprintf(&cmd, FINDCMD, VideoDirectory, Deleted ? "*" DELEXT : "*" RECEXT);
FILE *p = popen(cmd, "r"); FILE *p = popen(cmd, "r");
if (p) { if (p) {
char *s; char *s;

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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 #ifndef __RECORDING_H
@ -14,6 +14,8 @@
#include "config.h" #include "config.h"
#include "tools.h" #include "tools.h"
extern const char *VideoDirectory;
void AssertFreeDiskSpace(void); void AssertFreeDiskSpace(void);
class cRecording : public cListObject { class cRecording : public cListObject {

20
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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 #define _GNU_SOURCE
@ -145,6 +145,24 @@ bool isnumber(const char *s)
return true; 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 MakeDirs(const char *FileName, bool IsDirectory)
{ {
bool result = true; bool result = true;

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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 #ifndef __TOOLS_H
@ -43,6 +43,7 @@ char *skipspace(char *s);
int time_ms(void); int time_ms(void);
void delay_ms(int ms); void delay_ms(int ms);
bool isnumber(const char *s); bool isnumber(const char *s);
bool DirectoryOk(const char *DirName);
bool MakeDirs(const char *FileName, bool IsDirectory = false); bool MakeDirs(const char *FileName, bool IsDirectory = false);
bool RemoveFileOrDir(const char *FileName); bool RemoveFileOrDir(const char *FileName);
bool CheckProcess(pid_t pid); bool CheckProcess(pid_t pid);

27
vdr.c
View File

@ -22,7 +22,7 @@
* *
* The project's page is at http://www.cadsoft.de/people/kls/vdr * 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> #include <getopt.h>
@ -65,20 +65,24 @@ int main(int argc, char *argv[])
{ "daemon", no_argument, NULL, 'd' }, { "daemon", no_argument, NULL, 'd' },
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ "port", required_argument, NULL, 'p' }, { "port", required_argument, NULL, 'p' },
{ "video", required_argument, NULL, 'v' },
{ 0 } { 0 }
}; };
int c; int c;
int option_index = 0; 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) { switch (c) {
case 'd': DaemonMode = true; break; case 'd': DaemonMode = true; break;
case 'h': printf("Usage: vdr [OPTION]\n\n" case 'h': printf("Usage: vdr [OPTION]\n\n"
" -h, --help display this help and exit\n" " -h, --help display this help and exit\n"
" -d, --daemon run in daemon mode\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" "\n"
"Report bugs to <vdr-bugs@cadsoft.de>\n" "Report bugs to <vdr-bugs@cadsoft.de>\n",
DEFAULTSVDRPPORT,
VideoDirectory
); );
return 0; return 0;
break; break;
@ -86,9 +90,11 @@ int main(int argc, char *argv[])
SVDRPport = strtol(optarg, NULL, 10); SVDRPport = strtol(optarg, NULL, 10);
else { else {
fprintf(stderr, "vdr: invalid port number: %s\n", optarg); fprintf(stderr, "vdr: invalid port number: %s\n", optarg);
return 1; abort();
} }
break; break;
case 'v': VideoDirectory = optarg;
break;
default: abort(); default: abort();
} }
} }
@ -97,6 +103,13 @@ int main(int argc, char *argv[])
openlog("vdr", LOG_PID | LOG_CONS, LOG_USER); 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: // Daemon mode:
if (DaemonMode) { if (DaemonMode) {
@ -105,7 +118,7 @@ int main(int argc, char *argv[])
if (pid < 0) { if (pid < 0) {
fprintf(stderr, "%s\n", strerror(errno)); fprintf(stderr, "%s\n", strerror(errno));
esyslog(LOG_ERR, strerror(errno)); esyslog(LOG_ERR, strerror(errno));
return 1; abort();
} }
if (pid != 0) if (pid != 0)
return 0; // initial program immediately returns return 0; // initial program immediately returns
@ -122,7 +135,7 @@ int main(int argc, char *argv[])
// DVB interfaces: // DVB interfaces:
if (!cDvbApi::Init()) if (!cDvbApi::Init())
return 1; abort();
// Configuration data: // Configuration data: