/[cvs]/eggdrop1.9/src/main.c
ViewVC logotype

Annotation of /eggdrop1.9/src/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.151 - (hide annotations) (download) (as text)
Wed Jun 11 08:37:39 2003 UTC (16 years, 4 months ago) by stdarg
Branch: MAIN
Changes since 1.150: +64 -34 lines
File MIME type: text/x-chdr
* guppy needed something to read on the bathroom
* new approach to create the initial user -- we prompt for the owner's handle
  when the bot starts with -m, and then generate a random password and print
  it out.

1 guppy 1.56 /*
2 tothwolf 1.117 * main.c --
3 guppy 1.56 *
4 tothwolf 1.117 * core event handling
5     * signal handling
6     * command line arguments
7 segfault 1.1 */
8 guppy 1.56 /*
9     * Copyright (C) 1997 Robey Pointer
10 wcc 1.128 * Copyright (C) 1999, 2000, 2001, 2002, 2003 Eggheads Development Team
11 guppy 1.56 *
12 fabian 1.14 * This program is free software; you can redistribute it and/or
13     * modify it under the terms of the GNU General Public License
14     * as published by the Free Software Foundation; either version 2
15     * of the License, or (at your option) any later version.
16 guppy 1.56 *
17 segfault 1.1 * This program is distributed in the hope that it will be useful,
18     * but WITHOUT ANY WARRANTY; without even the implied warranty of
19     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20     * GNU General Public License for more details.
21 guppy 1.56 *
22 segfault 1.1 * You should have received a copy of the GNU General Public License
23     * along with this program; if not, write to the Free Software
24 fabian 1.14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25     */
26 guppy 1.56 /*
27 segfault 1.1 * The author (Robey Pointer) can be reached at: robey@netcom.com
28 tothwolf 1.117 * NOTE: Robey is no longer working on this code, there is a discussion
29 guppy 1.60 * list available at eggheads@eggheads.org.
30 segfault 1.1 */
31 tothwolf 1.117
32     #ifndef lint
33 stdarg 1.151 static const char rcsid[] = "$Id: main.c,v 1.150 2003/06/08 03:21:23 stdarg Exp $";
34 tothwolf 1.117 #endif
35 segfault 1.1
36 stdarg 1.151 #include <ctype.h>
37 stdarg 1.145 #include <unistd.h>
38 stdarg 1.125 #include <eggdrop/eggdrop.h>
39 fabian 1.28 #include "main.h"
40 stdarg 1.133 #include "core_config.h"
41 fabian 1.27 #include <fcntl.h>
42 wcc 1.129 #ifdef TIME_WITH_SYS_TIME
43     # include <sys/time.h>
44     # include <time.h>
45     #else
46     # ifdef HAVE_SYS_TIME_H
47     # include <sys/time.h>
48     # else
49     # include <time.h>
50     # endif
51     #endif
52 stdarg 1.142 #include <sys/stat.h>
53 segfault 1.1 #include <errno.h>
54     #include <signal.h>
55     #include <netdb.h>
56     #include <setjmp.h>
57 ite 1.76 #include <locale.h>
58 stdarg 1.142 #include <ctype.h>
59 stdarg 1.145 #include <ltdl.h>
60 ite 1.76
61 fabian 1.27 #ifdef STOP_UAC /* osf/1 complains a lot */
62 segfault 1.1 #include <sys/sysinfo.h>
63     #define UAC_NOPRINT 0x00000001 /* Don't report unaligned fixups */
64     #endif
65 fabian 1.27 /* Some systems have a working sys/wait.h even though configure will
66     * decide it's not bsd compatable. Oh well.
67     */
68 guppy 1.49
69 fabian 1.43 #include "bg.h"
70 stdarg 1.85 #include "core_binds.h"
71 ite 1.105 #include "logfile.h"
72 drummer 1.71
73 poptix 1.62 #ifdef CYGWIN_HACKS
74     #include <windows.h>
75     #endif
76    
77 segfault 1.1 #ifndef _POSIX_SOURCE
78 fabian 1.27 /* Solaris needs this */
79 segfault 1.1 #define _POSIX_SOURCE 1
80     #endif
81    
82 ite 1.76 char egg_version[1024] = VERSION;
83     int egg_numver = VERSION_NUM;
84 segfault 1.1
85 ite 1.109 eggdrop_t *egg = NULL; /* Eggdrop's context */
86    
87 fabian 1.27 int default_flags = 0; /* Default user flags and */
88     int default_uflags = 0; /* Default userdefinied flags for people
89     who say 'hello' or for .adduser */
90    
91     int backgrd = 1; /* Run in the background? */
92     int con_chan = 0; /* Foreground: constantly display channel
93     stats? */
94     int term_z = 0; /* Foreground: use the terminal as a party
95     line? */
96 stdarg 1.134 char configfile[121] = "config.xml"; /* Name of the config file */
97 wcc 1.127 char helpdir[121] = "help/"; /* Directory of help files (if used) */
98     char textdir[121] = "text/"; /* Directory for text files that get dumped */
99 fabian 1.27 time_t online_since; /* Unix-time that the bot loaded up */
100     int make_userfile = 0; /* Using bot in make-userfile mode? (first
101     user to 'hello' becomes master) */
102 guppy 1.92 char pid_file[120]; /* Name of the file for the pid to be
103 fabian 1.27 stored in */
104     int save_users_at = 0; /* How many minutes past the hour to
105     save the userfile? */
106     char version[81]; /* Version info (long form) */
107     char ver[41]; /* Version info (short form) */
108     int use_stderr = 1; /* Send stuff to stderr instead of logfiles? */
109     int do_restart = 0; /* .restart has been called, restart asap */
110     int die_on_sighup = 0; /* die if bot receives SIGHUP */
111 guppy 1.52 int die_on_sigterm = 1; /* die if bot receives SIGTERM */
112 fabian 1.27 int resolve_timeout = 15; /* hostname/address lookup timeout */
113 guppy 1.72 char quit_msg[1024]; /* quit message */
114 fabian 1.27 time_t now; /* duh, now :) */
115 stdarg 1.108 egg_timeval_t egg_timeval_now; /* Same thing, but seconds and microseconds. */
116 fabian 1.27
117 fabian 1.44 void fatal(const char *s, int recoverable)
118 segfault 1.1 {
119     putlog(LOG_MISC, "*", "* %s", s);
120     flushlogs();
121     unlink(pid_file);
122 fabian 1.43 if (!recoverable) {
123     bg_send_quit(BG_ABORT);
124 segfault 1.1 exit(1);
125 fabian 1.43 }
126 segfault 1.1 }
127    
128     static void got_bus(int z)
129     {
130     fatal("BUS ERROR -- CRASHING!", 1);
131     #ifdef SA_RESETHAND
132     kill(getpid(), SIGBUS);
133     #else
134 fabian 1.43 bg_send_quit(BG_ABORT);
135 segfault 1.1 exit(1);
136     #endif
137     }
138    
139     static void got_segv(int z)
140     {
141     fatal("SEGMENT VIOLATION -- CRASHING!", 1);
142     #ifdef SA_RESETHAND
143     kill(getpid(), SIGSEGV);
144     #else
145 fabian 1.43 bg_send_quit(BG_ABORT);
146 segfault 1.1 exit(1);
147     #endif
148     }
149    
150     static void got_fpe(int z)
151     {
152     fatal("FLOATING POINT ERROR -- CRASHING!", 0);
153     }
154    
155     static void got_term(int z)
156     {
157 stdarg 1.85 check_bind_event("sigterm");
158 segfault 1.1 if (die_on_sigterm) {
159     fatal("TERMINATE SIGNAL -- SIGNING OFF", 0);
160     } else {
161     putlog(LOG_MISC, "*", "RECEIVED TERMINATE SIGNAL (IGNORING)");
162     }
163     }
164    
165     static void got_quit(int z)
166     {
167 stdarg 1.85 check_bind_event("sigquit");
168 segfault 1.1 putlog(LOG_MISC, "*", "RECEIVED QUIT SIGNAL (IGNORING)");
169     return;
170     }
171    
172     static void got_hup(int z)
173     {
174 stdarg 1.85 check_bind_event("sighup");
175 segfault 1.1 if (die_on_sighup) {
176     fatal("HANGUP SIGNAL -- SIGNING OFF", 0);
177     } else
178     putlog(LOG_MISC, "*", "Received HUP signal: rehashing...");
179     do_restart = -2;
180     return;
181     }
182    
183 guppy 1.101 /* Got ILL signal
184 fabian 1.27 */
185 segfault 1.1 static void got_ill(int z)
186     {
187 stdarg 1.85 check_bind_event("sigill");
188 fabian 1.10 }
189    
190 ite 1.114
191 wcc 1.135 static void print_version(void)
192 segfault 1.1 {
193 wcc 1.143 char x[1024];
194 ite 1.114
195     strlcpy(x, egg_version, sizeof x);
196     printf("%s\n", version);
197     }
198    
199 wcc 1.135 static void print_help(void)
200 ite 1.114 {
201     print_version ();
202     printf("\n\
203     Usage: %s [OPTIONS]... [FILE]\n", PACKAGE);
204     printf(_("\n\
205     -h, --help Print help and exit\n\
206     -v, --version Print version and exit\n\
207     -n, --foreground Don't go into the background (default=off)\n\
208     -c --channel-stats (with -n) Display channel stats every 10 seconds\n\
209     -t --terminal (with -n) Use terminal to simulate dcc-chat\n\
210     -m --make-userfile Userfile creation mode\n\
211 wcc 1.135 FILE optional config filename (default 'config.xml')\n"));
212 ite 1.114 printf("\n");
213     }
214 segfault 1.1
215 ite 1.114 static void do_args(int argc, char * const *argv)
216     {
217     int c;
218    
219     optarg = 0;
220     optind = 1;
221     opterr = 1;
222     optopt = '?';
223    
224     while (1) {
225     int option_index = 0;
226     static struct option long_options[] = {
227     { "help", 0, NULL, 'h' },
228     { "version", 0, NULL, 'v' },
229     { "load-module", 1, NULL, 'p' },
230     { "foreground", 0, NULL, 'n' },
231     { "channel-stats", 0, NULL, 'c' },
232     { "terminal", 0, NULL, 't' },
233     { "make-userfile", 0, NULL, 'm' },
234     { NULL, 0, NULL, 0 }
235     };
236    
237     c = getopt_long (argc, argv, "hvp:nctm", long_options, &option_index);
238    
239     if (c == -1) break;
240    
241     switch (c) {
242     case 'n':
243 segfault 1.1 backgrd = 0;
244 ite 1.114 break;
245    
246     case 'c':
247 segfault 1.1 con_chan = 1;
248     term_z = 0;
249 ite 1.114 break;
250    
251     case 't':
252 segfault 1.1 con_chan = 0;
253     term_z = 1;
254 ite 1.114 break;
255    
256     case 'm':
257 segfault 1.1 make_userfile = 1;
258 ite 1.114 break;
259    
260     case 'v':
261     print_version();
262 fabian 1.43 bg_send_quit(BG_ABORT);
263 segfault 1.1 exit(0);
264 ite 1.114 break; /* this should never be reached */
265    
266     case 'h':
267     print_help();
268 fabian 1.43 bg_send_quit(BG_ABORT);
269 segfault 1.1 exit(0);
270 ite 1.114 break; /* this should never be reached */
271    
272     case 0: /* Long option with no short option */
273     case '?': /* Invalid option. */
274     /* getopt_long() already printed an error message. */
275     bg_send_quit(BG_ABORT);
276     exit(1);
277    
278     default: /* bug: option not considered. */
279     fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
280     bg_send_quit(BG_ABORT);
281     exit(1);
282     break; /* this should never be reached */
283     }
284     }
285     if (optind < argc)
286     strlcpy(configfile, argv[optind], sizeof configfile);
287 segfault 1.1 }
288    
289 fabian 1.27 /* Timer info */
290     static int lastmin = 99;
291     static struct tm nowtm;
292 segfault 1.1
293 fabian 1.34 /* Called once a second.
294 fabian 1.27 */
295 stdarg 1.139 static int core_secondly()
296 segfault 1.1 {
297     static int cnt = 0;
298     int miltime;
299    
300 stdarg 1.145 check_bind_secondly();
301 segfault 1.1 cnt++;
302 tothwolf 1.79 memcpy(&nowtm, localtime(&now), sizeof(struct tm));
303 fabian 1.17 if (nowtm.tm_min != lastmin) {
304 segfault 1.1 int i = 0;
305    
306 fabian 1.27 /* Once a minute */
307 segfault 1.1 lastmin = (lastmin + 1) % 60;
308 stdarg 1.145 check_bind_event("minutely");
309     check_bind_time(&nowtm);
310 fabian 1.27 /* In case for some reason more than 1 min has passed: */
311 fabian 1.17 while (nowtm.tm_min != lastmin) {
312 fabian 1.27 /* Timer drift, dammit */
313 wcc 1.141 putlog(LOG_DEBUG, "*", "timer: drift (lastmin=%d, now=%d)", lastmin,
314     nowtm.tm_min);
315 segfault 1.1 i++;
316     lastmin = (lastmin + 1) % 60;
317 stdarg 1.145 check_bind_event("minutely");
318 segfault 1.1 }
319     if (i > 1)
320     putlog(LOG_MISC, "*", "(!) timer drift -- spun %d minutes", i);
321 fabian 1.17 miltime = (nowtm.tm_hour * 100) + (nowtm.tm_min);
322     if (((int) (nowtm.tm_min / 5) * 5) == (nowtm.tm_min)) { /* 5 min */
323 stdarg 1.145 check_bind_event("5minutely");
324 guppy 1.49 if (!miltime) { /* At midnight */
325     char s[25];
326 segfault 1.1
327 ite 1.111 strlcpy(s, ctime(&now), sizeof s);
328 fabian 1.4 putlog(LOG_ALL, "*", "--- %.11s%s", s, s + 20);
329 stdarg 1.145 check_bind_event("backup");
330     check_bind_event("daily");
331 segfault 1.1 }
332     }
333     }
334 stdarg 1.139 return(0);
335 segfault 1.1 }
336    
337 stdarg 1.130 void core_party_init();
338 stdarg 1.133 void core_config_init();
339 stdarg 1.140
340 stdarg 1.142 int file_check(const char *filename)
341     {
342     struct stat sbuf = {0};
343     int r;
344    
345     r = stat(filename, &sbuf);
346     if (r) return(-1);
347     errno = 0;
348     if (sbuf.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) return(-1);
349     return(0);
350     }
351    
352 segfault 1.1 int main(int argc, char **argv)
353     {
354     int xx, i;
355 stdarg 1.138 char s[25];
356 segfault 1.1 FILE *f;
357     struct sigaction sv;
358 stdarg 1.82 egg_timeval_t howlong;
359 stdarg 1.131 int timeout;
360 stdarg 1.137 void *config_root, *entry;
361 stdarg 1.134 char *modname, *scriptname;
362 segfault 1.1
363 tothwolf 1.81 #ifdef DEBUG
364 fabian 1.21 /* Make sure it can write core, if you make debug. Else it's pretty
365     * useless (dw)
366     */
367 fabian 1.15 {
368     #include <sys/resource.h>
369     struct rlimit cdlim;
370 fabian 1.21
371 fabian 1.15 cdlim.rlim_cur = RLIM_INFINITY;
372     cdlim.rlim_max = RLIM_INFINITY;
373 fabian 1.32 setrlimit(RLIMIT_CORE, &cdlim);
374 fabian 1.15 }
375     #endif
376 fabian 1.32
377 ite 1.99 #ifdef ENABLE_NLS
378 ite 1.76 setlocale(LC_MESSAGES, "");
379     bindtextdomain(PACKAGE, LOCALEDIR);
380     textdomain(PACKAGE);
381 ite 1.99 #endif
382 wcc 1.143
383 stdarg 1.145 /* Initialize ltdl. */
384     LTDL_SET_PRELOADED_SYMBOLS();
385     if (lt_dlinit()) {
386     printf("Fatal error initializing ltdl: %s\n", lt_dlerror());
387     return(-1);
388     }
389    
390 fabian 1.27 /* Version info! */
391 ite 1.114 snprintf(ver, sizeof ver, "%s v%s", PACKAGE, egg_version);
392 wcc 1.128 snprintf(version, sizeof version, "Eggdrop v%s (C) 1997 Robey Pointer (C) 2003 Eggheads",
393 guppy 1.56 egg_version);
394 fabian 1.27 /* Now add on the patchlevel (for Tcl) */
395 fabian 1.2 sprintf(&egg_version[strlen(egg_version)], " %u", egg_numver);
396 segfault 1.1 #ifdef STOP_UAC
397     {
398     int nvpair[2];
399    
400     nvpair[0] = SSIN_UACPROC;
401     nvpair[1] = UAC_NOPRINT;
402     setsysinfo(SSI_NVPAIRS, (char *) nvpair, 1, NULL, 0);
403     }
404     #endif
405 fabian 1.27
406     /* Set up error traps: */
407 segfault 1.1 sv.sa_handler = got_bus;
408     sigemptyset(&sv.sa_mask);
409     #ifdef SA_RESETHAND
410     sv.sa_flags = SA_RESETHAND;
411     #else
412     sv.sa_flags = 0;
413     #endif
414     sigaction(SIGBUS, &sv, NULL);
415     sv.sa_handler = got_segv;
416     sigaction(SIGSEGV, &sv, NULL);
417     #ifdef SA_RESETHAND
418     sv.sa_flags = 0;
419     #endif
420     sv.sa_handler = got_fpe;
421     sigaction(SIGFPE, &sv, NULL);
422     sv.sa_handler = got_term;
423     sigaction(SIGTERM, &sv, NULL);
424     sv.sa_handler = got_hup;
425     sigaction(SIGHUP, &sv, NULL);
426     sv.sa_handler = got_quit;
427     sigaction(SIGQUIT, &sv, NULL);
428     sv.sa_handler = SIG_IGN;
429     sigaction(SIGPIPE, &sv, NULL);
430     sv.sa_handler = got_ill;
431     sigaction(SIGILL, &sv, NULL);
432 fabian 1.27
433     /* Initialize variables and stuff */
434 stdarg 1.121 timer_update_now(&egg_timeval_now);
435 stdarg 1.108 now = egg_timeval_now.sec;
436 tothwolf 1.79 memcpy(&nowtm, localtime(&now), sizeof(struct tm));
437 fabian 1.17 lastmin = nowtm.tm_min;
438 poptix 1.63 srandom(now % (getpid() + getppid()));
439 ite 1.114
440     do_args(argc, argv);
441    
442 segfault 1.1 printf("\n%s\n", version);
443 guppy 1.93 printf(" *** WARNING: Do NOT run this DEVELOPMENT version for any purpose other than testing.\n\n");
444 guppy 1.53
445     /* Don't allow eggdrop to run as root */
446     if (((int) getuid() == 0) || ((int) geteuid() == 0))
447 ite 1.76 fatal(_("ERROR: Eggdrop will not run as root!"), 0);
448 stdarg 1.142
449     if (file_check(configfile)) {
450     if (errno) perror(configfile);
451     else fprintf(stderr, "ERROR\n\nCheck file permissions on your config file!\nMake sure other groups and users cannot read/write it.\n");
452     exit(-1);
453     }
454 guppy 1.53
455 stdarg 1.151 egg = eggdrop_new();
456     eggdrop_init();
457     core_config_init(configfile);
458     logfile_init();
459     if (core_config.userfile) user_load(core_config.userfile);
460     core_party_init();
461     core_binds_init();
462    
463     if (make_userfile) {
464     user_t *owner;
465     char handle[512], password[12];
466     int len;
467    
468     if (user_count() != 0) {
469     printf("\n\n\nYou are trying to create a new userfile, but the old one still exists (%s)!\n\nPlease remove the userfile, or do not pass the -m option.\n\n", core_config.userfile);
470     exit(1);
471     }
472    
473     printf("\n\n\nHello! I see you are creating a new userfile.\n\n");
474     printf("Let's create the owner account.\n\n");
475     do {
476     printf("Enter the owner handle: ");
477     fflush(stdout);
478     fgets(handle, sizeof(handle), stdin);
479     for (len = 0; handle[len]; len++) {
480     if (!ispunct(handle[len]) && !isalnum(handle[len])) break;
481     }
482     if (len == 0) {
483     printf("Come on, enter a real handle.\n\n");
484     }
485     } while (len <= 0);
486     handle[len] = 0;
487     owner = user_new(handle);
488     if (!owner) {
489     printf("Failed to create user record! Out of memory?\n\n");
490     exit(1);
491     }
492     user_rand_pass(password, sizeof(password));
493     user_set_pass(owner, password);
494     printf("Your owner handle is '%s' and your password is '%s' (without the quotes).\n\n", handle, password);
495     memset(password, 0, sizeof(password));
496     str_redup(&core_config.owner, handle);
497     core_config_save();
498     user_save(core_config.userfile);
499     }
500 stdarg 1.80
501 fabian 1.43 if (backgrd)
502     bg_prepare_split();
503 stdarg 1.80
504 ite 1.111 strlcpy(s, ctime(&now), sizeof s);
505 segfault 1.1 strcpy(&s[11], &s[20]);
506     putlog(LOG_ALL, "*", "--- Loading %s (%s)", ver, s);
507 stdarg 1.134
508 guppy 1.92 if (!pid_file[0])
509 stdarg 1.139 snprintf(pid_file, sizeof pid_file, "pid.%s", core_config.botname);
510 fabian 1.27
511     /* Check for pre-existing eggdrop! */
512 segfault 1.1 f = fopen(pid_file, "r");
513     if (f != NULL) {
514     fgets(s, 10, f);
515     xx = atoi(s);
516 fabian 1.27 kill(xx, SIGCHLD); /* Meaningless kill to determine if pid
517     is used */
518 segfault 1.1 if (errno != ESRCH) {
519 stdarg 1.139 printf(_("I detect %s already running from this directory.\n"), core_config.botname);
520 ite 1.73 printf(_("If this is incorrect, erase the %s\n"), pid_file);
521 fabian 1.43 bg_send_quit(BG_ABORT);
522 segfault 1.1 exit(1);
523     }
524     }
525 fabian 1.27
526 stdarg 1.151 /* Put the module directory in the ltdl search path. */
527     if (core_config.module_path) module_add_dir(core_config.module_path);
528    
529     /* Scan the autoload section of config. */
530     config_root = config_get_root("eggdrop");
531     for (i = 0; (entry = config_exists(config_root, "eggdrop", 0, "autoload", 0, "module", i, NULL)); i++) {
532     modname = NULL;
533     config_get_str(&modname, entry, NULL);
534     module_load(modname);
535     }
536     for (i = 0; (entry = config_exists(config_root, "eggdrop", 0, "autoload", 0, "script", i, NULL)); i++) {
537     scriptname = NULL;
538     config_get_str(&scriptname, entry, NULL);
539     script_load(scriptname);
540     }
541    
542 fabian 1.27 /* Move into background? */
543 segfault 1.1 if (backgrd) {
544 fabian 1.38 #ifndef CYGWIN_HACKS
545 fabian 1.43 bg_do_split();
546 fabian 1.38 } else { /* !backgrd */
547 fabian 1.5 #endif
548 fabian 1.38 xx = getpid();
549     if (xx != 0) {
550     FILE *fp;
551    
552     /* Write pid to file */
553     unlink(pid_file);
554     fp = fopen(pid_file, "w");
555     if (fp != NULL) {
556     fprintf(fp, "%u\n", xx);
557     if (fflush(fp)) {
558     /* Let the bot live since this doesn't appear to be a botchk */
559 ite 1.73 printf(_("* Warning! Could not write %s file!\n"), pid_file);
560 fabian 1.38 fclose(fp);
561     unlink(pid_file);
562     } else
563     fclose(fp);
564 fabian 1.27 } else
565 ite 1.73 printf(_("* Warning! Could not write %s file!\n"), pid_file);
566 fabian 1.38 #ifdef CYGWIN_HACKS
567 guppy 1.68 printf("Launched into the background (pid: %d)\n\n", xx);
568 fabian 1.38 #endif
569     }
570 segfault 1.1 }
571 stdarg 1.151
572 fabian 1.38
573     use_stderr = 0; /* Stop writing to stderr now */
574 segfault 1.1 if (backgrd) {
575 fabian 1.27 /* Ok, try to disassociate from controlling terminal (finger cross) */
576 fabian 1.5 #if HAVE_SETPGID && !defined(CYGWIN_HACKS)
577 segfault 1.1 setpgid(0, 0);
578     #endif
579 fabian 1.38 /* Tcl wants the stdin, stdout and stderr file handles kept open. */
580 segfault 1.1 freopen("/dev/null", "r", stdin);
581     freopen("/dev/null", "w", stdout);
582     freopen("/dev/null", "w", stderr);
583 poptix 1.62 #ifdef CYGWIN_HACKS
584     FreeConsole();
585     #endif
586 segfault 1.1 }
587 fabian 1.27
588 segfault 1.1 online_since = now;
589 stdarg 1.82 howlong.sec = 1;
590     howlong.usec = 0;
591 stdarg 1.144 timer_create_repeater(&howlong, "main loop", core_secondly);
592 segfault 1.1
593 wcc 1.141 putlog(LOG_DEBUG, "*", "main: entering loop");
594 stdarg 1.139 while (1) {
595     timer_update_now(&egg_timeval_now);
596     now = egg_timeval_now.sec;
597     random(); /* Woop, lets really jumble things */
598     timer_run();
599    
600     if (timer_get_shortest(&howlong)) {
601     timeout = 1000;
602     }
603     else {
604     timeout = howlong.sec * 1000 + howlong.usec / 1000;
605     }
606     sockbuf_update_all(timeout);
607 stdarg 1.150 garbage_run();
608 stdarg 1.131 }
609 segfault 1.1 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23