configure.ac: Fix mysql configuration
[paraslash.git] / audiod.c
index 0e5fed4..bd87cf8 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -609,17 +609,14 @@ __malloc static char *glob_cmd(char *cmd)
        else
                tv_diff(&server_stream_start, &sa_time_diff, &rss);
        tv_add(&rss, &delay, &tmp);
-       replacement = make_message("%lu:%lu", tmp.tv_sec, tmp.tv_usec);
+       replacement = make_message("%lu:%lu",
+               (long unsigned)tmp.tv_sec,
+               (long unsigned)tmp.tv_usec);
        ret = s_a_r(cmd, "STREAM_START", replacement);
        free(replacement);
        if (!ret)
                goto out;
        PARA_INFO_LOG("cmd: %s, repl: %s\n", cmd, ret);
-       {
-       struct timeval now;
-       gettimeofday(&now, NULL);
-       PARA_INFO_LOG("now: %lu:%lu\n", now.tv_sec, now.tv_usec);
-       }
 out:
        return ret;
 }
@@ -699,7 +696,7 @@ static void start_stream_writer(int slot_num)
        if (a->write_cmd)
                glob = glob_cmd(a->write_cmd);
        if (!glob)
-               glob = para_strdup("para_play");
+               glob = para_strdup("para_write -w alsa");
        PARA_INFO_LOG("starting stream writer: %s\n", glob);
        open_filters(slot_num);
        ret = para_exec_cmdline_pid(&s->wpid, glob, fds);
@@ -797,21 +794,22 @@ static void compute_time_diff(const struct timeval *status_time)
                count > 10? sign : sign * time_smooth, &diff,
                &tmp);
        sa_time_diff = tmp;
-       PARA_INFO_LOG("time diff (cur/avg): "
-               "%li:%lu/%li:%lu\n",
-               sign * diff.tv_sec, (diff.tv_usec + 500) / 1000,
-               sa_time_diff_sign * sa_time_diff.tv_sec,
-               (sa_time_diff.tv_usec + 500)/ 1000);
+       PARA_INFO_LOG("time diff (cur/avg): %s%lums/%s%lums\n",
+               sign > 0? "+" : "-",
+               tv2ms(&diff),
+               sa_time_diff_sign ? "+" : "-",
+               tv2ms(&sa_time_diff)
+       );
 }
 
 static void check_stat_line(char *line)
 {
        int itemnum;
        size_t ilen = 0;
-       struct timeval tv;
+       long unsigned sec, usec;
        char *tmp;
 
-       PARA_INFO_LOG("line: %s\n", line);
+//     PARA_INFO_LOG("line: %s\n", line);
        if (!line)
                return;
        itemnum = stat_line_valid(line);
@@ -840,14 +838,16 @@ static void check_stat_line(char *line)
                length_seconds = atoi(line + ilen + 1);
                break;
        case SI_STREAM_START:
-               if (sscanf(line + ilen + 1, "%lu.%lu",
-                               &tv.tv_sec, &tv.tv_usec) == 2)
-                       server_stream_start = tv;
+               if (sscanf(line + ilen + 1, "%lu.%lu", &sec, &usec) == 2) {
+                       server_stream_start.tv_sec = sec;
+                       server_stream_start.tv_usec = usec;
+               }
                break;
        case SI_CURRENT_TIME:
-               if (sscanf(line + ilen + 1, "%lu.%lu", &tv.tv_sec,
-                               &tv.tv_usec) == 2)
+               if (sscanf(line + ilen + 1, "%lu.%lu", &sec, &usec) == 2) {
+                       struct timeval tv = {sec, usec};
                        compute_time_diff(&tv);
+               }
                break;
        }
 }
@@ -1096,8 +1096,9 @@ static int setup_default_filters(void)
                free(tmp);
                if (ret < 0)
                        goto out;
-               PARA_INFO_LOG("%s -> default filter: %s\n", audio_formats[i], filters[j].name);
-               ret = add_filter(i, para_strdup("wav"));
+               PARA_INFO_LOG("%s -> default filter: %s\n", audio_formats[i],
+                       filters[j].name);
+               ret = add_filter(i, "wav");
                if (ret < 0)
                        goto out;
                PARA_INFO_LOG("%s -> default filter: wav\n", audio_formats[i]);
@@ -1157,7 +1158,7 @@ static int init_stream_io(void)
        free(cmd);
        /* filters */
        filter_init(filters);
-       nf = MAX(2,  conf.filter_given) + 1;
+       nf = PARA_MAX(2,  conf.filter_given) + 1;
        PARA_INFO_LOG("allocating space for %d filters\n", nf);
        FOR_EACH_AUDIO_FORMAT(i) {
                afi[i].filter_conf = para_malloc(nf * sizeof(char *));
@@ -1417,14 +1418,14 @@ static int com_cycle(int fd, int argc, char **argv)
        return 1;
 }
 
-static int check_perms(struct ucred *c)
+static int check_perms(uid_t uid)
 {
        int i;
 
        if (!conf.user_allow_given)
                return 1;
        for (i = 0; i < conf.user_allow_given; i++)
-               if (c->uid == conf.user_allow_arg[i])
+               if (uid == conf.user_allow_arg[i])
                        return 1;
        return -E_UCRED_PERM;
 }
@@ -1432,7 +1433,6 @@ static int check_perms(struct ucred *c)
 static int handle_connect(void)
 {
        int i, argc, ret, clifd = -1;
-       struct ucred c;
        char *buf = para_malloc(MAXLINE), **argv = NULL;
        struct sockaddr_un unix_addr;
 
@@ -1440,12 +1440,11 @@ static int handle_connect(void)
        if (ret < 0)
                goto out;
        clifd = ret;
-       ret = recv_cred_buffer(clifd, buf, MAXLINE - 1, &c);
+       ret = recv_cred_buffer(clifd, buf, MAXLINE - 1);
        if (ret < 0)
                goto out;
-       PARA_INFO_LOG("pid: %i, uid: %i, gid: %i, ret: %i, buf: %s\n", c.pid, c.uid, c.gid, ret, buf);
-       buf[ret] = '\0';
-       ret = check_perms(&c);
+       PARA_INFO_LOG("connection from user %i\n",  ret);
+       ret = check_perms(ret);
        if (ret < 0)
                goto out;
        argc = split_args(buf, &argv, "\n");
@@ -1525,7 +1524,7 @@ static void audiod_pre_select(fd_set *rfds, fd_set *wfds, struct timeval *tv,
                a = &afi[s->format];
                ret = a->receiver->pre_select(rn, rfds, wfds, tv);
 //             PARA_NOTICE_LOG("%s preselect: %d\n", a->receiver->name, ret);
-               *max_fileno = MAX(*max_fileno, ret);
+               *max_fileno = PARA_MAX(*max_fileno, ret);
        }
 }
 static void audiod_post_select(int select_ret, fd_set *rfds, fd_set *wfds)
@@ -1563,9 +1562,9 @@ static void __noreturn audiod_mainloop(void)
 repeat:
        FD_ZERO(&wfds);
        FD_ZERO(&rfds);
+       max_fileno = -1;
        /* always check signal pipe and the local socket */
-       FD_SET(signal_pipe, &rfds);
-       max_fileno = signal_pipe;
+       para_fd_set(signal_pipe, &rfds, &max_fileno);
        para_fd_set(audiod_socket, &rfds, &max_fileno);
 
        if (audiod_status != AUDIOD_ON)
@@ -1646,7 +1645,6 @@ int __noreturn main(int argc, char *argv[])
        char *cf;
        int i;
 
-       fprintf(stderr, "argc: %d\n", argc);
        valid_fd_012();
        hostname = para_hostname();
        cmdline_parser(argc, argv, &conf);