diff --git a/dvdplugin.c b/dvdplugin.c index 4412e0a..0579238 100644 --- a/dvdplugin.c +++ b/dvdplugin.c @@ -1,4 +1,4 @@ -#include + #include #include #include @@ -62,63 +62,68 @@ cDVDPluginThread *cDVDPlugin::thread = NULL; void cDVDPlugin::DetectDevice(void) { - dsyslog("dvdswitch: Scan for DVD Device"); - char *cmd = NULL; - char *output = NULL; + dsyslog("dvdswitch: parse cmdline of dvd-plugin for DVD Device"); + char *file = NULL; char *dvd = NULL; - if(0 < asprintf(&cmd, "ps -p %i -o cmd --no-header", getpid())) { - dsyslog("dvdswitch: Command: %s", cmd); - - FILE *p = popen(cmd, "r"); - if(p) - { - #if VDRVERSNUM >= 10318 - cReadLine rl; - output = rl.Read(p); - #else - output = readline(p); - #endif - pclose(p); + if(0 < asprintf(&file, "/proc/%i/cmdline", getpid())) { + /* read /proc/`pidof vdr`/cmdline */ + char buffer[1024]; + int len = -1; + + int fd = open(file,O_RDONLY); + if (fd >= 0) { + do { + len = read(fd,buffer,sizeof(buffer)); } + while (len == -1 && errno == EINTR); + close(fd); + } else { + char* szErr = get_strerror(errno); + esyslog("dvdswitch: could not open %s:%s", file, szErr ? szErr : ""); + if(szErr) free(szErr); } - - cTokenizer *token = new cTokenizer(output, " "); - for(int i = 1; i <= token->Count(); i++) - { - if(RegIMatch(token->GetToken(i), "^--plugin=dvd") || - (RegIMatch(token->GetToken(i - 1), "^-P$") && - RegIMatch(token->GetToken(i), "^dvd$"))) - { - if(RegIMatch(token->GetToken(i + 1), "^-C$") && - token->GetToken(i + 2)) - { - dvd = strdup(token->GetToken(i + 2)); - break; - } - if(RegIMatch(token->GetToken(i + 1), "^--dvd=")) - { - const char *p = strchr(token->GetToken(i + 1), '='); - p++; - dvd = strdup(p); - break; + free(file); + + if (len < 0) { + char* szErr = get_strerror(errno); + esyslog("dvdswitch: could not read %s:%s", file, szErr ? szErr : ""); + if(szErr) free(szErr); + } else { + char *output = NULL; + for(int n = 0; n < len && !dvd;n += (strlen(output) + 1)) { + output = buffer + n; + //dsyslog("dvdswitch: parse '%s'", output); + if(0 == strncmp(output, "--plugin=dvd ",13) + || 0 == strncmp(output, "-Pdvd ",6) + || 0 == strncmp(output, "-P dvd ",7) + || 0 == strncmp(output, "-P'dvd ",7) + || 0 == strncmp(output, "-P\"dvd ",7)) { + + cTokenizer *token = new cTokenizer(output, " "); + for(int i = 0; i <= token->Count(); i++) { + if(RegIMatch(token->GetToken(i), "^-C$") && + token->GetToken(i + 1)) { + dvd = strdup(token->GetToken(i + 1)); + break; + } + if(RegIMatch(token->GetToken(i), "^--dvd=")) { + const char *p = strchr(token->GetToken(i), '='); + dvd = strdup(p + 1); + break; + } + } + DELETENULL(token); } } } - DELETENULL(token); - - if(dvd) - { - isyslog("dvdswitch: Used DVD Device: %s", dvd); + if(!dvd) { + dvd = strdup("/dev/dvd"); + } + if(dvd) { + isyslog("dvdswitch: use DVD Device: %s", dvd); DVDSwitchSetup.SetDVDDevice(dvd); free(dvd); } - else - { - isyslog("dvdswitch: Use Default-DVD Device /dev/dvd"); - DVDSwitchSetup.SetDVDDevice("/dev/dvd"); - } - - free(cmd); } } @@ -163,14 +168,17 @@ void cDVDPlugin::ChangeLink(char *target) { if(target) { - char *cmd = NULL; - int rc = 0; - - if(0 < asprintf(&cmd, LINK, target, DVDSwitchSetup.DVDLink)) { - dsyslog("dvdswitch: Change link: %s", cmd); - rc = system(cmd); - dsyslog("dvdswitch: Change link got: %i", rc); - free(cmd); + isyslog("dvdswitch: create link %s to %s", DVDSwitchSetup.DVDLink, target); + + if(-1 == unlink(DVDSwitchSetup.DVDLink) && errno != ENOENT) { + char* szErr = get_strerror(errno); + esyslog("dvdswitch: could not remove symbolic link %s : %s (%d)", DVDSwitchSetup.DVDLink, szErr ? szErr : "", errno); + if(szErr) free(szErr); + } + if(-1 == symlink(target, DVDSwitchSetup.DVDLink)) { + char* szErr = get_strerror(errno); + esyslog("dvdswitch: could not create link %s to %s :%s (%d)", DVDSwitchSetup.DVDLink, target, szErr ? szErr : "", errno); + if(szErr) free(szErr); } } } diff --git a/dvdplugin.h b/dvdplugin.h index 6591370..e7ff69f 100644 --- a/dvdplugin.h +++ b/dvdplugin.h @@ -5,8 +5,6 @@ #include "helpers.h" #include "setup.h" -#define LINK "ln -nfs '%s' '%s' 2> /dev/null" - class cDVDPluginThread : public cThread { private: diff --git a/dvdswitch.c b/dvdswitch.c index 7afa524..f99ad53 100644 --- a/dvdswitch.c +++ b/dvdswitch.c @@ -19,9 +19,7 @@ #error "VDR-1.6.0 API version or greater is required!" #endif -static const char *VERSION = "0.1.6"; -static const char *DESCRIPTION = tr("Allowed to play DVD-Images"); -//static const char *MAINMENUENTRY = tr("DVDSwitch"); +static const char *VERSION = "0.1.7"; class cPluginDvdswitch : public cPlugin { private: @@ -33,7 +31,7 @@ class cPluginDvdswitch : public cPlugin { cPluginDvdswitch(void); virtual ~cPluginDvdswitch(); virtual const char *Version(void) { return VERSION; } - virtual const char *Description(void) { return tr(DESCRIPTION); } + virtual const char *Description(void) { return tr("Allows playback of DVD images"); } virtual const char *CommandLineHelp(void); virtual bool ProcessArgs(int argc, char *argv[]); virtual bool Initialize(void); diff --git a/helpers.c b/helpers.c index 729a173..e366e17 100644 --- a/helpers.c +++ b/helpers.c @@ -23,27 +23,23 @@ void OsdMsg(eMessageType Type, const char *Msg) #endif } -void OSDErrorNumMsg(int err, const char* szDef) -{ - char szErr[128]; - int nErr = err; - szErr[sizeof(szErr)-1] = '\0'; - if(0 != strerror_r(nErr,szErr,sizeof(szErr)-1)) { - szErr[0] = '\0'; - } - esyslog(szErr[0] != '\0'?szErr:szDef); - OsdMsg(mtError, szErr[0] != '\0'?szErr:szDef); -} +char *get_strerror(int n) +{ + char *s; + size_t size = 128; + s = (char*)malloc(size); + if (s == NULL) + return NULL; + strerror_r(n, s, size); + return s; +} -void SysLogErrorNumMsg(int err, const char* szDef) +void OSDErrorNumMsg(int err, const char* szDef) { - char szErr[128]; - int nErr = err; - szErr[sizeof(szErr)-1] = '\0'; - if(0 != strerror_r(nErr,szErr,sizeof(szErr)-1)) { - szErr[0] = '\0'; - } - esyslog(szErr[0] != '\0'?szErr:szDef); + char* szErr = get_strerror(err); + esyslog("dvdswitch: %s :%s", szDef, szErr ? szErr : ""); + OsdMsg(mtError, szErr ? szErr : szDef); + if(szErr) free(szErr); } void ChangeChars(char *name, char *chars) diff --git a/helpers.h b/helpers.h index 4013dfc..ef7410a 100644 --- a/helpers.h +++ b/helpers.h @@ -17,10 +17,10 @@ void OsdMsg(eMessageType Type, const char *Msg); void OSDErrorNumMsg(int err, const char* szDef); -void SysLogErrorNumMsg(int err, const char* szDef); void ChangeChars(char *name, char *chars); void StrRepeat(const char *input, int count, char *dest); bool RegIMatch(const char *string,const char *pattern); +char *get_strerror(int n); // --- cStringValue ------------------------------------- diff --git a/po/de_DE.po b/po/de_DE.po index 00c33d9..bdfe6de 100644 --- a/po/de_DE.po +++ b/po/de_DE.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: vdr-dvdswitch-plugin 0.1.6\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-21 21:35+0100\n" +"POT-Creation-Date: 2010-12-23 20:45+0100\n" "PO-Revision-Date: 2009-10-03 14:03+0200\n" "Last-Translator:\n" "Language-Team: \n" @@ -140,7 +140,7 @@ msgstr "Es wurde kein Verzeichnis ausgew msgid "Now Read?" msgstr "Jetzt einlesen?" -msgid "Allowed to play DVD-Images" +msgid "Allows playback of DVD images" msgstr "Erlaubt das Abspielen von DVD-Abbildern" msgid "Image Directory not readable or not exist" diff --git a/po/fr_FR.po b/po/fr_FR.po index adde8dd..429c776 100644 --- a/po/fr_FR.po +++ b/po/fr_FR.po @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: vdr-dvdswitch-plugin 0.1.6\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-12-21 21:35+0100\n" +"POT-Creation-Date: 2010-12-23 20:45+0100\n" "PO-Revision-Date: 2010-12-21 12:59+0100\n" "Last-Translator: Nicolas Huillard \n" "Language-Team: \n" @@ -149,7 +149,7 @@ msgstr "Aucun dossier n'est choisi. Utiliser le standard?" msgid "Now Read?" msgstr "Lire maintenant?" -msgid "Allowed to play DVD-Images" +msgid "Allows playback of DVD images" msgstr "" msgid "Image Directory not readable or not exist" diff --git a/tools.c b/tools.c index 4334ab2..59f7df9 100644 --- a/tools.c +++ b/tools.c @@ -72,8 +72,11 @@ void cFileDelThread::Action(void) if(File) { dsyslog("dvdswitch: Execute remove %s",File); errno = 0; - if(!cFileCMD::Del(File)) - SysLogErrorNumMsg(errno,"Operation file remove failed"); + if(!cFileCMD::Del(File)) { + char* err = get_strerror(errno); + esyslog("dvdswitch: could not remove failed %s :%s", File, err ? err : ""); + if(err) free(err); + } } delete(this); }; @@ -134,8 +137,11 @@ void cFileMoveThread::Action(void) if(0 < asprintf(&buffer, "%s/%s", Dest, FileName)) { dsyslog("dvdswitch: Execute move %s to %s",File, buffer); errno = 0; - if(!cFileCMD::Rn(File, buffer)) - SysLogErrorNumMsg(errno,"Operation file remove failed"); + if(!cFileCMD::Rn(File, buffer)) { + char* err = get_strerror(errno); + esyslog("dvdswitch: could not move file failed %s to %s :%s", File, buffer, err ? err : ""); + if(err) free(err); + } free(buffer); } }