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


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

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