Пример #1
0
char* pid2text(pid_t pid)
{
    static unsigned id = 0;

    char *str = 0;
    char *exe = 0;

    if( pid == 0 ) {
	str = strdup("<internal>");
	goto EXIT;
    }

    exe = pid2exe(pid);

    if( asprintf(&str, "external-%u/%ld (%s)", ++id,
		 (long)pid, exe ?: "unknown") < 0 )
	str = 0;

EXIT:
    free(exe);

    return str ?: strdup("error");
}
mir_node_type pa_classify_guess_stream_node_type(struct userdata *u,
                                                 pa_proplist *pl,
                                                 pa_nodeset_resdef **resdef)
{
    pa_nodeset_map *map = NULL;
    const char     *role;
    const char     *bin;
    char            buf[4096];
    char            appid[PATH_MAX];
    const char     *pidstr;
    const char     *name;
    int             pid;

    pa_assert(u);
    pa_assert(pl);


    do {
        if (!(pidstr = pa_proplist_gets(pl, PA_PROP_APPLICATION_PROCESS_ID)) ||
            (pid = strtol(pidstr, NULL, 10)) < 2)
        {
            pid = 0;
        }

        if ((bin = pa_proplist_gets(pl, PA_PROP_APPLICATION_PROCESS_BINARY))) {
            if (!strcmp(bin, "threaded-ml") ||
                !strcmp(bin, "WebProcess")  ||
                !strcmp(bin,"wrt_launchpad_daemon"))
            {
                if (!pid)
                    break;

#ifdef WITH_AUL
                if (aul_app_get_appid_bypid(pid, buf, sizeof(buf)) < 0 &&
                    pid2exe(pid, buf, sizeof(buf)) < 0)
                {
                    pa_log("can't obtain real application name for wrt '%s' "
                           "(pid %d)", bin, pid);
                    break;
                }
#else
                if (pid2exe(pid, buf, sizeof(buf)) < 0) {
                    pa_log("can't obtain real application name for wrt '%s' "
                           "(pid %d)", bin, pid);
                    break;
                }
#endif
                if ((name = strrchr(buf, '.')))
                    name++;
                else
                    name = buf;

                pa_proplist_sets(pl, PA_PROP_APPLICATION_NAME, name);
                pa_proplist_sets(pl, PA_PROP_APPLICATION_PROCESS_BINARY, buf);

                bin = buf;
            }

            if ((map = pa_nodeset_get_map_by_binary(u, bin))) {
                if (map->role)
                    pa_proplist_sets(pl, PA_PROP_MEDIA_ROLE, map->role);
                break;
            }
        }

        if ((role = pa_proplist_gets(pl, PA_PROP_MEDIA_ROLE)) &&
            (map = pa_nodeset_get_map_by_role(u, role)))
            break;

        if (resdef)
            *resdef = NULL;

        return role ? mir_node_type_unknown : mir_player;

    } while (0);

    if (pid2appid(pid, appid, sizeof(appid)))
        pa_proplist_sets(pl, PA_PROP_RESOURCE_SET_APPID, appid);

    if (resdef)
        *resdef = map ? map->resdef : NULL;

    return map ? map->type : mir_player;
}