X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=afs.c;h=355400874377a82cd1b5c085f6d3c729411ce540;hp=f619c08ec85e659414fc3fd3e03a3015a19f91f6;hb=4ef71951aaf3621308977c1de7b8506b00331294;hpb=4a198ca75a3edf2865d599fc7aa0f672c4f30069 diff --git a/afs.c b/afs.c index f619c08e..35540087 100644 --- a/afs.c +++ b/afs.c @@ -460,7 +460,7 @@ static int pass_afd(int fd, char *buf, size_t size) /* Sum of the length of all control messages in the buffer */ msg.msg_controllen = cmsg->cmsg_len; - PARA_NOTICE_LOG("passing %zu bytes and fd %d\n", size, fd); + PARA_DEBUG_LOG("passing %zu bytes and fd %d\n", size, fd); ret = sendmsg(server_socket, &msg, 0); if (ret < 0) { ret = -ERRNO_TO_PARA_ERROR(errno); @@ -486,16 +486,16 @@ int open_next_audio_file(void) struct audio_file_data afd; int ret, shmid; char buf[8]; + long score; - PARA_NOTICE_LOG("getting next af\n"); - ret = score_get_best(&aft_row, &afd.score); + 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); + ret = open_and_update_audio_file(aft_row, &afd, score); if (ret < 0) return ret; shmid = ret; - PARA_NOTICE_LOG("shmid: %u\n", shmid); if (!write_ok(server_socket)) { PARA_EMERG_LOG("afs_socket not writable\n"); goto destroy; @@ -541,7 +541,9 @@ static int activate_mood_or_playlist(char *arg, int *num_admissible) if (arg) { current_mop = para_strdup(arg); mmd_lock(); - strcpy(mmd->afs_mode_string, arg); /* FIXME: check length */ + strncpy(mmd->afs_mode_string, arg, + sizeof(mmd->afs_mode_string)); + mmd->afs_mode_string[sizeof(mmd->afs_mode_string) - 1] = '\0'; mmd_unlock(); } else { mmd_lock(); @@ -611,7 +613,7 @@ static void init_admissible_files(char *arg) static int setup_command_socket_or_die(void) { - int ret; + int ret, socket_fd; char *socket_name = conf.afs_socket_arg; struct sockaddr_un unix_addr; @@ -622,13 +624,18 @@ static int setup_command_socket_or_die(void) PARA_EMERG_LOG("%s: %s\n", PARA_STRERROR(-ret), socket_name); exit(EXIT_FAILURE); } - if (listen(ret , 5) < 0) { - PARA_EMERG_LOG("%s", "can not listen on socket\n"); + socket_fd = ret; + if (listen(socket_fd , 5) < 0) { + PARA_EMERG_LOG("can not listen on socket\n"); exit(EXIT_FAILURE); } - PARA_INFO_LOG("listening on command socket %s (fd %d)\n", socket_name, - ret); - return ret; + ret = mark_fd_nonblock(socket_fd); + if (ret < 0) { + close(socket_fd); + return ret; + } + PARA_INFO_LOG("listening on socket %s (fd %d)\n", socket_name, ret); + return socket_fd; } static void close_afs_tables(void) @@ -672,6 +679,8 @@ 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, + database_dir); for (i = 0; i < NUM_AFS_TABLES; i++) { ret = afs_tables[i].open(database_dir); if (ret >= 0) @@ -746,9 +755,13 @@ static void register_signal_task(void) static struct list_head afs_client_list; +/** Describes on connected afs client. */ struct afs_client { + /** Position in the afs client list. */ struct list_head node; + /** The socket file descriptor for this client. */ int fd; + /** The time the client connected. */ struct timeval connect_time; }; @@ -830,7 +843,7 @@ static void execute_server_command(void) return; } buf[ret] = '\0'; - PARA_NOTICE_LOG("received: %s\n", buf); + PARA_DEBUG_LOG("received: %s\n", buf); if (!strcmp(buf, "new")) { ret = open_next_audio_file(); if (ret < 0) @@ -881,7 +894,7 @@ static void command_post_select(struct sched *s, struct task *t) struct command_task *ct = t->private_data; struct sockaddr_un unix_addr; struct afs_client *client, *tmp; - + int fd; if (FD_ISSET(server_socket, &s->rfds)) execute_server_command(); @@ -908,8 +921,15 @@ static void command_post_select(struct sched *s, struct task *t) PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-t->ret)); goto out; } + fd = t->ret; + t->ret = mark_fd_nonblock(fd); + if (t->ret < 0) { + PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-t->ret)); + close(fd); + goto out; + } client = para_malloc(sizeof(*client)); - client->fd = t->ret; + client->fd = fd; client->connect_time = *now; para_list_add(&client->node, &afs_client_list); out: