From: Jaroslav Kysela Date: Wed, 10 Feb 2016 17:01:01 +0000 (+0100) Subject: idnode: add idnode_save_check mechanism to save queued entry on removal X-Git-Tag: v4.2.1~1038 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8097f96d524c0064688ca28ee54d79f861c09bdd;p=thirdparty%2Ftvheadend.git idnode: add idnode_save_check mechanism to save queued entry on removal --- diff --git a/src/access.c b/src/access.c index b11886f6a..1bf6e4d75 100644 --- a/src/access.c +++ b/src/access.c @@ -1093,6 +1093,8 @@ access_entry_destroy(access_entry_t *ae, int delconf) access_ipmask_t *ai; char ubuf[UUID_HEX_SIZE]; + idnode_save_check(&ae->ae_id, delconf); + if (delconf) hts_settings_remove("accesscontrol/%s", idnode_uuid_as_str(&ae->ae_id, ubuf)); @@ -1759,6 +1761,8 @@ passwd_entry_destroy(passwd_entry_t *pw, int delconf) if (pw == NULL) return; + idnode_save_check(&pw->pw_id, delconf); + if (delconf) hts_settings_remove("passwd/%s", idnode_uuid_as_str(&pw->pw_id, ubuf)); TAILQ_REMOVE(&passwd_entries, pw, pw_link); @@ -1931,10 +1935,11 @@ ipblock_entry_create(const char *uuid, htsmsg_t *conf) } static void -ipblock_entry_destroy(ipblock_entry_t *ib) +ipblock_entry_destroy(ipblock_entry_t *ib, int delconf) { if (ib == NULL) return; + idnode_save_check(&ib->ib_id, delconf); TAILQ_REMOVE(&ipblock_entries, ib, ib_link); idnode_unlink(&ib->ib_id); free(ib->ib_comment); @@ -1969,7 +1974,7 @@ ipblock_entry_class_delete(idnode_t *self) char ubuf[UUID_HEX_SIZE]; hts_settings_remove("ipblock/%s", idnode_uuid_as_str(&ib->ib_id, ubuf)); - ipblock_entry_destroy(ib); + ipblock_entry_destroy(ib, 1); } static int @@ -2127,7 +2132,7 @@ access_done(void) while ((pw = TAILQ_FIRST(&passwd_entries)) != NULL) passwd_entry_destroy(pw, 0); while ((ib = TAILQ_FIRST(&ipblock_entries)) != NULL) - ipblock_entry_destroy(ib); + ipblock_entry_destroy(ib, 0); free((void *)superuser_username); superuser_username = NULL; free((void *)superuser_password); diff --git a/src/bouquet.c b/src/bouquet.c index a628f2180..88ed93abc 100644 --- a/src/bouquet.c +++ b/src/bouquet.c @@ -132,6 +132,7 @@ bouquet_destroy(bouquet_t *bq) return; RB_REMOVE(&bouquets, bq, bq_link); + idnode_save_check(&bq->bq_id, 1); idnode_unlink(&bq->bq_id); if ((bqd = bq->bq_download) != NULL) { diff --git a/src/channels.c b/src/channels.c index 59d649ed0..bd0e783a9 100644 --- a/src/channels.c +++ b/src/channels.c @@ -1012,6 +1012,8 @@ channel_delete ( channel_t *ch, int delconf ) lock_assert(&global_lock); + idnode_save_check(&ch->ch_id, delconf); + if (delconf) tvhinfo("channel", "%s - deleting", channel_get_name(ch)); @@ -1227,6 +1229,8 @@ channel_tag_destroy(channel_tag_t *ct, int delconf) idnode_list_mapping_t *ilm; char ubuf[UUID_HEX_SIZE]; + idnode_save_check(&ct->ct_id, delconf); + while((ilm = LIST_FIRST(&ct->ct_ctms)) != NULL) channel_tag_mapping_destroy(ilm, delconf ? ilm->ilm_in1 : NULL); diff --git a/src/descrambler/caclient.c b/src/descrambler/caclient.c index 83e2ed11b..32f506cb6 100644 --- a/src/descrambler/caclient.c +++ b/src/descrambler/caclient.c @@ -137,6 +137,7 @@ caclient_delete(caclient_t *cac, int delconf) { char ubuf[UUID_HEX_SIZE]; + idnode_save_check(&cac->cac_id, delconf); cac->cac_enabled = 0; cac->cac_conf_changed(cac); if (delconf) diff --git a/src/dvr/dvr_autorec.c b/src/dvr/dvr_autorec.c index bb08edf28..e8b791db6 100644 --- a/src/dvr/dvr_autorec.c +++ b/src/dvr/dvr_autorec.c @@ -364,6 +364,8 @@ autorec_entry_destroy(dvr_autorec_entry_t *dae, int delconf) { char ubuf[UUID_HEX_SIZE]; + idnode_save_check(&dae->dae_id, delconf); + dvr_autorec_purge_spawns(dae, delconf, 0); if (delconf) diff --git a/src/dvr/dvr_config.c b/src/dvr/dvr_config.c index eff44d30c..1050439ca 100644 --- a/src/dvr/dvr_config.c +++ b/src/dvr/dvr_config.c @@ -236,6 +236,8 @@ dvr_config_destroy(dvr_config_t *cfg, int delconf) { char ubuf[UUID_HEX_SIZE]; + idnode_save_check(&cfg->dvr_id, delconf); + if (delconf) { tvhinfo("dvr", "Deleting configuration '%s'", cfg->dvr_config_name); hts_settings_remove("dvr/config/%s", idnode_uuid_as_str(&cfg->dvr_id, ubuf)); diff --git a/src/dvr/dvr_db.c b/src/dvr/dvr_db.c index ab1b9e1ab..8139b929b 100644 --- a/src/dvr/dvr_db.c +++ b/src/dvr/dvr_db.c @@ -1294,6 +1294,8 @@ dvr_entry_dec_ref(dvr_entry_t *de) return; } + idnode_save_check(&de->de_id, 1); + idnode_unlink(&de->de_id); if(de->de_autorec != NULL) @@ -1330,6 +1332,8 @@ dvr_entry_destroy(dvr_entry_t *de, int delconf) { char ubuf[UUID_HEX_SIZE]; + idnode_save_check(&de->de_id, delconf); + if (delconf) hts_settings_remove("dvr/log/%s", idnode_uuid_as_str(&de->de_id, ubuf)); diff --git a/src/dvr/dvr_timerec.c b/src/dvr/dvr_timerec.c index 56fb64232..66a053456 100644 --- a/src/dvr/dvr_timerec.c +++ b/src/dvr/dvr_timerec.c @@ -232,6 +232,8 @@ timerec_entry_destroy(dvr_timerec_entry_t *dte, int delconf) { char ubuf[UUID_HEX_SIZE]; + idnode_save_check(&dte->dte_id, delconf); + dvr_timerec_purge_spawn(dte, delconf); if (delconf) diff --git a/src/epggrab.c b/src/epggrab.c index 8474c6b1b..c8ca9c010 100644 --- a/src/epggrab.c +++ b/src/epggrab.c @@ -437,6 +437,7 @@ void epggrab_done ( void ) pthread_mutex_lock(&global_lock); while ((mod = LIST_FIRST(&epggrab_modules)) != NULL) { + idnode_save_check(&mod->idnode, 1); idnode_unlink(&mod->idnode); LIST_REMOVE(mod, link); pthread_mutex_unlock(&global_lock); diff --git a/src/epggrab/channel.c b/src/epggrab/channel.c index 865773f9c..0123787e7 100644 --- a/src/epggrab/channel.c +++ b/src/epggrab/channel.c @@ -393,6 +393,8 @@ void epggrab_channel_destroy( epggrab_channel_t *ec, int delconf, int rb_remove if (ec == NULL) return; + idnode_save_check(&ec->idnode, delconf); + /* Already linked */ epggrab_channel_links_delete(ec, 0); if (rb_remove) diff --git a/src/esfilter.c b/src/esfilter.c index 6273781a1..2915dfe2a 100644 --- a/src/esfilter.c +++ b/src/esfilter.c @@ -194,6 +194,7 @@ esfilter_delete(esfilter_t *esf, int delconf) if (delconf) hts_settings_remove("esfilter/%s", idnode_uuid_as_str(&esf->esf_id, ubuf)); TAILQ_REMOVE(&esfilters[esf->esf_class], esf, esf_link); + idnode_save_check(&esf->esf_id, delconf); idnode_unlink(&esf->esf_id); free(esf->esf_comment); free(esf); diff --git a/src/idnode.c b/src/idnode.c index 972ab2f57..cf9b2f238 100644 --- a/src/idnode.c +++ b/src/idnode.c @@ -161,11 +161,7 @@ idnode_unlink(idnode_t *in) RB_REMOVE(in->in_domain, in, in_domain_link); tvhtrace("idnode", "unlink node %s", idnode_uuid_as_str(in, ubuf)); idnode_notify(in, "delete"); - - if (in->in_save) { - TAILQ_REMOVE(&idnodes_save, in->in_save, ise_link); - in->in_save = NULL; - } + assert(in->in_save == NULL); } /** @@ -1111,6 +1107,29 @@ idnode_save_queue ( idnode_t *self ) self->in_save = ise; } +void +idnode_save_check ( idnode_t *self, int weak ) +{ + char filename[PATH_MAX]; + htsmsg_t *m; + + if (self->in_save == NULL) + return; + + TAILQ_REMOVE(&idnodes_save, self->in_save, ise_link); + free(self->in_save); + self->in_save = NULL; + + if (weak) + return; + + m = idnode_savefn(self, filename, sizeof(filename)); + if (m) { + hts_settings_save(m, "%s", filename); + htsmsg_destroy(m); + } +} + int idnode_write0 ( idnode_t *self, htsmsg_t *c, int optmask, int dosave ) { diff --git a/src/idnode.h b/src/idnode.h index 8a032d852..0b77766af 100644 --- a/src/idnode.h +++ b/src/idnode.h @@ -212,6 +212,7 @@ htsmsg_t *idclass_serialize0 (const idclass_t *idc, htsmsg_t *list, int optmask, htsmsg_t *idnode_serialize0 (idnode_t *self, htsmsg_t *list, int optmask, const char *lang); void idnode_read0 (idnode_t *self, htsmsg_t *m, htsmsg_t *list, int optmask, const char *lang); int idnode_write0 (idnode_t *self, htsmsg_t *m, int optmask, int dosave); +void idnode_save_check (idnode_t *self, int weak); #define idclass_serialize(idc, lang) idclass_serialize0(idc, NULL, 0, lang) #define idnode_serialize(in, lang) idnode_serialize0(in, NULL, 0, lang) diff --git a/src/input/mpegts/linuxdvb/linuxdvb_adapter.c b/src/input/mpegts/linuxdvb/linuxdvb_adapter.c index 4988c55b9..bed5c7119 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_adapter.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_adapter.c @@ -498,6 +498,8 @@ linuxdvb_adapter_del ( const char *path ) break; } if (!th) return; + + idnode_save_check(&la->th_id, 1); /* Delete the frontends */ for (lfe = LIST_FIRST(&la->la_frontends); lfe != NULL; lfe = next) { diff --git a/src/input/mpegts/linuxdvb/linuxdvb_satconf.c b/src/input/mpegts/linuxdvb/linuxdvb_satconf.c index e72f82843..93b6278b3 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_satconf.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_satconf.c @@ -1396,6 +1396,7 @@ void linuxdvb_satconf_ele_destroy ( linuxdvb_satconf_ele_t *ls ) { TAILQ_REMOVE(&ls->lse_parent->ls_elements, ls, lse_link); + idnode_save_check(&ls->lse_id, 1); idnode_unlink(&ls->lse_id); if (ls->lse_lnb) linuxdvb_lnb_destroy(ls->lse_lnb); if (ls->lse_switch) linuxdvb_switch_destroy(ls->lse_switch); @@ -1461,6 +1462,7 @@ linuxdvb_satconf_delete ( linuxdvb_satconf_t *ls, int delconf ) nxt = TAILQ_NEXT(lse, lse_link); linuxdvb_satconf_ele_destroy(lse); } + idnode_save_check(&ls->ls_id, 1); idnode_unlink(&ls->ls_id); free(ls); } @@ -1518,6 +1520,7 @@ linuxdvb_diseqc_create0 void linuxdvb_diseqc_destroy ( linuxdvb_diseqc_t *ld ) { + idnode_save_check(&ld->ld_id, 1); idnode_unlink(&ld->ld_id); free((void *)ld->ld_type); } diff --git a/src/input/mpegts/mpegts_input.c b/src/input/mpegts/mpegts_input.c index c33c820a6..51c4cb950 100644 --- a/src/input/mpegts/mpegts_input.c +++ b/src/input/mpegts/mpegts_input.c @@ -1829,6 +1829,8 @@ mpegts_input_delete ( mpegts_input_t *mi, int delconf ) /* Early shutdown flag */ mi->mi_running = 0; + idnode_save_check(&mi->ti_id, delconf); + /* Remove networks */ while ((mnl = LIST_FIRST(&mi->mi_networks))) mpegts_input_del_network(mnl); diff --git a/src/input/mpegts/mpegts_mux.c b/src/input/mpegts/mpegts_mux.c index 44c66a6d9..bb44d7e9a 100644 --- a/src/input/mpegts/mpegts_mux.c +++ b/src/input/mpegts/mpegts_mux.c @@ -48,6 +48,7 @@ mpegts_mux_instance_delete { mpegts_mux_instance_t *mmi = (mpegts_mux_instance_t *)tii; + idnode_save_check(&tii->tii_id, 1); idnode_unlink(&tii->tii_id); LIST_REMOVE(mmi, mmi_mux_link); LIST_REMOVE(tii, tii_input_link); @@ -660,6 +661,8 @@ mpegts_mux_delete ( mpegts_mux_t *mm, int delconf ) th_subscription_t *ths; char buf[256]; + idnode_save_check(&mm->mm_id, delconf); + mpegts_mux_nice_name(mm, buf, sizeof(buf)); tvhinfo("mpegts", "%s (%p) - deleting", buf, mm); diff --git a/src/input/mpegts/satip/satip.c b/src/input/mpegts/satip/satip.c index bd32e8c41..af66fe424 100644 --- a/src/input/mpegts/satip/satip.c +++ b/src/input/mpegts/satip/satip.c @@ -721,6 +721,8 @@ satip_device_destroy( satip_device_t *sd ) gtimer_disarm(&sd->sd_destroy_timer); + idnode_save_check(&sd->th_id, 1); + while ((lfe = TAILQ_FIRST(&sd->sd_frontends)) != NULL) satip_frontend_delete(lfe); diff --git a/src/input/mpegts/satip/satip_satconf.c b/src/input/mpegts/satip/satip_satconf.c index ccc8e6acc..8ec90440a 100644 --- a/src/input/mpegts/satip/satip_satconf.c +++ b/src/input/mpegts/satip/satip_satconf.c @@ -307,6 +307,7 @@ satip_satconf_destroy0 { satip_frontend_t *lfe = sfc->sfc_lfe; TAILQ_REMOVE(&lfe->sf_satconf, sfc, sfc_link); + idnode_save_check(&sfc->sfc_id, 1); idnode_unlink(&sfc->sfc_id); idnode_set_free(sfc->sfc_networks); free(sfc->sfc_name); diff --git a/src/input/mpegts/tvhdhomerun/tvhdhomerun.c b/src/input/mpegts/tvhdhomerun/tvhdhomerun.c index b032c4af8..a52c03bbd 100644 --- a/src/input/mpegts/tvhdhomerun/tvhdhomerun.c +++ b/src/input/mpegts/tvhdhomerun/tvhdhomerun.c @@ -446,6 +446,8 @@ tvhdhomerun_device_destroy( tvhdhomerun_device_t *hd ) gtimer_disarm(&hd->hd_destroy_timer); + idnode_save_check(&hd->th_id, 1); + tvhlog(LOG_INFO, "tvhdhomerun", "Releasing locks for devices"); while ((lfe = TAILQ_FIRST(&hd->hd_frontends)) != NULL) { tvhdhomerun_frontend_delete(lfe); diff --git a/src/profile.c b/src/profile.c index 17982a1d5..afbcbc275 100644 --- a/src/profile.c +++ b/src/profile.c @@ -132,6 +132,7 @@ static void profile_delete(profile_t *pro, int delconf) { char ubuf[UUID_HEX_SIZE]; + idnode_save_check(&pro->pro_id, delconf); pro->pro_enabled = 0; if (pro->pro_conf_changed) pro->pro_conf_changed(pro); diff --git a/src/service.c b/src/service.c index 2c3f3d00e..a3ef64490 100644 --- a/src/service.c +++ b/src/service.c @@ -822,6 +822,8 @@ service_destroy(service_t *t, int delconf) lock_assert(&global_lock); + idnode_save_check(&t->s_id, delconf); + if(t->s_delete != NULL) t->s_delete(t, delconf);