[PATCH 3/6] pacmd: Add optional argument for quiet mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 19.07.2013 21:32, schrieb Peter Meerwald:
> quiet mode allows to turn off PA's welcome message and the >>> prompt
>
> pacmd waits 100 ms; if nothing is coming from the PA daemon, it is a new
> version and we actively ask for the welcome message (non-quiet mode) by sending
> "hello"; in quiet mode, we send "hello quiet" to tell the daemon we are not
> interested in polite messaging and prompts
>
> if something is received from the PA daemon within 100 ms, it must be an old
> version and we just continue as before; quiet is silently ignored for older
> PA daemons (nothing we can do, except filter the data coming from the
> server -- no)
>
> Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
> ---
>   src/utils/pacmd.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
>   1 file changed, 56 insertions(+), 5 deletions(-)
>
> diff --git a/src/utils/pacmd.c b/src/utils/pacmd.c
> index cf0eb44..7dd3c9b 100644
> --- a/src/utils/pacmd.c
> +++ b/src/utils/pacmd.c
> @@ -46,6 +46,7 @@
>   static void help(const char *argv0) {
>       printf("%s %s\n",    argv0, "exit");
>       printf("%s %s\n",    argv0, "help");
> +    printf("%s %s\n",    argv0, "hello");
>       printf("%s %s\n",    argv0, "list-(modules|sinks|sources|clients|cards|samples)");
>       printf("%s %s\n",    argv0, "list-(sink-inputs|source-outputs)");
>       printf("%s %s\n",    argv0, "stat");
> @@ -83,11 +84,13 @@ static void help(const char *argv0) {
>       printf(_("\n"
>            "  -h, --help                            Show this help\n"
>            "      --version                         Show version\n"
> +         "      --quiet                           Don't show welcome message\n"
>            "When no command is given pacmd starts in the interactive mode\n" ));
>   }
>   
>   enum {
> -    ARG_VERSION = 256
> +    ARG_VERSION = 256,
> +    ARG_QUIET
>   };
>   
>   int main(int argc, char*argv[]) {
> @@ -102,7 +105,7 @@ int main(int argc, char*argv[]) {
>       bool ibuf_eof, obuf_eof, ibuf_closed, obuf_closed;
>       struct pollfd pollfd[3];
>       struct pollfd *watch_socket, *watch_stdin, *watch_stdout;
> -
> +    bool quiet = false;
>       int stdin_type = 0, stdout_type = 0, fd_type = 0;
>   
>       char *bn = NULL;
> @@ -110,6 +113,7 @@ int main(int argc, char*argv[]) {
>   
>       static const struct option long_options[] = {
>           {"version",     0, NULL, ARG_VERSION},
> +        {"quiet",       0, NULL, ARG_QUIET},
>           {"help",        0, NULL, 'h'},
>           {NULL,          0, NULL, 0}
>       };
> @@ -121,7 +125,7 @@ int main(int argc, char*argv[]) {
>   
>       bn = pa_path_get_filename(argv[0]);
>   
> -    while ((c = getopt_long(argc, argv, "h", long_options, NULL)) != -1) {
> +    while ((c = getopt_long(argc, argv, "hq", long_options, NULL)) != -1) {
>           switch (c) {
>               case 'h' :
>                   help(bn);
> @@ -136,11 +140,18 @@ int main(int argc, char*argv[]) {
>                          pa_get_library_version());
>                   ret = 0;
>                   goto quit;
> +            case 'q':
> +            case ARG_QUIET:
> +                quiet = true;
> +                break;
>               default:
>                   goto quit;
>           }
>       }
>   
> +    argv += optind;
> +    argc -= optind;
> +
>       if (pa_pid_file_check_running(&pid, "pulseaudio") < 0) {
>           pa_log(_("No PulseAudio daemon running, or not running as session daemon."));
>           goto quit;
> @@ -192,8 +203,8 @@ int main(int argc, char*argv[]) {
>       ibuf_index = ibuf_length = obuf_index = obuf_length = 0;
>       ibuf_eof = obuf_eof = ibuf_closed = obuf_closed = false;
>   
> -    if (argc > 1) {
> -        for (i = 1; i < argc; i++) {
> +    if (argc > 0) {
> +        for (i = 0; i < argc; i++) {
>               size_t k;
>   
>               k = PA_MIN(ibuf_size - ibuf_length, strlen(argv[i]));
> @@ -209,6 +220,46 @@ int main(int argc, char*argv[]) {
>           ibuf_eof = true;
>       }
>   
> +    /* wait for initial welcome */
> +    for (;;) {
> +        struct pollfd *p;
> +        int res;
> +
> +        pa_zero(pollfd);
> +        p = pollfd;
> +
> +        watch_socket = p++;
> +        watch_socket->fd = fd;
> +        watch_socket->events = POLLIN;
> +
> +        if ((res = pa_poll(pollfd, p-pollfd, 100)) < 0) {
> +            if (errno == EINTR)
> +                continue;
> +
> +            pa_log(_("poll(): %s"), strerror(errno));
> +            goto quit;
> +        }

The setup of watch_socket/pollfd and the call (why isn't watch_socket 
passed?) is really awkward to me. Why such strange code?

> +
> +        /* if nothing coming from daemon quickly, it supports explicit hello */
> +        if (res == 0) {
> +            char buf[32];
> +            ssize_t r;
> +
> +            /* send explicit hello */
> +            sprintf(buf, "hello %s\n", quiet ? "quiet" : "");
> +            if ((r = pa_write(fd, buf, strlen(buf), &fd_type)) < 0) {
> +                pa_log(_("write(): %s"), strerror(errno));
> +                goto quit;
> +            }
> +
> +            break;
> +        }
> +
> +        /* got data from the daemon, just continue */
> +        if (watch_socket->revents & POLLIN)
> +            break;
> +    }
> +
>       for (;;) {
>           struct pollfd *p;
>   



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux