| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
bbsd.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 |
| 15 |
* * |
* * |
| 16 |
***************************************************************************/ |
***************************************************************************/ |
| 17 |
|
|
| 18 |
|
#include "bbs.h" |
| 19 |
#include "common.h" |
#include "common.h" |
| 20 |
|
#include "io.h" |
| 21 |
|
#include <unistd.h> |
| 22 |
#include <signal.h> |
#include <signal.h> |
| 23 |
|
#include <sys/param.h> |
| 24 |
|
#include <sys/types.h> |
| 25 |
|
#include <sys/stat.h> |
| 26 |
|
|
| 27 |
void |
void |
| 28 |
init_daemon (void) |
init_daemon (void) |
| 42 |
else if (pid < 0) |
else if (pid < 0) |
| 43 |
exit (1); |
exit (1); |
| 44 |
|
|
| 45 |
for (i = 0; i < NOFILE; ++i) |
// for (i = 0; i < NOFILE; ++i) |
| 46 |
close (i); |
// close (i); |
| 47 |
chdir ("/tmp"); |
chdir (app_home_dir); |
| 48 |
umask (0); |
umask (0); |
| 49 |
|
|
| 50 |
signal(SIGCHLD,SIG_IGN); |
signal (SIGCHLD, SIG_IGN); |
| 51 |
|
|
| 52 |
return; |
return; |
| 53 |
} |
} |
| 54 |
|
|
| 55 |
|
int |
| 56 |
|
load_conf (const char *conf_file) |
| 57 |
|
{ |
| 58 |
|
char temp[256]; |
| 59 |
|
|
| 60 |
|
// Load configuration |
| 61 |
|
char c_name[256]; |
| 62 |
|
FILE *fin; |
| 63 |
|
|
| 64 |
|
if ((fin = fopen (conf_file, "r")) == NULL) |
| 65 |
|
{ |
| 66 |
|
log_error ("Open %s failed", conf_file); |
| 67 |
|
return -1; |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
while (fscanf (fin, "%s", c_name) != EOF) |
| 71 |
|
{ |
| 72 |
|
if (c_name[0] == '#') |
| 73 |
|
{ |
| 74 |
|
fgets (temp, 256, fin); |
| 75 |
|
continue; |
| 76 |
|
} |
| 77 |
|
fscanf (fin, "%*c"); |
| 78 |
|
if (strcmp (c_name, "bbs_id") == 0) |
| 79 |
|
{ |
| 80 |
|
fscanf (fin, "%s", BBS_id); |
| 81 |
|
} |
| 82 |
|
if (strcmp (c_name, "bbs_name") == 0) |
| 83 |
|
{ |
| 84 |
|
fscanf (fin, "%s", BBS_name); |
| 85 |
|
} |
| 86 |
|
if (strcmp (c_name, "bbs_server") == 0) |
| 87 |
|
{ |
| 88 |
|
fscanf (fin, "%s", BBS_server); |
| 89 |
|
} |
| 90 |
|
if (strcmp (c_name, "bbs_address") == 0) |
| 91 |
|
{ |
| 92 |
|
fscanf (fin, "%s", BBS_address); |
| 93 |
|
} |
| 94 |
|
if (strcmp (c_name, "bbs_port") == 0) |
| 95 |
|
{ |
| 96 |
|
fscanf (fin, "%ud", &BBS_port); |
| 97 |
|
} |
| 98 |
|
if (strcmp (c_name, "bbs_max_client") == 0) |
| 99 |
|
{ |
| 100 |
|
fscanf (fin, "%d", &BBS_max_client); |
| 101 |
|
} |
| 102 |
|
if (strcmp (c_name, "bbs_max_user") == 0) |
| 103 |
|
{ |
| 104 |
|
fscanf (fin, "%d", &BBS_max_user); |
| 105 |
|
} |
| 106 |
|
if (strcmp (c_name, "bbs_start_dt") == 0) |
| 107 |
|
{ |
| 108 |
|
int y = 0, m = 0, d = 0; |
| 109 |
|
fscanf (fin, "%d-%d-%d", &y, &m, &d); |
| 110 |
|
sprintf (BBS_start_dt, "%4dÄê%2dÔÂ%2dÈÕ", y, m, d); |
| 111 |
|
} |
| 112 |
|
if (strcmp (c_name, "db_host") == 0) |
| 113 |
|
{ |
| 114 |
|
fscanf (fin, "%s", DB_host); |
| 115 |
|
} |
| 116 |
|
if (strcmp (c_name, "db_username") == 0) |
| 117 |
|
{ |
| 118 |
|
fscanf (fin, "%s", DB_username); |
| 119 |
|
} |
| 120 |
|
if (strcmp (c_name, "db_password") == 0) |
| 121 |
|
{ |
| 122 |
|
fscanf (fin, "%s", DB_password); |
| 123 |
|
} |
| 124 |
|
if (strcmp (c_name, "db_database") == 0) |
| 125 |
|
{ |
| 126 |
|
fscanf (fin, "%s", DB_database); |
| 127 |
|
} |
| 128 |
|
} |
| 129 |
|
|
| 130 |
|
fclose (fin); |
| 131 |
|
|
| 132 |
|
return 0; |
| 133 |
|
} |