Index: main/asterisk.c =================================================================== --- main/asterisk.c (revision 254361) +++ main/asterisk.c (working copy) @@ -2703,7 +2703,7 @@ FILE *f; sigset_t sigs; int num; - int isroot = 1; + int isroot = 1, rundir_exists = 0; char *buf; char *runuser = NULL, *rungroup = NULL; @@ -2870,8 +2870,12 @@ /* It's common on some platforms to clear /var/run at boot. Create the * socket file directory before we drop privileges. */ - if (mkdir(ast_config_AST_RUN_DIR, 0755) && errno != EEXIST) { - ast_log(LOG_WARNING, "Unable to create socket file directory. Remote consoles will not be able to connect! (%s)\n", strerror(x)); + if (mkdir(ast_config_AST_RUN_DIR, 0755)) { + if (errno == EEXIST) { + rundir_exists = 1; + } else { + ast_log(LOG_WARNING, "Unable to create socket file directory. Remote consoles will not be able to connect! (%s)\n", strerror(x)); + } } #ifndef __CYGWIN__ @@ -2886,7 +2890,7 @@ ast_log(LOG_WARNING, "No such group '%s'!\n", rungroup); exit(1); } - if (chown(ast_config_AST_RUN_DIR, -1, gr->gr_gid)) { + if (!rundir_exists && chown(ast_config_AST_RUN_DIR, -1, gr->gr_gid)) { ast_log(LOG_WARNING, "Unable to chgrp run directory to %d (%s)\n", (int) gr->gr_gid, rungroup); } if (setgid(gr->gr_gid)) {