Index: roard/roard.c
===================================================================
--- roard/roard.c	(revision 1227)
+++ roard/roard.c	(revision 1486)
@@ -272,5 +272,7 @@
  char user_sock[80]  = {0};
  struct roar_audio_info sa;
+#ifdef ROAR_HAVE_FORK
  int    daemon       = 0;
+#endif
  int    realtime     = 0;
  int    sysclocksync = 0;
@@ -294,10 +296,22 @@
  char * sock_user = NULL;
  int    sock_type = ROAR_SOCKET_TYPE_UNKNOWN;
+#ifdef ROAR_HAVE_CHROOT
  char * chrootdir = NULL;
+#endif
+#if defined(ROAR_HAVE_SETGID) || defined(ROAR_HAVE_SETUID)
  int    setids    = 0;
+#endif
+#ifdef ROAR_HAVE_UNIX
  char * env_roar_proxy_backup;
+#endif
+#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
  struct group   * grp  = NULL;
+#endif
+#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
  struct passwd  * pwd  = NULL;
+#endif
+#ifdef ROAR_HAVE_GETSERVBYNAME
  struct servent * serv = NULL;
+#endif
  DRIVER_USERDATA_T drvinst;
  struct roar_client * self = NULL;
@@ -320,6 +334,6 @@
 
 
- if ( getuid() != 0 && getenv("HOME") ) {
-  snprintf(user_sock, 79, "%s/%s", getenv("HOME"), ROAR_DEFAULT_SOCK_USER);
+ if ( getuid() != 0 && getenv("HOME") != NULL ) {
+  snprintf(user_sock, 79, "%s/%s", (char*)getenv("HOME"), ROAR_DEFAULT_SOCK_USER);
   server = user_sock;
  }
@@ -366,5 +380,9 @@
 
   } else if ( strcmp(k, "--demon") == 0 || strcmp(k, "--daemon") == 0 ) {
+#ifdef ROAR_HAVE_FORK
    daemon = 1;
+#else
+   ROAR_ERR("--daemon not supported");
+#endif
   } else if ( strcmp(k, "--terminate") == 0 ) {
    g_terminate = 1;
@@ -374,9 +392,22 @@
    realtime++;
   } else if ( strcmp(k, "--chroot") == 0 ) {
+#ifdef ROAR_HAVE_CHROOT
    chrootdir = argv[++i];
+#else
+   ROAR_ERR("--chroot not supported");
+   i++;
+#endif
   } else if ( strcmp(k, "--setgid") == 0 ) {
+#ifdef ROAR_HAVE_SETGID
    setids |= R_SETGID;
+#else
+   ROAR_ERR("--setgid not supported");
+#endif
   } else if ( strcmp(k, "--setuid") == 0 ) {
+#ifdef ROAR_HAVE_SETUID
    setids |= R_SETUID;
+#else
+   ROAR_ERR("--setuid not supported");
+#endif
 
   } else if ( strcmp(k, "--list-cf") == 0 ) {
@@ -446,4 +477,5 @@
    errno = 0;
    if ( (port = atoi(argv[++i])) < 1 ) {
+#ifdef ROAR_HAVE_GETSERVBYNAME
     if ( (serv = getservbyname(argv[i], "tcp")) == NULL ) {
      ROAR_ERR("Unknown service: %s: %s", argv[i], strerror(errno));
@@ -454,4 +486,8 @@
             serv->s_name, ROAR_NET2HOST16(serv->s_port), serv->s_proto);
     port = ROAR_NET2HOST16(serv->s_port);
+#else
+    ROAR_ERR("invalite port number: %s", argv[i]);
+    return 1;
+#endif
    }
   } else if ( strcmp(k, "-b") == 0 || strcmp(k, "--bind") == 0 || strcmp(k, "--sock") == 0 ) {
@@ -509,5 +545,10 @@
    }
   } else if ( strcmp(k, "--close-fh") == 0 ) {
+#ifdef ROAR_HAVE_IO_POSIX
    close(atoi(argv[++i]));
+#else
+   i++;
+   ROAR_WARN("can not close file handle %s (closing not supported)", argv[i]);
+#endif
 
   } else if ( strcmp(k, "--standby") == 0 ) {
@@ -537,4 +578,5 @@
  if ( *server != 0 ) {
   if ( (g_listen_socket = roar_socket_listen(sock_type, server, port)) == -1 ) {
+#ifdef ROAR_HAVE_UNIX
    if ( *server == '/' ) {
     if ( (env_roar_proxy_backup = getenv("ROAR_PROXY")) != NULL ) {
@@ -557,4 +599,7 @@
      free(env_roar_proxy_backup);
     }
+#else
+   if (0) { // noop
+#endif
    } else {
     ROAR_ERR("Can not open listen socket!");
@@ -563,7 +608,10 @@
   }
 
+#if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX)
   if ( (grp = getgrnam(sock_grp)) == NULL ) {
    ROAR_ERR("Can not get GID for group %s: %s", sock_grp, strerror(errno));
   }
+#endif
+#if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX)
   if ( sock_user || (setids & R_SETUID) ) {
    if ( (pwd = getpwnam(sock_user)) == NULL ) {
@@ -571,5 +619,7 @@
    }
   }
-
+#endif
+
+#ifdef ROAR_HAVE_IO_POSIX
   if ( *server == '/' ) {
    if ( grp ) {
@@ -583,4 +633,5 @@
    }
   }
+#endif
  }
 
@@ -607,7 +658,10 @@
 
 
+ // we should handle this on microcontrollers, too.
+#if !defined(ROAR_TARGET_MICROCONTROLLER)
  signal(SIGINT,  on_sig_int);
  signal(SIGCHLD, on_sig_chld);
  signal(SIGPIPE, SIG_IGN);  // ignore broken pipes
+#endif
 
  if ( realtime ) {
@@ -616,8 +670,13 @@
 #endif
 
+#ifdef ROAR_HAVE_NICE
   errno = 0;
   nice(-5*realtime); // -5 for each --realtime
-  if ( errno )
-   ROAR_WARN("Can not decrease nice value by 5: %s", strerror(errno));
+  if ( errno ) {
+   ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
+  }
+#else
+  ROAR_WARN("Can not decrease nice value by %i: %s", 5*realtime, strerror(errno));
+#endif
 /*
 #ifdef __linux__
@@ -628,4 +687,5 @@
  }
 
+#ifdef ROAR_HAVE_SETGID
  if ( setids & R_SETGID ) {
   if ( setgroups(0, (const gid_t *) NULL) == -1 ) {
@@ -636,4 +696,5 @@
   }
  }
+#endif
 
 
@@ -650,4 +711,5 @@
  strcpy(self->name, "RoarAudio daemon internal");
 
+#ifdef ROAR_HAVE_FORK
  if ( daemon ) {
   close(ROAR_STDIN );
@@ -656,8 +718,10 @@
   setsid();
   if ( fork() )
-   _exit(0);
+   ROAR_U_EXIT(0);
   clients_set_pid(g_self_client, getpid()); // reset pid as it changed
  }
-
+#endif
+
+#ifdef ROAR_HAVE_CHROOT
  if (chrootdir) {
   if ( chroot(chrootdir) == -1 ) {
@@ -670,5 +734,7 @@
   }
  }
-
+#endif
+
+#ifdef ROAR_HAVE_SETUID
  if ( setids & R_SETUID ) {
   if ( !pwd || setuid(pwd->pw_uid) == -1 ) {
@@ -678,4 +744,5 @@
   clients_set_uid(g_self_client, getuid());
  }
+#endif
 
  // start main loop...
@@ -693,10 +760,14 @@
 
  if ( g_listen_socket != -1 ) {
+#ifdef ROAR_HAVE_IO_POSIX
   close(g_listen_socket);
+#endif // #else is useless because we are in void context.
 
   g_listen_socket = -1;
 
+#ifdef ROAR_HAVE_UNIX
   if ( *server == '/' )
    unlink(server);
+#endif
  }
 
