Esempio n. 1
0
int pa_client_conf_env(pa_client_conf *c) {
    char *e;

    if ((e = getenv(ENV_DEFAULT_SINK))) {
        pa_xfree(c->default_sink);
        c->default_sink = pa_xstrdup(e);
    }

    if ((e = getenv(ENV_DEFAULT_SOURCE))) {
        pa_xfree(c->default_source);
        c->default_source = pa_xstrdup(e);
    }

    if ((e = getenv(ENV_DEFAULT_SERVER))) {
        pa_xfree(c->default_server);
        c->default_server = pa_xstrdup(e);

        /* We disable autospawning automatically if a specific server was set */
        c->autospawn = FALSE;
    }

    if ((e = getenv(ENV_DAEMON_BINARY))) {
        pa_xfree(c->daemon_binary);
        c->daemon_binary = pa_xstrdup(e);
    }

    if ((e = getenv(ENV_COOKIE_FILE))) {
        pa_xfree(c->cookie_file);
        c->cookie_file = pa_xstrdup(e);

        return pa_client_conf_load_cookie(c);
    }

    return 0;
}
Esempio n. 2
0
int pa_client_conf_env(pa_client_conf *c) {
    char *e;

    if ((e = getenv(ENV_DEFAULT_SINK))) {
        pa_xfree(c->default_sink);
        c->default_sink = pa_xstrdup(e);
    }

    if ((e = getenv(ENV_DEFAULT_SOURCE))) {
        pa_xfree(c->default_source);
        c->default_source = pa_xstrdup(e);
    }

    if ((e = getenv(ENV_DEFAULT_SERVER))) {
        pa_xfree(c->default_server);
        c->default_server = pa_xstrdup(e);
    }

    if ((e = getenv(ENV_DAEMON_BINARY))) {
        pa_xfree(c->daemon_binary);
        c->daemon_binary = pa_xstrdup(e);
    }

    if ((e = getenv(ENV_COOKIE_FILE))) {
        pa_xfree(c->cookie_file);
        c->cookie_file = pa_xstrdup(e);

        return pa_client_conf_load_cookie(c);
    }

    return 0;
}
Esempio n. 3
0
static void setup_context(pa_context *c, pa_iochannel *io) {
    uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
    pa_tagstruct *t;
    uint32_t tag;

    pa_assert(c);
    pa_assert(io);

    pa_context_ref(c);

    pa_assert(!c->pstream);
    c->pstream = pa_pstream_new(c->mainloop, io, c->mempool);

    pa_pstream_set_die_callback(c->pstream, pstream_die_callback, c);
    pa_pstream_set_receive_packet_callback(c->pstream, pstream_packet_callback, c);
    pa_pstream_set_receive_memblock_callback(c->pstream, pstream_memblock_callback, c);

    pa_assert(!c->pdispatch);
    c->pdispatch = pa_pdispatch_new(c->mainloop, c->use_rtclock, command_table, PA_COMMAND_MAX);

    if (pa_client_conf_load_cookie(c->conf, cookie, sizeof(cookie)) < 0)
        pa_log_info("No cookie loaded. Attempting to connect without.");

    t = pa_tagstruct_command(c, PA_COMMAND_AUTH, &tag);

    c->do_shm =
        pa_mempool_is_shared(c->mempool) &&
        c->is_local;

    pa_log_debug("SHM possible: %s", pa_yes_no(c->do_shm));

    /* Starting with protocol version 13 we use the MSB of the version
     * tag for informing the other side if we could do SHM or not.
     * Starting from version 31, second MSB is used to flag memfd support. */
    pa_tagstruct_putu32(t, PA_PROTOCOL_VERSION | (c->do_shm ? 0x80000000U : 0) |
                        (c->memfd_on_local ? 0x40000000 : 0));
    pa_tagstruct_put_arbitrary(t, cookie, sizeof(cookie));

#ifdef HAVE_CREDS
{
    pa_creds ucred;

    if (pa_iochannel_creds_supported(io))
        pa_iochannel_creds_enable(io);

    ucred.uid = getuid();
    ucred.gid = getgid();

    pa_pstream_send_tagstruct_with_creds(c->pstream, t, &ucred);
}
#else
    pa_pstream_send_tagstruct(c->pstream, t);
#endif

    pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, setup_complete_callback, c, NULL);

    pa_context_set_state(c, PA_CONTEXT_AUTHORIZING);

    pa_context_unref(c);
}
Esempio n. 4
0
int pa_client_conf_load(pa_client_conf *c, const char *filename) {
    FILE *f = NULL;
    char *fn = NULL;
    int r = -1;

    /* Prepare the configuration parse table */
    pa_config_item table[] = {
        { "daemon-binary",          pa_config_parse_string,  NULL },
        { "extra-arguments",        pa_config_parse_string,  NULL },
        { "default-sink",           pa_config_parse_string,  NULL },
        { "default-source",         pa_config_parse_string,  NULL },
        { "default-server",         pa_config_parse_string,  NULL },
        { "autospawn",              pa_config_parse_bool,    NULL },
        { "cookie-file",            pa_config_parse_string,  NULL },
        { "disable-shm",            pa_config_parse_bool,    NULL },
        { NULL,                     NULL,                    NULL },
    };

    table[0].data = &c->daemon_binary;
    table[1].data = &c->extra_arguments;
    table[2].data = &c->default_sink;
    table[3].data = &c->default_source;
    table[4].data = &c->default_server;
    table[5].data = &c->autospawn;
    table[6].data = &c->cookie_file;
    table[7].data = &c->disable_shm;

    f = filename ?
        fopen((fn = pa_xstrdup(filename)), "r") :
        pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn, "r");

    if (!f && errno != EINTR) {
        pa_log_warn("Failed to open configuration file '%s': %s", fn, pa_cstrerror(errno));
        goto finish;
    }

    r = f ? pa_config_parse(fn, f, table, NULL) : 0;

    if (!r)
        r = pa_client_conf_load_cookie(c);


finish:
    pa_xfree(fn);

    if (f)
        fclose(f);

    return r;
}
Esempio n. 5
0
int pa_client_conf_load(pa_client_conf *c, const char *filename) {
    FILE *f = NULL;
    char *fn = NULL;
    int r = -1;

    /* Prepare the configuration parse table */
    pa_config_item table[] = {
        { "daemon-binary",          pa_config_parse_string,   &c->daemon_binary, NULL },
        { "extra-arguments",        pa_config_parse_string,   &c->extra_arguments, NULL },
        { "default-sink",           pa_config_parse_string,   &c->default_sink, NULL },
        { "default-source",         pa_config_parse_string,   &c->default_source, NULL },
        { "default-server",         pa_config_parse_string,   &c->default_server, NULL },
        { "autospawn",              pa_config_parse_bool,     &c->autospawn, NULL },
        { "cookie-file",            pa_config_parse_string,   &c->cookie_file, NULL },
        { "disable-shm",            pa_config_parse_bool,     &c->disable_shm, NULL },
        { "enable-shm",             pa_config_parse_not_bool, &c->disable_shm, NULL },
        { "shm-size-bytes",         pa_config_parse_size,     &c->shm_size, NULL },
        { NULL,                     NULL,                     NULL, NULL },
    };

    if (filename) {

        if (!(f = fopen(filename, "r"))) {
            pa_log(_("Failed to open configuration file '%s': %s"), fn, pa_cstrerror(errno));
            goto finish;
        }

        fn = pa_xstrdup(fn);

    } else {

        if (!(f = pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn)))
            if (errno != ENOENT)
                goto finish;
    }

    r = f ? pa_config_parse(fn, f, table, NULL) : 0;

    if (!r)
        r = pa_client_conf_load_cookie(c);

finish:
    pa_xfree(fn);

    if (f)
        fclose(f);

    return r;
}