From 549acaede7b62e4fcbb7c0bbc8b5e8f5ac420d9b Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Mon, 16 Sep 2013 13:43:01 +0000
Subject: code cleanups and fixes (new gcc and clang)


diff --git a/client_list.c b/client_list.c
index 8c3a73d..ff86878 100644
--- a/client_list.c
+++ b/client_list.c
@@ -20,13 +20,14 @@
  */
 
 #include <stdlib.h>
+#include <unistd.h>
 
 #include "client_list.h"
 #include "datatypes.h"
 
 client_t* client_get_last(client_t* first)
 {
-  if(!first) 
+  if(!first)
     return NULL;
 
   while(first->next) {
@@ -61,7 +62,7 @@ int client_add(client_t** first, int fd)
     *first = new_client;
     return 0;
   }
-    
+
   client_get_last(*first)->next = new_client;
 
   return 0;
@@ -69,7 +70,7 @@ int client_add(client_t** first, int fd)
 
 void client_remove(client_t** first, int fd)
 {
-  if(!first || !(*first)) 
+  if(!first || !(*first))
     return;
 
   client_t* deletee = *first;
@@ -98,7 +99,7 @@ client_t* client_find(client_t* first, int fd)
 {
   if(!first)
     return NULL;
-  
+
   while(first) {
     if(first->fd == fd)
       return first;
@@ -110,7 +111,7 @@ client_t* client_find(client_t* first, int fd)
 
 void client_clear(client_t** first)
 {
-  if(!first || !(*first)) 
+  if(!first || !(*first))
     return;
 
   while(*first) {
diff --git a/daemon.h b/daemon.h
index 22e0ac0..2b3b00a 100644
--- a/daemon.h
+++ b/daemon.h
@@ -13,7 +13,7 @@
  *  message authentication based on the methodes used by SRTP.  It is
  *  intended to deliver a generic, scaleable and secure solution for
  *  tunneling and relaying of packets of any protocol.
- *  
+ *
  *
  *  Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
  *
@@ -105,7 +105,6 @@ int priv_drop(priv_info_t* priv)
   return 0;
 }
 
-
 int do_chroot(const char* chrootdir)
 {
   if(getuid() != 0) {
@@ -122,6 +121,7 @@ int do_chroot(const char* chrootdir)
     log_printf(ERROR, "can't change to /: %s", strerror(errno));
     return -1;
   }
+  return 0;
 }
 
 void daemonize()
@@ -170,4 +170,3 @@ void daemonize()
 }
 
 #endif
-
diff --git a/datatypes.h b/datatypes.h
index e0d1774..e38d121 100644
--- a/datatypes.h
+++ b/datatypes.h
@@ -22,6 +22,7 @@
 #ifndef RHCTL_datatypes_h_INCLUDED
 #define RHCTL_datatypes_h_INCLUDED
 
+#define _GNU_SOURCE
 #include <stdint.h>
 #include <arpa/inet.h>
 
diff --git a/heartbeatclient.c b/heartbeatclient.c
index e3b9e8e..162660b 100644
--- a/heartbeatclient.c
+++ b/heartbeatclient.c
@@ -71,9 +71,9 @@ int process_serial(read_buffer_t* buffer, int serial_fd, u_int32_t* time, int le
       if(buffer->offset > 0 && buffer->buf[buffer->offset-1] == '\r')
         buffer->buf[buffer->offset-1] = 0;
 
-      if(strlen(buffer->buf)) {
+      if(strlen((char *)(buffer->buf))) {
         log_printf(INFO, "heartbeat: '%s'", buffer->buf);
-        *time = 0;  
+        *time = 0;
         if(led_pipe_fd >= 0) {
           char buf = '1';
           ret = write(led_pipe_fd, &buf, 1);
@@ -81,7 +81,7 @@ int process_serial(read_buffer_t* buffer, int serial_fd, u_int32_t* time, int le
             log_printf(WARNING, "write to led process pipe returned with error: %s", strerror(errno));
         }
       }
-        
+
       buffer->offset = 0;
       return 0;
     }
@@ -160,7 +160,7 @@ int main_loop(int serial_fd, int cmd_fd, int led_pipe_fd, options_t* opt)
     if(FD_ISSET(sig_fd, &tmpfds))
       if(signal_handle())
         return_value = 1;
-   
+
     if(reset_flag) {
       active = 1;
       time = 0;
@@ -205,14 +205,14 @@ int led_process(int pipe_fd, int led_fd)
       log_printf(ERROR, "led_process: read returned with error: %s", strerror(errno));
       break;
     }
-    
+
     buf = '1';
     ret = write(led_fd, &buf, 1);
     if(ret == -1 && errno != EAGAIN) {
       log_printf(ERROR, "led_process: write returned with error: %s", strerror(errno));
       break;
     }
-      
+
     timeout.tv_sec = 0;
     timeout.tv_usec = 100000;
     ret = select(0, NULL, NULL, NULL, &timeout);
@@ -220,7 +220,7 @@ int led_process(int pipe_fd, int led_fd)
       log_printf(ERROR, "led_process: select returned with error: %s", strerror(errno));
       break;
     }
-    
+
     buf = '0';
     ret = write(led_fd, &buf, 1);
     if(ret == -1 && errno != EAGAIN) {
@@ -236,7 +236,7 @@ int start_led_process(options_t* opt)
   int pipefd[2];
   int led_fd;
   pid_t cpid;
-  
+
   led_fd = open(opt->led_filename_, O_WRONLY);
   if(led_fd < 0) {
     log_printf(ERROR, "led_process: open() failed: %s", strerror(errno));
@@ -248,7 +248,7 @@ int start_led_process(options_t* opt)
     close(led_fd);
     return -2;
   }
-  
+
   cpid = fork();
   if (cpid == -1) {
     log_printf(ERROR, "led_process: fork() failed: %s", strerror(errno));
@@ -257,7 +257,7 @@ int start_led_process(options_t* opt)
     close(led_fd);
     return -2;
   }
-  
+
   if (cpid == 0) {
     close(pipefd[1]);
     return led_process(pipefd[0], led_fd);
@@ -306,7 +306,7 @@ int main(int argc, char* argv[])
         case -4: fprintf(stderr, "this log target is only allowed once: '%s', exitting\n", tmp->string_); break;
         default: fprintf(stderr, "syntax error near: '%s', exitting\n", tmp->string_); break;
         }
-        
+
         options_clear(&opt);
         log_close();
         exit(ret);
@@ -384,7 +384,7 @@ int main(int argc, char* argv[])
     cmd_fd = connect_command_socket(opt.command_sock_);
     if(cmd_fd < 0)
       ret = 3;
-    else {    
+    else {
       serial_fd = open(opt.serial_dev_, O_RDWR | O_NOCTTY);
       if(serial_fd < 0)
         ret = 2;
@@ -395,14 +395,14 @@ int main(int argc, char* argv[])
         else
           ret = main_loop(serial_fd, cmd_fd, led_pipe_fd, &opt);
       }
-    }      
+    }
 
     if(ret == 2 || ret == 3) {
-      if(ret == 2) 
+      if(ret == 2)
         log_printf(ERROR, "%s error, trying to reopen in 5 seconds..", opt.serial_dev_);
       if(ret == 3)
         log_printf(ERROR, "socket error, trying to reconnect in 5 seconds..");
-      
+
       if(cmd_fd > 0)
         close(cmd_fd);
       if(serial_fd > 0)
diff --git a/l_cmd.c b/l_cmd.c
index 2d2a139..338b377 100644
--- a/l_cmd.c
+++ b/l_cmd.c
@@ -22,6 +22,7 @@
 #include <lua.h>
 #include <lauxlib.h>
 
+#include <unistd.h>
 #include <sys/socket.h>
 #include <errno.h>
 
@@ -33,6 +34,7 @@
 #include "command_queue.h"
 #include "client_list.h"
 #include "log.h"
+#include "utils.h"
 
 int cmd_fd;
 read_buffer_t cmd_buffer;
@@ -43,7 +45,7 @@ static int l_cmd_getfd(lua_State *L)
     luaL_error(L, "can't retreive signal fd");
 
   lua_pushliteral(L, "fd");
-  lua_gettable(L, -2);  
+  lua_gettable(L, -2);
   return 1;
 }
 
@@ -84,7 +86,7 @@ static int cmd_recv_data(lua_State* L)
     if(cmd_buffer.buf[cmd_buffer.offset] == '\n') {
       cmd_buffer.buf[cmd_buffer.offset] = 0;
 
-      lua_pushstring(L, cmd_buffer.buf);
+      lua_pushstring(L, (char *)(cmd_buffer.buf));
 
       ret = lua_pcall(L, 1, 1, 0);
       if(ret) {
@@ -96,7 +98,7 @@ static int cmd_recv_data(lua_State* L)
         }
         return -1;
       }
-      
+
       ret = lua_tointeger(L, 1);
       cmd_buffer.offset = 0;
       break;
@@ -130,20 +132,20 @@ static int l_cmd_send_string(lua_State* L)
 
   if(ret > 0)
     ret = 0;
-  
+
   lua_pushinteger(L, ret);
   return 1;
 }
 
 static const struct luaL_reg cmd_funcs [] = {
-  { "init", l_cmd_init }, 
+  { "init", l_cmd_init },
   { "recv_data", l_cmd_recv_data },
   { "send_string", l_cmd_send_string },
   { NULL, NULL }
 };
 
 
-LUALIB_API int luaopen_cmd(lua_State *L) 
+LUALIB_API int luaopen_cmd(lua_State *L)
 {
   luaL_register(L, LUA_CMDLIBNAME, cmd_funcs);
   return 1;
diff --git a/log.c b/log.c
index 43a0a5a..6f8f622 100644
--- a/log.c
+++ b/log.c
@@ -13,7 +13,7 @@
  *  message authentication based on the methodes used by SRTP.  It is
  *  intended to deliver a generic, scaleable and secure solution for
  *  tunneling and relaying of packets of any protocol.
- *  
+ *
  *
  *  Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
  *
@@ -39,6 +39,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <ctype.h>
 
 #define SYSLOG_NAMES
 #include <syslog.h>
@@ -84,7 +85,7 @@ int log_targets_target_exists(log_targets_t* targets, log_target_type_t type)
     if(tmp->type_ == type)
       return 1;
     tmp = tmp->next_;
-  }  
+  }
   return 0;
 }
 
@@ -147,7 +148,7 @@ int log_targets_add(log_targets_t* targets, const char* conf)
     log_target_t* tmp = targets->first_;
     while(tmp->next_)
       tmp = tmp->next_;
-    
+
     tmp->next_ = new_target;
   }
   return 0;
@@ -246,8 +247,8 @@ void log_print_hex_dump(log_prio_t prio, const u_int8_t* buf, u_int32_t len)
     int offset = snprintf(msg, MSG_LENGTH_MAX, "dump(%d): ", len);
     if(offset < 0)
       return;
-    u_int8_t* ptr = &msg[offset];
-    
+    char* ptr = &msg[offset];
+
     for(i=0; i < len; i++) {
       if(((i+1)*3) >= (MSG_LENGTH_MAX - offset))
         break;
diff --git a/options.h b/options.h
index 38d6e3f..fa3db16 100644
--- a/options.h
+++ b/options.h
@@ -29,10 +29,10 @@
 #include <termios.h>
 
 enum mode_enum { MODE_MASTER, MODE_STANDBY };
-typedef enum mode_enum mode_t;
+typedef enum mode_enum switchctl_mode_t;
 
 enum channel_enum { CHAN_MAIN, CHAN_MUSIC };
-typedef enum channel_enum channel_t;
+typedef enum channel_enum switchctl_channel_t;
 
 struct options_struct {
 /* common */
@@ -48,9 +48,9 @@ struct options_struct {
   speed_t baudrate_;
 
 /* switchctl */
-  mode_t mode_;
-  channel_t channel_master_;
-  channel_t channel_standby_;
+  switchctl_mode_t mode_;
+  switchctl_channel_t channel_master_;
+  switchctl_channel_t channel_standby_;
   char* conf_file_;
   char* switch_dev_;
   key_value_storage_t alias_table_;
diff --git a/serialclient.c b/serialclient.c
index 538df13..cee4ec5 100644
--- a/serialclient.c
+++ b/serialclient.c
@@ -50,7 +50,7 @@ int process_data(int src_fd, int dest_fd)
     return ret;
 
   log_printf(DEBUG, "read %d bytes from fd (%d)", ret, src_fd);
-  
+
   int len = ret;
   int offset = 0;
   for(;;) {
@@ -89,8 +89,8 @@ int main_loop(int serial_fd, int cmd_fd, options_t* opt)
   int return_value = 0;
   if(opt->type_) {
     char* tmp;
-    asprintf(&tmp, "type %s\n", opt->type_);
-    if(!tmp) {
+    int len = asprintf(&tmp, "type %s\n", opt->type_);
+    if(len < 0) {
       log_printf(ERROR, "memory error at init");
       return_value = -2;
     }
@@ -123,7 +123,7 @@ int main_loop(int serial_fd, int cmd_fd, options_t* opt)
     if(FD_ISSET(sig_fd, &tmpfds))
       if(signal_handle())
         return_value = 1;
-   
+
     if(FD_ISSET(serial_fd, &tmpfds))
       return_value = process_data(serial_fd, cmd_fd);
 
@@ -175,7 +175,7 @@ int main(int argc, char* argv[])
         case -4: fprintf(stderr, "this log target is only allowed once: '%s', exitting\n", tmp->string_); break;
         default: fprintf(stderr, "syntax error near: '%s', exitting\n", tmp->string_); break;
         }
-        
+
         options_clear(&opt);
         log_close();
         exit(ret);
@@ -237,7 +237,7 @@ int main(int argc, char* argv[])
     cmd_fd = connect_command_socket(opt.command_sock_);
     if(cmd_fd < 0)
       ret = 3;
-    else {    
+    else {
       serial_fd = open(opt.serial_dev_, O_RDWR | O_NOCTTY);
       if(serial_fd < 0)
         ret = 2;
@@ -248,14 +248,14 @@ int main(int argc, char* argv[])
         else
           ret = main_loop(serial_fd, cmd_fd, &opt);
       }
-    }      
+    }
 
     if(ret == 2 || ret == 3) {
-      if(ret == 2) 
+      if(ret == 2)
         log_printf(ERROR, "%s error, trying to reopen in 5 seconds..", opt.serial_dev_);
       if(ret == 3)
         log_printf(ERROR, "socket error, trying to reconnect in 5 seconds..");
-      
+
       if(cmd_fd > 0)
         close(cmd_fd);
       if(serial_fd > 0)
diff --git a/sig_handler.c b/sig_handler.c
index ed4c140..0645f3c 100644
--- a/sig_handler.c
+++ b/sig_handler.c
@@ -13,7 +13,7 @@
  *  message authentication based on the methodes used by SRTP.  It is
  *  intended to deliver a generic, scaleable and secure solution for
  *  tunneling and relaying of packets of any protocol.
- *  
+ *
  *
  *  Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
  *
@@ -41,6 +41,7 @@
 #include <fcntl.h>
 #include <sys/select.h>
 #include <errno.h>
+#include <string.h>
 
 #include "sig_handler.h"
 
diff --git a/switchctl.c b/switchctl.c
index cb54077..7463eb7 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -41,14 +41,15 @@ int send_command(int switch_fd, cmd_t* cmd)
 {
   if(!cmd)
     return -1;
-  
+
   char* c = NULL;
   switch(cmd->cmd) {
   case SWITCH:
   case CHANNEL: c = cmd->param; break;
   case STATUS: c = "*0SL"; break;
+  default: break;
   }
-  
+
   if(c == NULL)
     return 0;
 
@@ -97,7 +98,7 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int
       log_printf(INFO, "silently ignoring request from inactive system (%s)", c->type == MASTER ? "master" : "standby");
       return 0;
     }
-  
+
     if(!param) {
       log_printf(INFO, "ignoring switch command without parameter");
       send_response(fd, "EEE: switch: missing parameter");
@@ -172,7 +173,7 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int
         free(cmd_param);
         return 0;
       }
-      
+
       ch_nr[0] = ch_tmp[0];
       ch_nr[1] = ch_tmp[1];
     }
@@ -180,7 +181,7 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int
   }
 
   int ret = cmd_push(cmd_q, fd, cmd_id, cmd_param);
-  if(cmd_param) 
+  if(cmd_param)
     free(cmd_param);
   if(ret)
     return ret;
@@ -204,7 +205,7 @@ int process_cmd_request(const char* cmd, cmd_id_t cmd_id, const char* param, int
     log_printf(DEBUG, "sent status to %d additional listeners", listener_cnt);
   }
 
-  log_printf(NOTICE, "command: %s", cmd); 
+  log_printf(NOTICE, "command: %s", cmd);
 
   return 0;
 }
@@ -262,7 +263,7 @@ int process_cmd_channel(const char* cmd, const char* param, int fd, cmd_t **cmd_
     return 0;
   }
 
-  channel_t old_channel;
+  switchctl_channel_t old_channel;
   if(c->type == MASTER)
     old_channel = opt->channel_master_;
   else
@@ -319,7 +320,7 @@ int process_cmd_channel(const char* cmd, const char* param, int fd, cmd_t **cmd_
     return ret;
   }
 
-  log_printf(NOTICE, "command: %s", cmd); 
+  log_printf(NOTICE, "command: %s", cmd);
 
   return 0;
 }
@@ -359,7 +360,7 @@ void process_cmd_type(const char* param, int fd, client_t* client_lst)
 
 int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, client_t* client_lst)
 {
-  mode_t old_mode = opt->mode_;
+  switchctl_mode_t old_mode = opt->mode_;
 
   if(param) {
     if(!strncmp(param, "master", 6))
@@ -388,7 +389,7 @@ int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, c
         log_printf(ERROR, "EEE: mode: old config is illegal?!");
         return 0;
       }
-      
+
       char* ch_to = NULL;
       if(opt->mode_ == MODE_MASTER && opt->channel_master_ == CHAN_MAIN)
         ch_to = "master_main";
@@ -403,13 +404,13 @@ int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, c
         log_printf(ERROR, "EEE: mode: current config is illegal?!");
         return 0;
       }
-      
+
       int ret = crossfade(ch_from, ch_to, fd, cmd_q, opt);
       if(ret) {
         opt->mode_ = old_mode;
         if(ret > 0)
           return 0;
-        
+
         return ret;
       }
     }
@@ -421,8 +422,8 @@ int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, c
 
   if(old_mode != opt->mode_) {
     char* mode_str;
-    asprintf(&mode_str, "new Mode: %s", opt->mode_ == MODE_MASTER ? "master" : "standby");
-    if(mode_str) {
+    int len = asprintf(&mode_str, "new Mode: %s", opt->mode_ == MODE_MASTER ? "master" : "standby");
+    if(len > 0) {
       log_printf(NOTICE, "%s", mode_str);
       client_t* client;
       int listener_cnt = 0;
@@ -439,7 +440,7 @@ int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, c
 
   return 0;
 }
- 
+
 void process_cmd_listen(const char* param, int fd, client_t* client_lst)
 {
   client_t* listener = client_find(client_lst, fd);
@@ -497,7 +498,7 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
 
   if(!cmd_q || !cmd)
     return -1;
-  
+
   cmd_id_t cmd_id;
   if(!strncmp(cmd, "switch", 6))
     cmd_id = SWITCH;
@@ -520,13 +521,13 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
     return 0;
   }
   char* param = strchr(cmd, ' ');
-  if(param) 
+  if(param)
     param++;
 
   if(cmd_id == SWITCH || cmd_id == CHANNEL || cmd_id == MODE) {
     char* resp;
-    asprintf(&resp, "Request: %s", cmd);
-    if(resp) {
+    int len = asprintf(&resp, "Request: %s", cmd);
+    if(len > 0) {
       char* linefeed = strchr(resp, '\n');
       if(linefeed) linefeed[0] = 0;
       client_t* client;
@@ -543,7 +544,7 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
   }
 
   switch(cmd_id) {
-  case SWITCH: 
+  case SWITCH:
   case STATUS: {
     int ret = process_cmd_request(cmd, cmd_id, param, fd, cmd_q, client_lst, opt);
     if(ret)
@@ -565,14 +566,14 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
   }
   case LOG: {
     if(param && param[0])
-      log_printf(NOTICE, "ext msg: %s", param); 
+      log_printf(NOTICE, "ext msg: %s", param);
     else
       log_printf(DEBUG, "ignoring empty ext log message");
     break;
   }
   case LISTEN: process_cmd_listen(param, fd, client_lst); break;
   }
-  
+
   return 0;
 }
 
@@ -590,7 +591,7 @@ int nonblock_recvline(read_buffer_t* buffer, int fd, cmd_t** cmd_q, client_t* cl
 
     if(buffer->buf[buffer->offset] == '\n') {
       buffer->buf[buffer->offset] = 0;
-      ret = process_cmd(buffer->buf, fd, cmd_q, client_lst, opt);
+      ret = process_cmd((char *)(buffer->buf), fd, cmd_q, client_lst, opt);
       buffer->offset = 0;
       break;
     }
@@ -607,12 +608,12 @@ int nonblock_recvline(read_buffer_t* buffer, int fd, cmd_t** cmd_q, client_t* cl
 }
 
 #define SEND_TO_LISTENER(STRING, LEN, FLAG)                                            \
-        if(!strncmp(buffer->buf, STRING, LEN)) {                                       \
+        if(!strncmp((char *)(buffer->buf), STRING, LEN)) {                                       \
           client_t* client;                                                            \
           int listener_cnt = 0;                                                        \
           for(client = client_lst; client; client = client->next)                      \
             if(client->FLAG && client->fd != cmd_fd) {                                 \
-              send_response(client->fd, buffer->buf);                                  \
+              send_response(client->fd, (char *)(buffer->buf));                                  \
               listener_cnt++;                                                          \
             }                                                                          \
           log_printf(DEBUG, "sent message to %d additional listeners", listener_cnt);  \
@@ -649,26 +650,26 @@ int process_switch(read_buffer_t* buffer, int switch_fd, cmd_t **cmd_q, client_t
       if(buffer->offset > 0 && buffer->buf[buffer->offset-1] == '\r')
         buffer->buf[buffer->offset-1] = 0;
 
-      if(strlen(buffer->buf)) {
-        log_printf(NOTICE, "switch-firmware: '%s'", buffer->buf);
-        
+      if(strlen((char *)(buffer->buf))) {
+        log_printf(NOTICE, "switch-firmware: '%s'", (char *)(buffer->buf));
+
         int cmd_fd = -1;
         if(cmd_q && (*cmd_q)) {
           cmd_fd = (*cmd_q)->fd;
-          send_response(cmd_fd, buffer->buf);
+          send_response(cmd_fd, (char *)(buffer->buf));
         }
-        
+
         SEND_TO_LISTENER("S0L", 3, status_listener);
         SEND_TO_LISTENER("S0P", 3, gpi_listener);
         SEND_TO_LISTENER("S0O", 3, oc_listener);
         SEND_TO_LISTENER("S0R", 3, relay_listener);
         SEND_TO_LISTENER("S0S", 3, silence_listener);
 
-        if((!strncmp(buffer->buf, "RRR", 3)) || 
-           (!strncmp(buffer->buf, "EEE", 3)))
+        if((!strncmp((char *)(buffer->buf), "RRR", 3)) ||
+           (!strncmp((char *)(buffer->buf), "EEE", 3)))
           cmd_pop(cmd_q);
       }
-        
+
       buffer->offset = 0;
       return 0;
     }
@@ -707,12 +708,12 @@ int main_loop(int switch_fd, int cmd_listen_fd, options_t* opt)
 
   int return_value = 0;
 
-  char* channel;
+  char* channel = "unknown";
   if(opt->mode_ == MODE_MASTER && opt->channel_master_ == CHAN_MAIN) channel = "master_main";
   else if(opt->mode_ == MODE_MASTER && opt->channel_master_ == CHAN_MUSIC) channel = "master_music";
   else if(opt->mode_ == MODE_STANDBY && opt->channel_standby_ == CHAN_MAIN) channel = "standby_main";
   else if(opt->mode_ == MODE_STANDBY && opt->channel_standby_ == CHAN_MUSIC) channel = "standby_music";
-  
+
   char* cmd_param = strdup("*0M1*0ii1");
   char* ch_nr = key_value_storage_find(&opt->alias_table_, channel);
   if(!ch_nr || ch_nr[0] == 0 || ch_nr[1] == 0 || ch_nr[2] != 0) {
@@ -757,7 +758,7 @@ int main_loop(int switch_fd, int cmd_listen_fd, options_t* opt)
         break;
       }
     }
-   
+
     if(FD_ISSET(switch_fd, &tmpfds)) {
       return_value = process_switch(&switch_buffer, switch_fd, &cmd_q, client_lst);
       if(return_value)
@@ -770,7 +771,7 @@ int main_loop(int switch_fd, int cmd_listen_fd, options_t* opt)
         log_printf(ERROR, "accept returned with error: %s", strerror(errno));
         return_value = -1;
         break;
-      }  
+      }
       log_printf(DEBUG, "new command connection (fd=%d)", new_fd);
       FD_SET(new_fd, &readfds);
       max_fd = (max_fd < new_fd) ? new_fd : max_fd;
@@ -853,7 +854,7 @@ int main(int argc, char* argv[])
         case -4: fprintf(stderr, "this log target is only allowed once: '%s', exitting\n", tmp->string_); break;
         default: fprintf(stderr, "syntax error near: '%s', exitting\n", tmp->string_); break;
         }
-        
+
         options_clear(&opt);
         log_close();
         exit(ret);
@@ -915,7 +916,7 @@ int main(int argc, char* argv[])
     log_close();
     exit(-1);
   }
-  
+
   int switch_fd = 0;
   for(;;) {
     switch_fd = open(opt.switch_dev_, O_RDWR | O_NOCTTY);
-- 
cgit v0.10.2