int ret = mood_get_name_and_def_by_row(mood_row, &mood_name, &mood_def);
if (ret < 0) {
- para_printf(pb, "failed to get mood definition: %s\n",
- para_strerror(-ret));
+ para_printf(pb, "cannot read mood\n");
return ret;
}
if (!*mood_name) /* ignore dummy row */
goto out;
- ret = para_printf(pb, "checking mood %s...\n", mood_name);
- if (ret < 0)
- goto out;
+ para_printf(pb, "checking mood %s...\n", mood_name);
ret = for_each_line(FELF_READ_ONLY, mood_def.data, mood_def.size,
parse_mood_line, &mlpd);
if (ret < 0)
- para_printf(pb, "%s line %u: %s\n", mood_name, mlpd.line_num,
- para_strerror(-ret));
+ para_printf(pb, "mood %s: error in line %u: %s\n", mood_name,
+ mlpd.line_num, para_strerror(-ret));
+ ret = 1; /* don't fail the loop on invalid mood definitions */
out:
osl_close_disk_object(&mood_def);
return ret;
/**
* Check all moods for syntax errors.
*
- * \param fd The afs socket.
- * \param query Unused.
+ * \param aca Only ->pbout is used for diagnostics.
+ *
+ * \return Negative on fatal errors. Inconsistent mood definitions are not
+ * considered an error.
*/
-void mood_check_callback(int fd, __a_unused const struct osl_object *query)
+int mood_check_callback(struct afs_callback_arg *aca)
{
- struct para_buffer pb = {
- .max_size = shm_get_shmmax(),
- .private_data = &(struct afs_max_size_handler_data) {
- .fd = fd,
- .band = SBD_OUTPUT
- },
- .max_size_handler = afs_max_size_handler
- };
-
- int ret = para_printf(&pb, "checking moods...\n");
- if (ret < 0)
- return;
- osl_rbtree_loop(moods_table, BLOBCOL_ID, &pb,
- check_mood);
- if (pb.offset)
- pass_buffer_as_shm(fd, SBD_OUTPUT, pb.buf, pb.offset);
- free(pb.buf);
+ para_printf(&aca->pbout, "checking moods...\n");
+ return osl(osl_rbtree_loop(moods_table, BLOBCOL_ID, &aca->pbout,
+ check_mood));
}
static int64_t normalized_value(int64_t x, int64_t n, int64_t sum, int64_t qd)
int ret;
char *mood_name = NULL;
+ ret = clear_score_table();
+ if (ret < 0)
+ return ret;
if (!current_mood)
return 1;
PARA_NOTICE_LOG("reloading %s\n", current_mood->name?
int moods_event_handler(enum afs_events event, __a_unused struct para_buffer *pb,
void *data)
{
- int ret;
-
if (!current_mood)
return 0;
switch (event) {
case BLOB_ADD:
if (data == moods_table || data == playlists_table)
return 1; /* no reload necessary for these */
- ret = clear_score_table();
- if (ret < 0)
- PARA_CRIT_LOG("clear score table returned %s\n",
- para_strerror(-ret));
return reload_current_mood();
/* these also require reload of the score table */
case ATTRIBUTE_ADD: