summaryrefslogtreecommitdiffstats
path: root/mbbsd/mbbsd.c
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-10-21 04:03:13 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-10-21 04:03:13 +0800
commit600422d4c70829782cde54cd6b27fc25d6a24871 (patch)
tree7a671585c841e317e182ae5eac356a0dc062979f /mbbsd/mbbsd.c
parentdac02d5bd1e21c5dae7308cdaf1ceb782e41d78b (diff)
downloadpttbbs-600422d4c70829782cde54cd6b27fc25d6a24871.tar
pttbbs-600422d4c70829782cde54cd6b27fc25d6a24871.tar.gz
pttbbs-600422d4c70829782cde54cd6b27fc25d6a24871.tar.bz2
pttbbs-600422d4c70829782cde54cd6b27fc25d6a24871.tar.lz
pttbbs-600422d4c70829782cde54cd6b27fc25d6a24871.tar.xz
pttbbs-600422d4c70829782cde54cd6b27fc25d6a24871.tar.zst
pttbbs-600422d4c70829782cde54cd6b27fc25d6a24871.zip
single daemon for all ports
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3228 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/mbbsd.c')
-rw-r--r--mbbsd/mbbsd.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c
index 15625061..38716ad0 100644
--- a/mbbsd/mbbsd.c
+++ b/mbbsd/mbbsd.c
@@ -1490,45 +1490,59 @@ daemon_login(int argc, char *argv[], char *envp[])
int msock, csock; /* socket for Master and Child */
FILE *fp;
int listen_port = 23;
- int len_of_sock_addr, overloading = 0;
+ int len_of_sock_addr, overloading = 0, i;
char buf[256];
#if OVERLOADBLOCKFDS
int blockfd[OVERLOADBLOCKFDS];
- int i, nblocked = 0;
+ int nblocked = 0;
#endif
struct sockaddr_in xsin;
xsin.sin_family = AF_INET;
/* setup standalone */
-
start_daemon();
-
signal_restart(SIGCHLD, reapchild);
/* choose port */
- if (argc == 1)
+ if( argc < 2 )
listen_port = 3006;
- else if (argc >= 2)
+ else{
+#ifdef NO_FORK
listen_port = atoi(argv[1]);
-
- snprintf(margs, sizeof(margs), "%s %d ", argv[0], listen_port);
+#else
+ for( i = 1 ; i < (argc - 1) ; ++i )
+ switch( fork() ){
+ case -1:
+ perror("fork()");
+ break;
+ case 0:
+ goto out;
+ default:
+ break;
+ }
+ out:
+ listen_port = atoi(argv[i]);
+#endif
+ }
/* port binding */
- msock = bind_port(listen_port);
- if (msock < 0) {
+ if( (msock = bind_port(listen_port)) < 0 ){
syslog(LOG_INFO, "mbbsd bind_port failed.\n");
exit(1);
}
- initsetproctitle(argc, argv, envp);
-#ifndef VALGRIND
- setproctitle("%s: listening ", margs);
-#endif
/* Give up root privileges: no way back from here */
setgid(BBSGID);
setuid(BBSUID);
chdir(BBSHOME);
+ /* proctitle */
+ initsetproctitle(argc, argv, envp);
+#ifndef VALGRIND
+ snprintf(margs, sizeof(margs), "%s %d ", argv[0], listen_port);
+ setproctitle("%s: listening ", margs);
+#endif
+
/* It's better to do something before fork */
#ifdef CONVERT
big2gb_init(NULL);
@@ -1540,7 +1554,6 @@ daemon_login(int argc, char *argv[], char *envp[])
#ifndef NO_FORK
#ifdef PRE_FORK
if( listen_port == 23 ){ // only pre-fork in port 23
- int i;
for( i = 0 ; i < PRE_FORK ; ++i )
if( fork() <= 0 )
break;
@@ -1548,7 +1561,8 @@ daemon_login(int argc, char *argv[], char *envp[])
#endif
#endif
- snprintf(buf, sizeof(buf), "run/mbbsd.%d.%d.pid", listen_port, (int)getpid());
+ snprintf(buf, sizeof(buf),
+ "run/mbbsd.%d.%d.pid", listen_port, (int)getpid());
if ((fp = fopen(buf, "w"))) {
fprintf(fp, "%d\n", (int)getpid());
fclose(fp);