Changeset 60:d1fa94aadc08 in roaraudio


Ignore:
Timestamp:
07/12/08 12:19:08 (16 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added basic UNIX Domain Socket code

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • include/roaraudio.h

    r57 r60  
    1212#include <limits.h> 
    1313#include <sys/mman.h> 
     14 
     15// TODO: can we move the next block into roard specific includes? 
     16#include <grp.h> 
     17#include <pwd.h> 
     18#include <sys/stat.h> 
    1419 
    1520#include <arpa/inet.h> 
  • libroar/socket.c

    r2 r60  
    6565 int fh; 
    6666 struct sockaddr_in   socket_addr; 
     67 struct sockaddr_un   socket_addr_un; 
    6768 struct hostent     * he; 
    6869 //unsigned int host_div = 0; 
     
    8283             type == ROAR_SOCKET_TYPE_UNIX ? "UNIX" : "INET", host, port); 
    8384 
    84  memset(&socket_addr, 0, sizeof(socket_addr)); 
    85  memset(&he,          0, sizeof(he)); 
     85 memset(&socket_addr   , 0, sizeof(socket_addr)); 
     86 memset(&socket_addr_un, 0, sizeof(socket_addr_un)); 
     87 memset(&he,             0, sizeof(he));               // FIXME: we have a valid pointer in here???? 
    8688 
    8789 
     
    109111  // hey! we have a socket... 
    110112 } else { 
     113  socket_addr_un.sun_family = AF_UNIX; 
     114  strncpy(socket_addr_un.sun_path, host, sizeof(socket_addr_un.sun_path) - 1); 
     115 
    111116  fh = roar_socket_new_unix(); 
    112   close(fh); 
    113   return -1; 
     117 
     118  if ( mode_func(fh, (struct sockaddr *)&socket_addr_un, sizeof(struct sockaddr_un)) == -1 ) { 
     119   ROAR_DBG("roar_socket_open(*): Can not connect/bind: %s", strerror(errno)); 
     120   close(fh); 
     121   return -1; 
     122  } 
    114123 } 
    115124 
  • roard/roard.c

    r44 r60  
    22 
    33#include "roard.h" 
     4 
     5char * server = ROAR_DEFAULT_SOCK_GLOBAL; // global server address 
    46 
    57void usage (void) { 
     
    3234        " -b  --bind            - IP/Hostname to bind to\n" 
    3335        " -s  --sock            - Filename for UNIX Domain Socket\n" 
     36        " -G  GROUP             - Sets the group for the UNIX Domain Socket, (default: audio)\n" 
     37        "                         You need the permittions to change the GID\n" 
    3438       ); 
    3539// printf("\n Options:\n\n"); 
     
    4044 int i; 
    4145 char * k; 
     46 char user_sock[80] = {0}; 
    4247 struct roar_audio_info sa; 
    4348 char * driver = NULL; 
    4449 char * device = NULL; 
    4550 char * opts   = NULL; 
    46  char * server = ROAR_DEFAULT_HOST; 
     51// char * server = ROAR_DEFAULT_SOCK_GLOBAL; 
    4752 int      port = ROAR_DEFAULT_PORT; 
    4853 int               drvid; 
     
    5156 char * s_opt  = NULL; 
    5257 int    s_prim = 0; 
     58 char * sock_grp = "audio"; 
     59 struct group * grp; 
    5360 DRIVER_USERDATA_T drvinst; 
    5461 struct roar_client * self = NULL; 
     
    6370 
    6471 g_sa = &sa; 
     72 
     73 
     74 if ( getuid() != 0 && getenv("HOME") ) { 
     75  snprintf(user_sock, 79, "%s/%s", getenv("HOME"), ROAR_DEFAULT_SOCK_USER); 
     76  server = user_sock; 
     77 } 
    6578 
    6679 if ( sources_init() == -1 ) { 
     
    113126  } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 ) { 
    114127   server = argv[++i]; 
     128  } else if ( strcmp(k, "-G") == 0 ) { 
     129   sock_grp = argv[++i]; 
    115130 
    116131  } else { 
     
    128143 } 
    129144 
     145 if ( *server == '/' ) { 
     146  if ( (grp = getgrnam(sock_grp)) == NULL ) { 
     147   ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno)); 
     148  } else { 
     149   chown(server, -1, grp->gr_gid); 
     150   if ( getuid() == 0 ) 
     151    chmod(server, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP); 
     152  } 
     153 } 
     154 
    130155 if ( output_buffer_init(&sa) == -1 ) { 
    131156  ROAR_ERR("Can not init output buffer!"); 
     
    185210void clean_quit_prep (void) { 
    186211 close(g_listen_socket); 
     212 
     213 if ( *server == '/' ) 
     214  unlink(server); 
     215 
     216 
    187217 sources_free(); 
    188218 streams_free(); 
Note: See TracChangeset for help on using the changeset viewer.