Changeset 5369:dfc6cbfe8025 in roaraudio for libroar/socket.c


Ignore:
Timestamp:
12/21/11 01:08:49 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

moved +fork out of socket.c into basic.c, now also support +fork=d:daemon and +fork=!daemon_command

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/socket.c

    r5364 r5369  
    795795#endif 
    796796 } else if ( type == ROAR_SOCKET_TYPE_FORK ) { 
    797   return roar_socket_open_fork(mode, host, port); 
     797  roar_err_set(ROAR_ERROR_INVAL); 
     798  return -1; 
    798799 } else if ( type == ROAR_SOCKET_TYPE_FILE ) { 
    799800  return roar_socket_open_file(mode, host, port); 
     
    817818 
    818819 return fh; 
    819 } 
    820  
    821 int roar_socket_open_fork  (int mode, const char * host, int port) { 
    822 #if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER) 
    823  char * daemonimage; 
    824  int socks[2]; 
    825  int r; 
    826  char fhstr[8]; 
    827  
    828  if ( mode == MODE_LISTEN ) 
    829   return -1; 
    830  
    831  // TODO: FIXME: we should move this into the config structure. 
    832  daemonimage = getenv("ROAR_DAEMONIMAGE"); 
    833  
    834  if ( daemonimage == NULL || *daemonimage == 0 ) 
    835   daemonimage = "roard"; 
    836  
    837  if ( socketpair(AF_UNIX, SOCK_STREAM, 0, socks) == -1 ) { 
    838   return -1; 
    839  } 
    840  
    841  r = fork(); 
    842  
    843  if ( r == -1 ) { // error! 
    844   ROAR_ERR("roar_socket_open_fork(*): Can not fork: %s", strerror(errno)); 
    845   close(socks[0]); 
    846   close(socks[1]); 
    847   return -1; 
    848  } else if ( r == 0 ) { // we are the child 
    849   close(socks[0]); 
    850  
    851   close(ROAR_STDIN ); // we do not want roard to have any standard input 
    852   close(ROAR_STDOUT); // STDOUT is also not needed, so we close it, 
    853                       // but STDERR we keep open for error messages. 
    854  
    855   snprintf(fhstr, 7, "%i", socks[1]); 
    856  
    857   execlp(daemonimage, daemonimage, "--no-listen", "--client-fh", fhstr, (_LIBROAR_GOOD_CAST char*)NULL); 
    858  
    859   // we are still alive? 
    860   ROAR_ERR("roar_socket_open_fork(*): alive after exec(), that's bad!"); 
    861   _exit(1); 
    862  } else { // we are the parent 
    863   close(socks[1]); 
    864   return socks[0]; 
    865  } 
    866  
    867  return -1; 
    868 #else 
    869  ROAR_ERR("roar_socket_open_fork(*): There is no UNIX Domain Socket support in win32, download a real OS."); 
    870  return -1; 
    871 #endif 
    872820} 
    873821 
Note: See TracChangeset for help on using the changeset viewer.