projects
/
umurmur.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Preparation for IPv6 support
[umurmur.git]
/
src
/
main.c
diff --git
a/src/main.c
b/src/main.c
index 10b9de3dce4bcdd923226dbf2a1816370d3fd10f..ebff0e523163b91fe99ae6594cbcf8bb2014f0d8 100644
(file)
--- a/
src/main.c
+++ b/
src/main.c
@@
-1,5
+1,5
@@
-/* Copyright (C) 2009-201
2
, Martin Johansson <martin@fatbob.nu>
- Copyright (C) 2005-201
2
, Thorvald Natvig <thorvald@natvig.com>
+/* Copyright (C) 2009-201
4
, Martin Johansson <martin@fatbob.nu>
+ Copyright (C) 2005-201
4
, Thorvald Natvig <thorvald@natvig.com>
All rights reserved.
All rights reserved.
@@
-54,10
+54,13
@@
#include "client.h"
#include "conf.h"
#include "version.h"
#include "client.h"
#include "conf.h"
#include "version.h"
+#include "config.h"
char system_string[64], version_string[64];
int bindport;
char system_string[64], version_string[64];
int bindport;
+int bindport6;
char *bindaddr;
char *bindaddr;
+char *bindaddr6;
void lockfile(const char *pidfile)
{
void lockfile(const char *pidfile)
{
@@
-68,7
+71,7
@@
void lockfile(const char *pidfile)
* unmodified if we cannot lock it.
*/
lfp = open(pidfile, O_WRONLY|O_CREAT, 0640);
* unmodified if we cannot lock it.
*/
lfp = open(pidfile, O_WRONLY|O_CREAT, 0640);
-
+
if (lfp < 0)
Log_fatal("Cannot open PID-file %s for writing", pidfile);
if (lfp < 0)
Log_fatal("Cannot open PID-file %s for writing", pidfile);
@@
-89,7
+92,7
@@
void lockfile(const char *pidfile)
}
snprintf(str,16,"%d\n", getpid());
}
snprintf(str,16,"%d\n", getpid());
- write(lfp, str, strlen(str)); /* record pid to lockfile */
+
(void)
write(lfp, str, strlen(str)); /* record pid to lockfile */
Log_info("PID-file: %s", pidfile);
/* If uMurmur ever starts to fork()+exec(), we don't want it to
Log_info("PID-file: %s", pidfile);
/* If uMurmur ever starts to fork()+exec(), we don't want it to
@@
-152,12
+155,12
@@
static void switch_user(void)
if (setuid(pwd->pw_uid))
Log_fatal("setuid() failed: %s", strerror(errno));
if (setuid(pwd->pw_uid))
Log_fatal("setuid() failed: %s", strerror(errno));
-
+
if (!grp)
grp = getgrgid(gid);
if (!grp)
Log_fatal("getgrgid() failed: %s", strerror(errno));
if (!grp)
grp = getgrgid(gid);
if (!grp)
Log_fatal("getgrgid() failed: %s", strerror(errno));
-
+
Log_info("Switch to user '%s' group '%s'", pwd->pw_name, grp->gr_name);
}
Log_info("Switch to user '%s' group '%s'", pwd->pw_name, grp->gr_name);
}
@@
-178,7
+181,7
@@
void signal_handler(int sig)
void daemonize()
{
int i;
void daemonize()
{
int i;
-
+
if (getppid() == 1)
return; /* already a daemon */
i = fork();
if (getppid() == 1)
return; /* already a daemon */
i = fork();
@@
-188,19
+191,19
@@
void daemonize()
}
if ( i > 0)
exit(0); /* parent exits */
}
if ( i > 0)
exit(0); /* parent exits */
-
+
/* child (daemon) continues */
setsid(); /* obtain a new process group */
for (i = getdtablesize(); i >= 0; --i)
close(i); /* close all descriptors */
/* child (daemon) continues */
setsid(); /* obtain a new process group */
for (i = getdtablesize(); i >= 0; --i)
close(i); /* close all descriptors */
-
+
i = open("/dev/null",O_RDWR);
i = open("/dev/null",O_RDWR);
- dup(i);
- dup(i);
-
+
(void)
dup(i);
+
(void)
dup(i);
+
umask(027); /* set newly created file permissions */
umask(027); /* set newly created file permissions */
- chdir("/");
-
+
(void)
chdir("/");
+
}
#ifdef POSIX_PRIORITY_SCHEDULING
}
#ifdef POSIX_PRIORITY_SCHEDULING
@@
-219,7
+222,8
@@
void setscheduler()
void printhelp()
{
void printhelp()
{
- printf("uMurmur version %s. Mumble protocol %d.%d.%d\n", UMURMUR_VERSION, PROTVER_MAJOR, PROTVER_MINOR, PROTVER_PATCH);
+ printf("uMurmur version %s ('%s'). Mumble protocol %d.%d.%d\n", UMURMUR_VERSION,
+ UMURMUR_CODENAME, PROTVER_MAJOR, PROTVER_MINOR, PROTVER_PATCH);
printf("Usage: umurmurd [-d] [-r] [-h] [-p <pidfile>] [-t] [-c <conf file>] [-a <addr>] [-b <port>]\n");
printf(" -d - Do not daemonize - run in foreground.\n");
#ifdef POSIX_PRIORITY_SCHEDULING
printf("Usage: umurmurd [-d] [-r] [-h] [-p <pidfile>] [-t] [-c <conf file>] [-a <addr>] [-b <port>]\n");
printf(" -d - Do not daemonize - run in foreground.\n");
#ifdef POSIX_PRIORITY_SCHEDULING
@@
-244,12
+248,12
@@
int main(int argc, char **argv)
char *conffile = NULL, *pidfile = NULL;
int c;
struct utsname utsbuf;
char *conffile = NULL, *pidfile = NULL;
int c;
struct utsname utsbuf;
-
+
/* Arguments */
#ifdef POSIX_PRIORITY_SCHEDULING
/* Arguments */
#ifdef POSIX_PRIORITY_SCHEDULING
- while ((c = getopt(argc, argv, "drp:c:a:
b
:ht")) != EOF) {
+ while ((c = getopt(argc, argv, "drp:c:a:
A:b:B
:ht")) != EOF) {
#else
#else
- while ((c = getopt(argc, argv, "dp:c:a:
b
:ht")) != EOF) {
+ while ((c = getopt(argc, argv, "dp:c:a:
A:b:B
:ht")) != EOF) {
#endif
switch(c) {
case 'c':
#endif
switch(c) {
case 'c':
@@
-261,9
+265,15
@@
int main(int argc, char **argv)
case 'a':
bindaddr = optarg;
break;
case 'a':
bindaddr = optarg;
break;
+ case 'A':
+ bindaddr6 = optarg;
+ break;
case 'b':
bindport = atoi(optarg);
break;
case 'b':
bindport = atoi(optarg);
break;
+ case 'B':
+ bindport6 = atoi(optarg);
+ break;
case 'd':
nodaemon = true;
break;
case 'd':
nodaemon = true;
break;
@@
-291,12
+301,12
@@
int main(int argc, char **argv)
else
exit(0);
}
else
exit(0);
}
-
+
/* Initialize the config subsystem early;
* switch_user() will need to read some config variables as well as logging.
*/
Conf_init(conffile);
/* Initialize the config subsystem early;
* switch_user() will need to read some config variables as well as logging.
*/
Conf_init(conffile);
-
+
/* Logging to terminal if not daemonizing, otherwise to syslog or log file.
*/
if (!nodaemon) {
/* Logging to terminal if not daemonizing, otherwise to syslog or log file.
*/
if (!nodaemon) {
@@
-310,10
+320,10
@@
int main(int argc, char **argv)
/* Reopen log file. If user switch results in access denied, we catch
* it early.
*/
/* Reopen log file. If user switch results in access denied, we catch
* it early.
*/
- Log_reset();
+ Log_reset();
}
else Log_init(true);
}
else Log_init(true);
-
+
signal(SIGCHLD, SIG_IGN); /* ignore child */
signal(SIGTSTP, SIG_IGN); /* ignore tty signals */
signal(SIGTTOU, SIG_IGN);
signal(SIGCHLD, SIG_IGN); /* ignore child */
signal(SIGTSTP, SIG_IGN); /* ignore tty signals */
signal(SIGTTOU, SIG_IGN);
@@
-321,7
+331,7
@@
int main(int argc, char **argv)
signal(SIGPIPE, SIG_IGN);
signal(SIGHUP, signal_handler); /* catch hangup signal */
signal(SIGTERM, signal_handler); /* catch kill signal */
signal(SIGPIPE, SIG_IGN);
signal(SIGHUP, signal_handler); /* catch hangup signal */
signal(SIGTERM, signal_handler); /* catch kill signal */
-
+
/* Build system string */
if (uname(&utsbuf) == 0) {
snprintf(system_string, 64, "%s %s", utsbuf.sysname, utsbuf.machine);
/* Build system string */
if (uname(&utsbuf) == 0) {
snprintf(system_string, 64, "%s %s", utsbuf.sysname, utsbuf.machine);
@@
-331,26
+341,28
@@
int main(int argc, char **argv)
snprintf(system_string, 64, "unknown unknown");
snprintf(version_string, 64, "unknown");
}
snprintf(system_string, 64, "unknown unknown");
snprintf(version_string, 64, "unknown");
}
-
+
/* Initializing */
SSLi_init();
Chan_init();
Client_init();
/* Initializing */
SSLi_init();
Chan_init();
Client_init();
+ Ban_init();
#ifdef POSIX_PRIORITY_SCHEDULING
if (realtime)
setscheduler();
#endif
#ifdef POSIX_PRIORITY_SCHEDULING
if (realtime)
setscheduler();
#endif
-
+
Server_run();
Server_run();
-
+
+ Ban_deinit();
SSLi_deinit();
Chan_free();
Log_free();
Conf_deinit();
SSLi_deinit();
Chan_free();
Log_free();
Conf_deinit();
-
+
if (pidfile != NULL)
unlink(pidfile);
if (pidfile != NULL)
unlink(pidfile);
-
+
return 0;
}
return 0;
}