fecdec_filter: Avoid potentially expensive pointer subtraction.
[paraslash.git] / afs.c
diff --git a/afs.c b/afs.c
index f4a44bbbe0af852a61d81488bfe2274e0879a52d..ccda7cdaaa4e211b696d4e898f08c7c2520ab3ef 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -54,13 +54,13 @@ enum afs_table_num {
 };
 
 static struct afs_table afs_tables[NUM_AFS_TABLES] = {
-       [TBLNUM_AUDIO_FILES] = {.init = aft_init},
-       [TBLNUM_ATTRIBUTES] = {.init = attribute_init},
-       [TBLNUM_SCORES] = {.init = score_init},
-       [TBLNUM_MOODS] = {.init = moods_init},
-       [TBLNUM_LYRICS] = {.init = lyrics_init},
-       [TBLNUM_IMAGES] = {.init = images_init},
-       [TBLNUM_PLAYLIST] = {.init = playlists_init},
+       [TBLNUM_AUDIO_FILES] = {.init = aft_init, .name = "audio_files"},
+       [TBLNUM_ATTRIBUTES] = {.init = attribute_init, .name = "attributes"},
+       [TBLNUM_SCORES] = {.init = score_init, .name = "scores"},
+       [TBLNUM_MOODS] = {.init = moods_init, .name = "moods"},
+       [TBLNUM_LYRICS] = {.init = lyrics_init, .name = "lyrics"},
+       [TBLNUM_IMAGES] = {.init = images_init, .name = "images"},
+       [TBLNUM_PLAYLIST] = {.init = playlists_init, .name = "playlists"},
 };
 
 struct command_task {
@@ -776,7 +776,7 @@ static void signal_pre_select(struct sched *s, struct task *t)
        para_fd_set(st->fd, &s->rfds, &s->max_fileno);
 }
 
-static void signal_post_select(struct sched *s, struct task *t)
+static void afs_signal_post_select(struct sched *s, struct task *t)
 {
        struct signal_task *st = container_of(t, struct signal_task, task);
        if (getppid() == 1) {
@@ -805,10 +805,7 @@ static void register_signal_task(void)
 {
        struct signal_task *st = &signal_task_struct;
 
-       if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
-               PARA_EMERG_LOG("failed to ignore SIGPIPE\n");
-               exit(EXIT_FAILURE);
-       }
+       para_sigaction(SIGPIPE, SIG_IGN);
        st->fd = para_signal_init();
        PARA_INFO_LOG("signal pipe: fd %d\n", st->fd);
        para_install_sighandler(SIGINT);
@@ -816,7 +813,7 @@ static void register_signal_task(void)
        para_install_sighandler(SIGHUP);
 
        st->task.pre_select = signal_pre_select;
-       st->task.post_select = signal_post_select;
+       st->task.post_select = afs_signal_post_select;
        sprintf(st->task.status, "signal task");
        register_task(&st->task);
 }
@@ -1075,7 +1072,7 @@ static void create_tables_callback(int fd, const struct osl_object *query)
 {
        uint32_t table_mask = *(uint32_t *)query->data;
        int i, ret;
-       char *buf;
+       struct para_buffer pb = {.buf = NULL};
 
        close_afs_tables();
        for (i = 0; i < NUM_AFS_TABLES; i++) {
@@ -1088,15 +1085,15 @@ static void create_tables_callback(int fd, const struct osl_object *query)
                ret = t->create(database_dir);
                if (ret < 0)
                        goto out;
+               para_printf(&pb, "successfully created %s table\n", t->name);
        }
        ret = open_afs_tables();
 out:
-       if (ret >= 0)
-               buf = make_message("successfully created afs table(s)\n");
-       else
-               buf = make_message("%s\n", para_strerror(-ret));
-       pass_buffer_as_shm(buf, strlen(buf), &fd);
-       free(buf);
+       if (ret < 0)
+               para_printf(&pb, "%s\n", para_strerror(-ret));
+       if (pb.buf)
+               pass_buffer_as_shm(pb.buf, pb.offset, &fd);
+       free(pb.buf);
 }
 
 int com_init(int fd, int argc, char * const * const argv)