Changeset 4722:469ca094d1fa in roaraudio


Ignore:
Timestamp:
01/16/11 19:54:29 (11 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

Delay --stop and --shutdown to after reading of all args.
adding listen sockets and outputs is disabled in stop and shutdown mode,
even for --new-sock and -oN.
Restart now does try to restart on position of --restart and retry later
after reading all args if restart at position of --restart failed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/roard.c

    r4710 r4722  
    2525 
    2626#include "roard.h" 
     27 
     28enum action { 
     29 START, 
     30 STOP, 
     31 RESTART, 
     32 RESTART_RETRY, 
     33 SHUTDOWN 
     34}; 
    2735 
    2836#ifdef ROAR_SUPPORT_LISTEN 
     
    416424#endif 
    417425 
    418  if ( roar_connect(&con, server) == -1 ) { 
     426 if ( roar_simple_connect(&con, server, "roard") == -1 ) { 
    419427  return -1; 
    420428 } 
     
    15001508#endif 
    15011509#ifdef ROAR_HAVE_MAIN_ARGS 
     1510 enum action action = START; 
    15021511 int i; 
    15031512 char * k; 
     
    17371746  } else if ( strcmp(k, "--start") == 0 ) { 
    17381747   // this is a no op 
     1748   action = START; 
    17391749  } else if ( strcmp(k, "--restart") == 0 ) { 
     1750   action = RESTART; 
    17401751#ifdef ROAR_SUPPORT_LISTEN 
    17411752   if ( restart_server(sock_addr, 1) == -1 ) { 
    1742     ROAR_WARN("Can not terminate old server (not running at %s?), tring to continue anyway", sock_addr); 
     1753    ROAR_WARN("Can not terminate old server (not running at %s?), will retry later.", sock_addr); 
     1754    action = RESTART_RETRY; 
    17431755   } 
    17441756#else 
     
    17461758#endif 
    17471759  } else if ( strcmp(k, "--shutdown") == 0 ) { 
    1748 #ifdef ROAR_SUPPORT_LISTEN 
    1749    if ( restart_server(sock_addr, 1) == -1 ) { 
    1750     ROAR_WARN("Can not terminate old server (not running at %s?)", sock_addr); 
    1751     return 1; 
    1752    } 
    1753    return 0; 
    1754 #else 
    1755    ROAR_ERR("--shutdown not supported"); 
    1756    return 1; 
    1757 #endif 
     1760   action = SHUTDOWN; 
    17581761  } else if ( strcmp(k, "--stop") == 0 ) { 
    1759 #ifdef ROAR_SUPPORT_LISTEN 
    1760    if ( restart_server(sock_addr, 0) == -1 ) { 
    1761     ROAR_WARN("Can not stop old server (not running at %s?)", sock_addr); 
    1762     return 1; 
    1763    } 
    1764    return 0; 
    1765 #else 
    1766    ROAR_ERR("--stop not supported"); 
    1767    return 1; 
    1768 #endif 
     1762   action = STOP; 
    17691763 
    17701764 
     
    19041898   o_prim = 1; 
    19051899  } else if ( strcmp(k, "-oN") == 0 ) { 
    1906    if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 ) 
    1907     o_count++; 
    1908  
    1909    o_drv  = o_dev = o_opts = NULL; 
    1910    o_prim = 0; 
     1900   if ( action == START || action == RESTART ) { 
     1901    if ( add_output(o_drv, o_dev, o_opts, o_prim, o_count) != -1 ) 
     1902     o_count++; 
     1903 
     1904    o_drv  = o_dev = o_opts = NULL; 
     1905    o_prim = 0; 
     1906   } 
    19111907 
    19121908  } else if ( strcmp(k, "-s") == 0 || strcmp(k, "--source") == 0 ) { 
     
    22812277  } else if ( strcmp(k, "--new-sock") == 0 ) { 
    22822278#ifdef ROAR_SUPPORT_LISTEN 
    2283    if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) { 
    2284     ROAR_ERR("Can not open listen socket!"); 
    2285     return 1; 
     2279   if ( action == START || action == RESTART ) { 
     2280    if ( add_listen(sock_addr, port, sock_type, sock_user, sock_grp, sock_proto, sock_dir, &sock_info) != 0 ) { 
     2281     ROAR_ERR("Can not open listen socket!"); 
     2282     return 1; 
     2283    } 
    22862284   } 
    22872285#endif 
     
    23482346#endif 
    23492347 
     2348#ifdef ROAR_HAVE_MAIN_ARGS 
     2349 switch (action) { 
     2350  case START: 
     2351    // NO-OP. 
     2352   break; 
     2353  case RESTART: 
     2354    // NO-OP, done before. 
     2355   break; 
     2356  case STOP: 
     2357#ifdef ROAR_SUPPORT_LISTEN 
     2358    if ( restart_server(sock_addr, 0) == -1 ) { 
     2359     ROAR_WARN("Can not stop old server (not running at %s?)", sock_addr); 
     2360     return 1; 
     2361    } 
     2362    return 0; 
     2363#else 
     2364    ROAR_ERR("--stop not supported"); 
     2365    return 1; 
     2366#endif 
     2367   break; 
     2368  case SHUTDOWN: 
     2369#ifdef ROAR_SUPPORT_LISTEN 
     2370    if ( restart_server(sock_addr, 1) == -1 ) { 
     2371     ROAR_WARN("Can not terminate old server (not running at %s?)", sock_addr); 
     2372     return 1; 
     2373    } 
     2374    return 0; 
     2375#else 
     2376    ROAR_ERR("--shutdown not supported"); 
     2377    return 1; 
     2378#endif 
     2379   break; 
     2380  case RESTART_RETRY: 
     2381#ifdef ROAR_SUPPORT_LISTEN 
     2382    if ( restart_server(sock_addr, 1) == -1 ) { 
     2383     ROAR_WARN("Can not terminate old server (again) (not running at %s?), tring to continue anyway", sock_addr); 
     2384     action = RESTART; 
     2385    } 
     2386#endif 
     2387   break; 
     2388 } 
     2389#endif 
     2390 
    23502391#ifndef DEBUG 
    23512392 // notify dbg if requested, if in DEBUG mode 
Note: See TracChangeset for help on using the changeset viewer.