Apache CGI - How to get ALSA functions to work properly.

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

 



The following code, when accessed CGI-style  through the Apache server, does not detect any midi cards on the system. Normally, at least 1 card, and more if MIDI devices are plugged in, are found by this function. Through Apache, the snd_card_next() function (https://www.alsa-project.org/alsa-doc/alsa-lib/group___control.html#ga6fccc8a2d7d5ebd072a552a05855c145) fails in some capacity, leading to the first if statement being executed. How can I fix this?

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <alsa/asoundlib.h>

#define NL    "\r\n"

void get_alsa_midi_cards(void)
{
    int card, status, cnt;
    int code;
    char *card_name;
    int i;

    card = -1;  // use -1 to prime the pump of iterating through card list
    status = snd_card_next(&card);
    if (status < 0 || card < 0) {
        printf ("Content-Type: text/html; charset=utf-8" NL "Cache-Control: no-cache" NL NL);
        printf("{\"alsa_midi_card\":[]}");
        //printf("Status: %i Card: %i", status, card);
        //printf("Status: 404 Not Found" NL NL);
        return;
    }
    printf ("Content-Type: text/html; charset=utf-8" NL "Cache-Control: no-cache" NL NL);

    printf("{\"alsa_midi_card\":[");

    for (i = 0, cnt = 0; card >= 0; i++) {
        if ((code = snd_card_get_longname (card, &card_name)) < 0)
            continue;
        if (cnt++ > 0)
            printf(",");
        printf("{\"longname\":\"");
        printf(card_name);
        printf("\"}");

        if ((status = snd_card_next (&card)) < 0)
            break;
    }
    printf("]}");
}

int main (int argc, char *argv[])
{
    get_alsa_midi_cards();

    return 0;
}


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx




[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux