Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
idnode: add idnode_save_check mechanism to save queued entry on removal
  • Loading branch information
perexg committed Feb 10, 2016
1 parent bd55aeb commit 8097f96
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/access.c
Expand Up @@ -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));

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/bouquet.c
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/channels.c
Expand Up @@ -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));

Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/descrambler/caclient.c
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/dvr/dvr_autorec.c
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/dvr/dvr_config.c
Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions src/dvr/dvr_db.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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));

Expand Down
2 changes: 2 additions & 0 deletions src/dvr/dvr_timerec.c
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/epggrab.c
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/epggrab/channel.c
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/esfilter.c
Expand Up @@ -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);
Expand Down
29 changes: 24 additions & 5 deletions src/idnode.c
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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 )
{
Expand Down
1 change: 1 addition & 0 deletions src/idnode.h
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/input/mpegts/linuxdvb/linuxdvb_adapter.c
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/input/mpegts/linuxdvb/linuxdvb_satconf.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/input/mpegts/mpegts_input.c
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/input/mpegts/mpegts_mux.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/input/mpegts/satip/satip.c
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/input/mpegts/satip/satip_satconf.c
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/input/mpegts/tvhdhomerun/tvhdhomerun.c
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/profile.c
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/service.c
Expand Up @@ -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);

Expand Down

0 comments on commit 8097f96

Please sign in to comment.