/[LeafOK_CVS]/lbbs/src/init.c
ViewVC logotype

Diff of /lbbs/src/init.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 by sysadm, Mon Oct 18 08:16:49 2004 UTC Revision 1.13 by sysadm, Wed Apr 30 09:18:19 2025 UTC
# Line 1  Line 1 
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
6      email                : leaflet@leafok.com          email                : leaflet@leafok.com
7   ***************************************************************************/   ***************************************************************************/
8    
9  /***************************************************************************  /***************************************************************************
# Line 15  Line 15 
15   *                                                                         *   *                                                                         *
16   ***************************************************************************/   ***************************************************************************/
17    
18    #include "init.h"
19    #include "bbs.h"
20  #include "common.h"  #include "common.h"
21    #include "log.h"
22    #include "io.h"
23    #include <string.h>
24    #include <stdlib.h>
25  #include <signal.h>  #include <signal.h>
26    #include <sys/param.h>
27    #include <sys/types.h>
28    #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 ("/tmp");  
   umask (0);  
49    
50    signal(SIGCHLD,SIG_IGN);          return;
51    }
52    
53    int load_conf(const char *conf_file)
54    {
55            char temp[256];
56    
57            // Load configuration
58            char c_name[256];
59            FILE *fin;
60    
61            if ((fin = fopen(conf_file, "r")) == NULL)
62            {
63                    log_error("Open %s failed", conf_file);
64                    return -1;
65            }
66    
67            while (fscanf(fin, "%s", c_name) != EOF)
68            {
69                    if (c_name[0] == '#')
70                    {
71                            fgets(temp, 256, fin);
72                            continue;
73                    }
74                    fscanf(fin, "%*c");
75                    if (strcmp(c_name, "bbs_id") == 0)
76                    {
77                            fscanf(fin, "%s", BBS_id);
78                    }
79                    if (strcmp(c_name, "bbs_name") == 0)
80                    {
81                            fscanf(fin, "%s", BBS_name);
82                    }
83                    if (strcmp(c_name, "bbs_server") == 0)
84                    {
85                            fscanf(fin, "%s", BBS_server);
86                    }
87                    if (strcmp(c_name, "bbs_address") == 0)
88                    {
89                            fscanf(fin, "%s", BBS_address);
90                    }
91                    if (strcmp(c_name, "bbs_port") == 0)
92                    {
93                            fscanf(fin, "%ud", &BBS_port);
94                    }
95                    if (strcmp(c_name, "bbs_max_client") == 0)
96                    {
97                            fscanf(fin, "%d", &BBS_max_client);
98                    }
99                    if (strcmp(c_name, "bbs_max_user") == 0)
100                    {
101                            fscanf(fin, "%d", &BBS_max_user);
102                    }
103                    if (strcmp(c_name, "bbs_start_dt") == 0)
104                    {
105                            int y = 0, m = 0, d = 0;
106                            fscanf(fin, "%d-%d-%d", &y, &m, &d);
107                            sprintf(BBS_start_dt, "%4dÄê%2dÔÂ%2dÈÕ", y, m, d);
108                    }
109                    if (strcmp(c_name, "db_host") == 0)
110                    {
111                            fscanf(fin, "%s", DB_host);
112                    }
113                    if (strcmp(c_name, "db_username") == 0)
114                    {
115                            fscanf(fin, "%s", DB_username);
116                    }
117                    if (strcmp(c_name, "db_password") == 0)
118                    {
119                            fscanf(fin, "%s", DB_password);
120                    }
121                    if (strcmp(c_name, "db_database") == 0)
122                    {
123                            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);
132    
133    return;          return 0;
134  }  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1