Merge branch 'refs/heads/t/makefile_conventions'
[paraslash.git] / afs.c
diff --git a/afs.c b/afs.c
index d5afc6d9eb12eb731fecfdb8209bcd150e0e01cd..7f27b7dd2653d79a0a7679da3e80d2d9c55e37ac 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -424,7 +424,7 @@ static int pass_afd(int fd, char *buf, size_t size)
 {
        struct msghdr msg = {.msg_iov = NULL};
        struct cmsghdr *cmsg;
-       char control[255];
+       char control[255] __a_aligned(8);
        int ret;
        struct iovec iov;
 
@@ -497,12 +497,11 @@ no_admissible_files:
 }
 
 /* Never fails if arg == NULL */
-static int activate_mood_or_playlist(char *arg, int *num_admissible)
+static int activate_mood_or_playlist(const char *arg, int *num_admissible)
 {
        enum play_mode mode;
        int ret;
 
-       PARA_INFO_LOG("new playlist: %s\n", arg);
        if (!arg) {
                ret = change_current_mood(NULL); /* always successful */
                mode = PLAY_MODE_MOOD;
@@ -591,7 +590,7 @@ static void flush_and_free_pb(struct para_buffer *pb)
 
 static int com_select_callback(struct afs_callback_arg *aca)
 {
-       char *arg = aca->query.data;
+       const char *arg = aca->query.data;
        int num_admissible, ret;
 
        ret = clear_score_table();
@@ -608,14 +607,17 @@ static int com_select_callback(struct afs_callback_arg *aca)
        if (ret >= 0)
                goto out;
        /* ignore subsequent errors (but log them) */
-       para_printf(&aca->pbout, "could not activate %s: %s\n"
-               "switching back to %s\n",
-               arg, para_strerror(-ret), current_mop? current_mop : "dummy");
-       ret = activate_mood_or_playlist(current_mop, &num_admissible);
-       if (ret >= 0)
-               goto out;
-       para_printf(&aca->pbout, "could not activate %s: %s\nswitching to dummy\n",
-               current_mop, para_strerror(-ret));
+       para_printf(&aca->pbout, "could not activate %s\n", arg);
+       if (current_mop) {
+               int ret2;
+               para_printf(&aca->pbout, "switching back to %s\n", current_mop);
+               ret2 = activate_mood_or_playlist(current_mop, &num_admissible);
+               if (ret2 >= 0)
+                       goto out;
+               para_printf(&aca->pbout, "could not reactivate %s: %s\n",
+                       current_mop, para_strerror(-ret2));
+       }
+       para_printf(&aca->pbout, "activating dummy mood\n");
        activate_mood_or_playlist(NULL, &num_admissible);
 out:
        para_printf(&aca->pbout, "activated %s (%d admissible files)\n",
@@ -647,15 +649,10 @@ static int setup_command_socket_or_die(void)
        char *socket_name = conf.afs_socket_arg;
 
        unlink(socket_name);
-       ret = create_local_socket(socket_name, 0);
+       ret = create_local_socket(socket_name);
        if (ret < 0) {
-               ret = create_local_socket(socket_name,
-                       S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IWOTH);
-               if (ret < 0) {
-                       PARA_EMERG_LOG("%s: %s\n", para_strerror(-ret),
-                               socket_name);
-                       exit(EXIT_FAILURE);
-               }
+               PARA_EMERG_LOG("%s: %s\n", para_strerror(-ret), socket_name);
+               exit(EXIT_FAILURE);
        }
        socket_fd = ret;
        PARA_INFO_LOG("listening on socket %s (fd %d)\n", socket_name,
@@ -704,7 +701,7 @@ static int open_afs_tables(void)
        int i, ret;
 
        get_database_dir();
-       PARA_NOTICE_LOG("opening %u osl tables in %s\n", NUM_AFS_TABLES,
+       PARA_NOTICE_LOG("opening %d osl tables in %s\n", NUM_AFS_TABLES,
                database_dir);
        for (i = 0; i < NUM_AFS_TABLES; i++) {
                ret = afs_tables[i].open(database_dir);
@@ -1022,6 +1019,13 @@ __noreturn void afs_init(uint32_t cookie, int socket_fd)
        register_command_task(cookie, &s);
        s.default_timeout.tv_sec = 0;
        s.default_timeout.tv_usec = 999 * 1000;
+       ret = write(socket_fd, "\0", 1);
+       if (ret != 1) {
+               if (ret == 0)
+                       errno = EINVAL;
+               ret = -ERRNO_TO_PARA_ERROR(errno);
+               goto out_close;
+       }
        ret = schedule(&s);
        sched_shutdown(&s);
 out_close:
@@ -1193,7 +1197,7 @@ __must_check int afs_event(enum afs_events event, struct para_buffer *pb,
                        continue;
                ret = t->event_handler(event, pb, data);
                if (ret < 0) {
-                       PARA_CRIT_LOG("table %s, event %d: %s\n", t->name,
+                       PARA_CRIT_LOG("table %s, event %u: %s\n", t->name,
                                event, para_strerror(-ret));
                        return ret;
                }