X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=afs.c;h=ac7884c7e4e4c959a3ce3b1c17d050705a70b394;hp=355400874377a82cd1b5c085f6d3c729411ce540;hb=7a0852896a75d852dbd2ac848ec5c0be3b5dea71;hpb=4ef71951aaf3621308977c1de7b8506b00331294 diff --git a/afs.c b/afs.c index 35540087..ac7884c7 100644 --- a/afs.c +++ b/afs.c @@ -164,7 +164,6 @@ int send_callback_request(callback_function *f, struct osl_object *query, int ret, fd = -1, query_shmid, result_shmid; void *query_shm, *result_shm; char buf[sizeof(afs_socket_cookie) + sizeof(int)]; - struct sockaddr_un unix_addr; size_t query_shm_size = sizeof(*cq); if (query) @@ -189,16 +188,10 @@ int send_callback_request(callback_function *f, struct osl_object *query, *(uint32_t *) buf = afs_socket_cookie; *(int *) (buf + sizeof(afs_socket_cookie)) = query_shmid; - ret = get_stream_socket(PF_UNIX); + ret = create_remote_socket(conf.afs_socket_arg); if (ret < 0) goto out; fd = ret; - ret = init_unix_addr(&unix_addr, conf.afs_socket_arg); - if (ret < 0) - goto out; - ret = PARA_CONNECT(fd, &unix_addr); - if (ret < 0) - goto out; ret = send_bin_buffer(fd, buf, sizeof(buf)); if (ret < 0) goto out; @@ -206,7 +199,7 @@ int send_callback_request(callback_function *f, struct osl_object *query, if (ret < 0) goto out; if (ret != sizeof(int)) { - ret = -E_RECV; + ret = -E_AFS_SHORT_READ; goto out; } ret = *(int *) buf; @@ -487,17 +480,26 @@ int open_next_audio_file(void) int ret, shmid; char buf[8]; long score; - +again: PARA_NOTICE_LOG("getting next audio file\n"); ret = score_get_best(&aft_row, &score); - if (ret < 0) - return ret; - ret = open_and_update_audio_file(aft_row, &afd, score); - if (ret < 0) - return ret; + if (ret < 0) { + PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); + goto no_admissible_files; + } + ret = open_and_update_audio_file(aft_row, score, &afd); + if (ret < 0) { + PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); + ret = score_delete(aft_row); + if (ret < 0) { + PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); + goto no_admissible_files; + } + goto again; + } shmid = ret; if (!write_ok(server_socket)) { - PARA_EMERG_LOG("afs_socket not writable\n"); + ret = -E_AFS_SOCKET; goto destroy; } *(uint32_t *)buf = NEXT_AUDIO_FILE; @@ -506,10 +508,13 @@ int open_next_audio_file(void) close(afd.fd); if (ret >= 0) return ret; - PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); destroy: shm_destroy(shmid); return ret; +no_admissible_files: + *(uint32_t *)buf = NO_ADMISSIBLE_FILES; + *(uint32_t *)(buf + 4) = (uint32_t)0; + return send_bin_buffer(server_socket, buf, 8); } /* Never fails if arg == NULL */ @@ -529,7 +534,7 @@ static int activate_mood_or_playlist(char *arg, int *num_admissible) ret = change_current_mood(arg + 2); mode = PLAY_MODE_MOOD; } else - ret = -E_AFS_SYNTAX; + return -E_AFS_SYNTAX; if (ret < 0) return ret; } @@ -629,7 +634,7 @@ static int setup_command_socket_or_die(void) PARA_EMERG_LOG("can not listen on socket\n"); exit(EXIT_FAILURE); } - ret = mark_fd_nonblock(socket_fd); + ret = mark_fd_nonblocking(socket_fd); if (ret < 0) { close(socket_fd); return ret; @@ -846,8 +851,10 @@ static void execute_server_command(void) PARA_DEBUG_LOG("received: %s\n", buf); if (!strcmp(buf, "new")) { ret = open_next_audio_file(); - if (ret < 0) - PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); + if (ret < 0) { + PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret)); + unregister_tasks(); + } return; } PARA_ERROR_LOG("unknown command\n"); @@ -922,7 +929,7 @@ static void command_post_select(struct sched *s, struct task *t) goto out; } fd = t->ret; - t->ret = mark_fd_nonblock(fd); + t->ret = mark_fd_nonblocking(fd); if (t->ret < 0) { PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-t->ret)); close(fd); @@ -976,7 +983,7 @@ __noreturn void afs_init(uint32_t cookie, int socket_fd) exit(EXIT_FAILURE); } server_socket = socket_fd; - ret = mark_fd_nonblock(server_socket); + ret = mark_fd_nonblocking(server_socket); if (ret < 0) exit(EXIT_FAILURE); PARA_INFO_LOG("server_socket: %d, afs_socket_cookie: %u\n", @@ -985,7 +992,7 @@ __noreturn void afs_init(uint32_t cookie, int socket_fd) register_tasks(cookie); s.default_timeout.tv_sec = 0; s.default_timeout.tv_usec = 999 * 1000; - ret = sched(&s); + ret = schedule(&s); if (ret < 0) PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret)); close_afs_tables();