testsuite: Introduce a new test for para_server.
[paraslash.git] / audiod_command.c
index 05059ac06d2ff7f23a9648e14e54c71c904bfa9d..dfb014aebc1c1d12659364189ac79813c952139c 100644 (file)
@@ -120,24 +120,22 @@ void stat_client_write_item(int item_num)
        struct para_buffer pb = {.flags = 0};
        struct para_buffer pfpb = {.flags = PBF_SIZE_PREFIX};
        const uint64_t one = 1;
+       char *msg = stat_item_values[item_num];
+       struct para_buffer *b;
 
        list_for_each_entry_safe(sc, tmp, &client_list, node) {
                int fd = sc->fd, ret;
 
                if (!((one << item_num) & sc->item_mask))
                        continue;
-               if (write_ok(fd) > 0) {
-                       struct para_buffer *b =
-                               (sc->flags & SCF_PARSER_FRIENDLY)? &pfpb : &pb;
-                       char *msg = stat_item_values[item_num];
-                       if (!b->buf)
-                               WRITE_STATUS_ITEM(b, item_num, "%s\n",
-                                       msg? msg : "");
-                       ret = write(fd, b->buf, b->offset);
-                       if (ret == b->offset)
-                               continue;
-               }
-               /* write error or fd not ready for writing */
+               b = (sc->flags & SCF_PARSER_FRIENDLY)? &pfpb : &pb;
+               if (!b->buf)
+                       (void)WRITE_STATUS_ITEM(b, item_num, "%s\n",
+                               msg? msg : "");
+               ret = write(fd, b->buf, b->offset);
+               if (ret == b->offset)
+                       continue;
+               /* write error or short write */
                close(fd);
                num_clients--;
                PARA_INFO_LOG("deleting client on fd %d\n", fd);
@@ -147,8 +145,6 @@ void stat_client_write_item(int item_num)
        }
        free(pb.buf);
        free(pfpb.buf);
-//     if (num_clients)
-//             PARA_DEBUG_LOG("%d client(s)\n", num_clients);
 }
 
 /**
@@ -198,7 +194,7 @@ static int get_play_time_slot_num(void)
        FOR_EACH_SLOT(i) {
                struct slot_info *s = &slot[i];
                struct timeval wstime;
-               if (!s->wns)
+               if (!s->wns || !s->wns[0].btrn)
                        continue;
                btr_get_node_start(s->wns[0].btrn, &wstime);
                if (oldest_slot >= 0 && tv_diff(&wstime, &oldest_wstime, NULL) > 0)
@@ -307,6 +303,9 @@ int com_stat(int fd, int argc, char **argv)
        const uint64_t one = 1;
        struct para_buffer b = {.flags = 0};
 
+       ret = mark_fd_nonblocking(fd);
+       if (ret < 0)
+               return ret;
        for (i = 1; i < argc; i++) {
                const char *arg = argv[i];
                if (arg[0] != '-')
@@ -334,7 +333,7 @@ int com_stat(int fd, int argc, char **argv)
                char *item = stat_item_values[i];
                if (!((one << i) & mask))
                        continue;
-               WRITE_STATUS_ITEM(&b, i, "%s\n", item? item : "");
+               (void)WRITE_STATUS_ITEM(&b, i, "%s\n", item? item : "");
        }
        ret = client_write(fd, b.buf);
        if (ret >= 0)
@@ -481,7 +480,7 @@ void audiod_status_dump(void)
                        free(new);
        }
 
-       new = uptime_str();
+       new = get_server_uptime_str(now);
        old = stat_item_values[SI_AUDIOD_UPTIME];
        if (!old || strcmp(old, new)) {
                free(old);