time_t t;
struct tm tm;
char tbuf[64];
+ int r;
t = dvr_entry_get_start_time(de);
localtime_r(&t, &tm);
#if ENABLE_INOTIFY
dvr_inotify_del(de);
#endif
- if(unlink(de->de_filename) && errno != ENOENT)
+ r = deferred_unlink(de->de_filename);
+ if(r && r != -ENOENT)
tvhlog(LOG_WARNING, "dvr", "Unable to remove file '%s' from disk -- %s",
- de->de_filename, strerror(errno));
+ de->de_filename, strerror(-errno));
/* Also delete directories, if they were created for the recording and if they are empty */
}
}
+/**
+ *
+ */
+tasklet_t *
+tasklet_arm_alloc(tsk_callback_t *callback, void *opaque)
+{
+ tasklet_t *tsk = calloc(1, sizeof(*tsk));
+ if (tsk) {
+ tsk->tsk_allocated = 1;
+ tasklet_arm(tsk, callback, opaque);
+ }
+ return tsk;
+}
+
/**
*
*/
TAILQ_REMOVE(&tasklets, tsk, tsk_link);
tsk->tsk_callback(tsk->tsk_opaque, 1);
tsk->tsk_callback = NULL;
+ if (tsk->tsk_allocated)
+ free(tsk);
}
pthread_mutex_unlock(&tasklet_lock);
TAILQ_REMOVE(&tasklets, tsk, tsk_link);
tsk->tsk_callback(tsk->tsk_opaque, 1);
tsk->tsk_callback = NULL;
+ if (tsk->tsk_allocated)
+ free(tsk);
}
pthread_mutex_unlock(&tasklet_lock);
pthread_mutex_init(&atomic_lock, NULL);
pthread_cond_init(>imer_cond, NULL);
pthread_cond_init(&tasklet_cond, NULL);
+ TAILQ_INIT(&tasklets);
/* Defaults */
tvheadend_webui_port = 9981;
tvhftrace("main", spawn_done);
tvhtrace("main", "tasklet enter");
+ pthread_cond_signal(&tasklet_cond);
pthread_join(tasklet_tid, NULL);
tvhtrace("main", "tasklet thread end");
tasklet_flush();
TAILQ_ENTRY(tasklet) tsk_link;
tsk_callback_t *tsk_callback;
void *tsk_opaque;
+ int tsk_allocated;
} tasklet_t;
+tasklet_t *tasklet_arm_alloc(tsk_callback_t *callback, void *opaque);
void tasklet_arm(tasklet_t *tsk, tsk_callback_t *callback, void *opaque);
void tasklet_disarm(tasklet_t *gti);
int mpegts_word_count(const uint8_t *tsb, int len, uint32_t mask);
+int deferred_unlink(const char *filename);
+
static inline int32_t deltaI32(int32_t a, int32_t b) { return (a > b) ? (a - b) : (b - a); }
static inline uint32_t deltaU32(uint32_t a, uint32_t b) { return (a > b) ? (a - b) : (b - a); }
return r;
}
+
+static void
+deferred_unlink_cb(void *s, int dearmed)
+{
+ if (unlink((const char *)s))
+ tvherror("main", "unable to remove file '%s'", (const char *)s);
+ free(s);
+}
+
+int
+deferred_unlink(const char *filename)
+{
+ char *s;
+ size_t l;
+ int r;
+
+ l = strlen(filename);
+ s = malloc(l + 9);
+ if (s == NULL)
+ return -ENOMEM;
+ strcpy(s, filename);
+ strcpy(s + l, ".removing");
+ r = rename(filename, s);
+ if (r) {
+ r = -errno;
+ free(s);
+ return r;
+ }
+ tasklet_arm_alloc(deferred_unlink_cb, s);
+ return 0;
+}