/[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.2 by sysadm, Mon Oct 18 08:44:54 2004 UTC Revision 1.16 by sysadm, Mon May 5 11:46:04 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 "database.h"
20    #include "bbs.h"
21  #include "common.h"  #include "common.h"
22    #include "log.h"
23    #include "io.h"
24    #include <string.h>
25    #include <stdlib.h>
26  #include <signal.h>  #include <signal.h>
27    #include <sys/param.h>
28    #include <sys/types.h>
29    #include <sys/stat.h>
30    #include <unistd.h>
31    
32  void  void init_daemon(void)
 init_daemon (void)  
33  {  {
34    int pid;          int pid;
   int i;  
35    
36    if (pid = fork ())          pid = fork();
     exit (0);  
   else if (pid < 0)  
     exit (1);  
37    
38    setsid ();          if (pid > 0) // Parent process
39            {
40                    exit(0);
41            }
42            else if (pid < 0) // Error
43            {
44                    exit(1);
45            }
46    
47            // Child process
48            setsid();
49    
50            pid = fork();
51    
52            if (pid > 0) // Parent process
53            {
54                    exit(0);
55            }
56            else if (pid < 0) // Error
57            {
58                    exit(1);
59            }
60    
61    if (pid = fork ())          // Child process
62      exit (0);          umask(022);
   else if (pid < 0)  
     exit (1);  
63    
64    for (i = 0; i < NOFILE; ++i)          return;
65      close (i);  }
66    chdir ("/tmp");  
67    umask (0);  int load_conf(const char *conf_file)
68    {
69            char temp[256];
70    
71            // Load configuration
72            char c_name[256];
73            FILE *fin;
74    
75            if ((fin = fopen(conf_file, "r")) == NULL)
76            {
77                    log_error("Open %s failed", conf_file);
78                    return -1;
79            }
80    
81            while (fscanf(fin, "%s", c_name) != EOF)
82            {
83                    if (c_name[0] == '#')
84                    {
85                            fgets(temp, 256, fin);
86                            continue;
87                    }
88                    fscanf(fin, "%*c");
89                    if (strcmp(c_name, "bbs_id") == 0)
90                    {
91                            fscanf(fin, "%s", BBS_id);
92                    }
93                    if (strcmp(c_name, "bbs_name") == 0)
94                    {
95                            fscanf(fin, "%s", BBS_name);
96                    }
97                    if (strcmp(c_name, "bbs_server") == 0)
98                    {
99                            fscanf(fin, "%s", BBS_server);
100                    }
101                    if (strcmp(c_name, "bbs_address") == 0)
102                    {
103                            fscanf(fin, "%s", BBS_address);
104                    }
105                    if (strcmp(c_name, "bbs_port") == 0)
106                    {
107                            fscanf(fin, "%ud", &BBS_port);
108                    }
109                    if (strcmp(c_name, "bbs_max_client") == 0)
110                    {
111                            fscanf(fin, "%d", &BBS_max_client);
112                    }
113                    if (strcmp(c_name, "bbs_max_user") == 0)
114                    {
115                            fscanf(fin, "%d", &BBS_max_user);
116                    }
117                    if (strcmp(c_name, "bbs_start_dt") == 0)
118                    {
119                            int y = 0, m = 0, d = 0;
120                            fscanf(fin, "%d-%d-%d", &y, &m, &d);
121                            snprintf(BBS_start_dt, sizeof(BBS_start_dt), "%4dÄê%2dÔÂ%2dÈÕ", y, m, d);
122                    }
123                    if (strcmp(c_name, "db_host") == 0)
124                    {
125                            fscanf(fin, "%s", DB_host);
126                    }
127                    if (strcmp(c_name, "db_username") == 0)
128                    {
129                            fscanf(fin, "%s", DB_username);
130                    }
131                    if (strcmp(c_name, "db_password") == 0)
132                    {
133                            fscanf(fin, "%s", DB_password);
134                    }
135                    if (strcmp(c_name, "db_database") == 0)
136                    {
137                            fscanf(fin, "%s", DB_database);
138                    }
139                    if (strcmp(c_name, "db_timezone") == 0)
140                    {
141                            fscanf(fin, "%s", DB_timezone);
142                    }
143            }
144    
145    signal (SIGCHLD, SIG_IGN);          fclose(fin);
146    
147    return;          return 0;
148  }  }


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

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