| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
init.c - description |
init.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Mon Oct 18 2004 |
begin : Mon Oct 18 2004 |
| 5 |
copyright : (C) 2004 by Leaflet |
copyright : (C) 2004 by Leaflet |
| 6 |
email : leaflet@leafok.com |
email : leaflet@leafok.com |
| 7 |
***************************************************************************/ |
***************************************************************************/ |
| 8 |
|
|
| 9 |
/*************************************************************************** |
/*************************************************************************** |
| 15 |
* * |
* * |
| 16 |
***************************************************************************/ |
***************************************************************************/ |
| 17 |
|
|
| 18 |
|
#include "init.h" |
| 19 |
#include "bbs.h" |
#include "bbs.h" |
| 20 |
#include "common.h" |
#include "common.h" |
| 21 |
|
#include "log.h" |
| 22 |
#include "io.h" |
#include "io.h" |
| 23 |
#include <unistd.h> |
#include <string.h> |
| 24 |
|
#include <stdlib.h> |
| 25 |
#include <signal.h> |
#include <signal.h> |
| 26 |
#include <sys/param.h> |
#include <sys/param.h> |
| 27 |
#include <sys/types.h> |
#include <sys/types.h> |
| 28 |
#include <sys/stat.h> |
#include <sys/stat.h> |
| 29 |
|
#include <unistd.h> |
| 30 |
|
|
| 31 |
void |
void init_daemon(void) |
|
init_daemon (void) |
|
| 32 |
{ |
{ |
| 33 |
int pid; |
int pid; |
| 34 |
int i; |
int i; |
| 35 |
|
|
| 36 |
if (pid = fork ()) |
if (pid = fork()) |
| 37 |
exit (0); |
exit(0); |
| 38 |
else if (pid < 0) |
else if (pid < 0) |
| 39 |
exit (1); |
exit(1); |
| 40 |
|
|
| 41 |
setsid (); |
setsid(); |
| 42 |
|
|
| 43 |
if (pid = fork ()) |
if (pid = fork()) |
| 44 |
exit (0); |
exit(0); |
| 45 |
else if (pid < 0) |
else if (pid < 0) |
| 46 |
exit (1); |
exit(1); |
| 47 |
|
|
| 48 |
// for (i = 0; i < NOFILE; ++i) |
umask(0); |
|
// close (i); |
|
|
chdir (app_home_dir); |
|
|
umask (0); |
|
| 49 |
|
|
| 50 |
signal (SIGCHLD, SIG_IGN); |
return; |
|
|
|
|
return; |
|
| 51 |
} |
} |
| 52 |
|
|
| 53 |
int |
int load_conf(const char *conf_file) |
|
load_conf (const char *conf_file) |
|
| 54 |
{ |
{ |
| 55 |
char temp[256]; |
char temp[256]; |
| 56 |
|
|
| 57 |
// Load configuration |
// Load configuration |
| 58 |
char c_name[256]; |
char c_name[256]; |
| 59 |
FILE *fin; |
FILE *fin; |
| 60 |
|
|
| 61 |
if ((fin = fopen (conf_file, "r")) == NULL) |
if ((fin = fopen(conf_file, "r")) == NULL) |
| 62 |
{ |
{ |
| 63 |
log_error ("Open %s failed", conf_file); |
log_error("Open %s failed", conf_file); |
| 64 |
return -1; |
return -1; |
| 65 |
} |
} |
| 66 |
|
|
| 67 |
while (fscanf (fin, "%s", c_name) != EOF) |
while (fscanf(fin, "%s", c_name) != EOF) |
| 68 |
{ |
{ |
| 69 |
if (c_name[0] == '#') |
if (c_name[0] == '#') |
| 70 |
{ |
{ |
| 71 |
fgets (temp, 256, fin); |
fgets(temp, 256, fin); |
| 72 |
continue; |
continue; |
| 73 |
} |
} |
| 74 |
fscanf (fin, "%*c"); |
fscanf(fin, "%*c"); |
| 75 |
if (strcmp (c_name, "bbs_id") == 0) |
if (strcmp(c_name, "bbs_id") == 0) |
| 76 |
{ |
{ |
| 77 |
fscanf (fin, "%s", BBS_id); |
fscanf(fin, "%s", BBS_id); |
| 78 |
} |
} |
| 79 |
if (strcmp (c_name, "bbs_name") == 0) |
if (strcmp(c_name, "bbs_name") == 0) |
| 80 |
{ |
{ |
| 81 |
fscanf (fin, "%s", BBS_name); |
fscanf(fin, "%s", BBS_name); |
| 82 |
} |
} |
| 83 |
if (strcmp (c_name, "bbs_server") == 0) |
if (strcmp(c_name, "bbs_server") == 0) |
| 84 |
{ |
{ |
| 85 |
fscanf (fin, "%s", BBS_server); |
fscanf(fin, "%s", BBS_server); |
| 86 |
} |
} |
| 87 |
if (strcmp (c_name, "bbs_address") == 0) |
if (strcmp(c_name, "bbs_address") == 0) |
| 88 |
{ |
{ |
| 89 |
fscanf (fin, "%s", BBS_address); |
fscanf(fin, "%s", BBS_address); |
| 90 |
} |
} |
| 91 |
if (strcmp (c_name, "bbs_port") == 0) |
if (strcmp(c_name, "bbs_port") == 0) |
| 92 |
{ |
{ |
| 93 |
fscanf (fin, "%ud", &BBS_port); |
fscanf(fin, "%ud", &BBS_port); |
| 94 |
} |
} |
| 95 |
if (strcmp (c_name, "bbs_max_client") == 0) |
if (strcmp(c_name, "bbs_max_client") == 0) |
| 96 |
{ |
{ |
| 97 |
fscanf (fin, "%d", &BBS_max_client); |
fscanf(fin, "%d", &BBS_max_client); |
| 98 |
} |
} |
| 99 |
if (strcmp (c_name, "bbs_max_user") == 0) |
if (strcmp(c_name, "bbs_max_user") == 0) |
| 100 |
{ |
{ |
| 101 |
fscanf (fin, "%d", &BBS_max_user); |
fscanf(fin, "%d", &BBS_max_user); |
| 102 |
} |
} |
| 103 |
if (strcmp (c_name, "bbs_start_dt") == 0) |
if (strcmp(c_name, "bbs_start_dt") == 0) |
| 104 |
{ |
{ |
| 105 |
int y = 0, m = 0, d = 0; |
int y = 0, m = 0, d = 0; |
| 106 |
fscanf (fin, "%d-%d-%d", &y, &m, &d); |
fscanf(fin, "%d-%d-%d", &y, &m, &d); |
| 107 |
sprintf (BBS_start_dt, "%4d年%2d月%2d日", y, m, d); |
sprintf(BBS_start_dt, "%4d年%2d月%2d日", y, m, d); |
| 108 |
} |
} |
| 109 |
if (strcmp (c_name, "db_host") == 0) |
if (strcmp(c_name, "db_host") == 0) |
| 110 |
{ |
{ |
| 111 |
fscanf (fin, "%s", DB_host); |
fscanf(fin, "%s", DB_host); |
| 112 |
} |
} |
| 113 |
if (strcmp (c_name, "db_username") == 0) |
if (strcmp(c_name, "db_username") == 0) |
| 114 |
{ |
{ |
| 115 |
fscanf (fin, "%s", DB_username); |
fscanf(fin, "%s", DB_username); |
| 116 |
} |
} |
| 117 |
if (strcmp (c_name, "db_password") == 0) |
if (strcmp(c_name, "db_password") == 0) |
| 118 |
{ |
{ |
| 119 |
fscanf (fin, "%s", DB_password); |
fscanf(fin, "%s", DB_password); |
| 120 |
} |
} |
| 121 |
if (strcmp (c_name, "db_database") == 0) |
if (strcmp(c_name, "db_database") == 0) |
| 122 |
{ |
{ |
| 123 |
fscanf (fin, "%s", DB_database); |
fscanf(fin, "%s", DB_database); |
| 124 |
|
} |
| 125 |
|
if (strcmp(c_name, "db_timezone") == 0) |
| 126 |
|
{ |
| 127 |
|
fscanf(fin, "%s", DB_timezone); |
| 128 |
|
} |
| 129 |
} |
} |
|
} |
|
| 130 |
|
|
| 131 |
fclose (fin); |
fclose(fin); |
| 132 |
|
|
| 133 |
return 0; |
return 0; |
| 134 |
} |
} |