summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <kls (at) cadsoft (dot) de>2001-10-21 18:00:00 +0200
committerKlaus Schmidinger <kls (at) cadsoft (dot) de>2001-10-21 18:00:00 +0200
commit8465398c6d2a57bc30a07fb61353a7c8ba6db574 (patch)
treef2e14e51ab0a43ebd3c148376c5be73f4bd1434d /tools.c
parent66bab90b60048a46e401ea506d3aa65c43779700 (diff)
downloadvdr-patch-lnbsharing-8465398c6d2a57bc30a07fb61353a7c8ba6db574.tar.gz
vdr-patch-lnbsharing-8465398c6d2a57bc30a07fb61353a7c8ba6db574.tar.bz2
Version 0.97vdr-0.97
- Implemented a lock file to prevent more than one instance of VDR from removing files from the video directory at the same time. - The new setup parameter SplitEditedFiles can be used to control whether or not the result of an editing process shall be written into separate files. - Fixed handling repeat function when using LIRC (thanks to Matthias Weingart). - The shutdown program (defined with the '-s' option) now also gets the channel number and recording title of the timer (see INSTALL). - New channel data for 'Premiere One', 'Premiere X-Action', 'Fox Kids Türkce' and 'N24' (thanks to Andreas Share, Ulrich Röder, Uwe Scheffler and Simon Bauschulte). Note that if you are using the default 'channels.conf' or 'channels.conf.cable' files you may need to check any exiting timers to see whether they still use the correct channel number. - Fixed the "EPG bugfix" (sometimes had duplicate information in Subtitle and Extended Description). - Fixed checking for valid video device when setting the video mode. - The external command 'sort' is no longer required. VDR now sorts the list of recordings itself, making sure that recordings that stem from repeating timers are sorted chronologically. Sorting is done according to the setting of the current locale, so you may want to make sure LC_COLLATE is set to the desired value (see INSTALL). - Fixed handling 'newline' characters in EPG texts (thanks to Rolf Hakenes for an improved version of his 'libdtv'). Newline characters are always mapped to a single "blank" in VDR, because they would otherwise disturb the Title and Subtitle layout in the channel display (where these are assumed to be single line texts) and would have to be specially handled in the 'epg.data' file and the LSTE command in SVDRP. - Mapping ` ("backtick") characters in EPG texts to ' (single quote). - Fixed timers starting and ending at unexpected times. 'localtime()' was not thread safe, now using localtime_r(). - Removed the "system time seen..." message. - Fixed a bug in the replay mode display when pressing the Green or Yellow button while in trick mode (thanks to Stefan Huelswitt) - Closing all open file descriptors when calling external programs. - The menu timeout now also works when pressing the "Back" button during replay to enter the "Recordings" menu. - Updated 'channels.conf' for the "Bundesliga" channels of Premiere World (thanks to Helmut Schächner). - Fixed reading timers.conf and channels.conf that contain blanks after numeric values. - Fixed handling trick modes near the beginning and end of a recording. - Pressing the "Back" button while replaying a DVD now leads to the DVD menu.
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c76
1 files changed, 73 insertions, 3 deletions
diff --git a/tools.c b/tools.c
index 7238137..472c50d 100644
--- a/tools.c
+++ b/tools.c
@@ -4,10 +4,9 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.c 1.46 2001/09/22 12:13:40 kls Exp $
+ * $Id: tools.c 1.50 2001/10/19 13:12:45 kls Exp $
*/
-#define _GNU_SOURCE
#include "tools.h"
#include <ctype.h>
#include <dirent.h>
@@ -74,6 +73,10 @@ char *strcpyrealloc(char *dest, const char *src)
else
esyslog(LOG_ERR, "ERROR: out of memory");
}
+ else {
+ delete dest;
+ dest = NULL;
+ }
return dest;
}
@@ -413,7 +416,8 @@ const char *DayDateTime(time_t t)
static char buffer[32];
if (t == 0)
time(&t);
- tm *tm = localtime(&t);
+ struct tm tm_r;
+ tm *tm = localtime_r(&t, &tm_r);
int weekday = tm->tm_wday == 0 ? 6 : tm->tm_wday - 1; // we start with monday==0!
const char *day = tr("MonTueWedThuFriSatSun");
day += weekday * 3;
@@ -590,6 +594,72 @@ bool cSafeFile::Close(void)
return result;
}
+// --- cLockFile -------------------------------------------------------------
+
+#define LOCKFILENAME ".lock-vdr"
+#define LOCKFILESTALETIME 600 // seconds before considering a lock file "stale"
+
+cLockFile::cLockFile(const char *Directory)
+{
+ fileName = NULL;
+ f = -1;
+ if (DirectoryOk(Directory))
+ asprintf(&fileName, "%s/%s", Directory, LOCKFILENAME);
+}
+
+cLockFile::~cLockFile()
+{
+ Unlock();
+ delete fileName;
+}
+
+bool cLockFile::Lock(int WaitSeconds)
+{
+ if (f < 0 && fileName) {
+ time_t Timeout = time(NULL) + WaitSeconds;
+ do {
+ f = open(fileName, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (f < 0) {
+ if (errno == EEXIST) {
+ struct stat fs;
+ if (stat(fileName, &fs) == 0) {
+ if (time(NULL) - fs.st_mtime > LOCKFILESTALETIME) {
+ esyslog(LOG_ERR, "ERROR: removing stale lock file '%s'", fileName);
+ if (remove(fileName) < 0) {
+ LOG_ERROR_STR(fileName);
+ break;
+ }
+ continue;
+ }
+ }
+ else if (errno != ENOENT) {
+ LOG_ERROR_STR(fileName);
+ break;
+ }
+ }
+ else {
+ LOG_ERROR_STR(fileName);
+ break;
+ }
+ if (WaitSeconds)
+ sleep(1);
+ }
+ } while (f < 0 && time(NULL) < Timeout);
+ }
+ return f >= 0;
+}
+
+void cLockFile::Unlock(void)
+{
+ if (f >= 0) {
+ close(f);
+ remove(fileName);
+ f = -1;
+ }
+ else
+ esyslog(LOG_ERR, "ERROR: attempt to unlock %s without holding a lock!", fileName);
+}
+
// --- cListObject -----------------------------------------------------------
cListObject::cListObject(void)