source: src/router/rc/init.c @ 10749

Last change on this file since 10749 was 10749, checked in by BrainSlayer, 5 years ago

fixes for WPAPSK/WPA2PSK

File size: 17.9 KB
Line 
1
2#include <stdio.h>
3#include <stdlib.h>
4#include <errno.h>
5#include <paths.h>
6#include <signal.h>
7#include <stdarg.h>
8#include <string.h>
9#include <termios.h>
10#include <unistd.h>
11#include <limits.h>
12#include <sys/fcntl.h>
13#include <sys/ioctl.h>
14#include <sys/mount.h>
15#include <sys/reboot.h>
16#include <sys/types.h>
17#include <sys/wait.h>
18#include <sys/time.h>
19
20#include <shutils.h>
21#include <utils.h>
22#include <bcmnvram.h>
23#include "rc.h"
24#include <cyutils.h>
25#include <revision.h>
26
27#define loop_forever() do { sleep(1); } while (1)
28#define SHELL "/bin/login"
29#define _PATH_CONSOLE   "/dev/console"
30
31#define start_service(a) eval("startservice",a);
32#define start_services() eval("startservices");
33#define start_single_service() eval("start_single_service");
34#define stop_service(a) eval("stopservice",a);
35#define stop_services() eval("stopservices");
36#define startstop(a) eval("startstop",a);
37
38static void set_term( int fd )
39{
40    struct termios tty;
41
42    tcgetattr( fd, &tty );
43
44    /*
45     * set control chars
46     */
47    tty.c_cc[VINTR] = 3;        /* C-c */
48    tty.c_cc[VQUIT] = 28;       /* C-\ */
49    tty.c_cc[VERASE] = 127;     /* C-? */
50    tty.c_cc[VKILL] = 21;       /* C-u */
51    tty.c_cc[VEOF] = 4;         /* C-d */
52    tty.c_cc[VSTART] = 17;      /* C-q */
53    tty.c_cc[VSTOP] = 19;       /* C-s */
54    tty.c_cc[VSUSP] = 26;       /* C-z */
55
56    /*
57     * use line dicipline 0
58     */
59    tty.c_line = 0;
60
61    /*
62     * Make it be sane
63     */
64    tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD;
65    tty.c_cflag |= CREAD | HUPCL | CLOCAL;
66
67    /*
68     * input modes
69     */
70    tty.c_iflag = ICRNL | IXON | IXOFF;
71
72    /*
73     * output modes
74     */
75    tty.c_oflag = OPOST | ONLCR;
76
77    /*
78     * local modes
79     */
80    tty.c_lflag =
81        ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
82
83    tcsetattr( fd, TCSANOW, &tty );
84}
85
86int console_init(  )
87{
88    int fd;
89
90    /*
91     * Clean up
92     */
93    ioctl( 0, TIOCNOTTY, 0 );
94    close( 0 );
95    close( 1 );
96    close( 2 );
97    setsid(  );
98
99    /*
100     * Reopen console
101     */
102    if( ( fd = open( _PATH_CONSOLE, O_RDWR ) ) < 0 )
103    {
104        /*
105         * Avoid debug messages is redirected to socket packet if no exist a
106         * UART chip, added by honor, 2003-12-04
107         */
108        ( void )open( "/dev/null", O_RDONLY );
109        ( void )open( "/dev/null", O_WRONLY );
110        ( void )open( "/dev/null", O_WRONLY );
111        perror( _PATH_CONSOLE );
112        return errno;
113    }
114    dup2( fd, 0 );
115    dup2( fd, 1 );
116    dup2( fd, 2 );
117
118    ioctl( 0, TIOCSCTTY, 1 );
119    tcsetpgrp( 0, getpgrp(  ) );
120    set_term( 0 );
121
122    return 0;
123}
124
125pid_t ddrun_shell( int timeout, int nowait )
126{
127    pid_t pid;
128    char tz[1000];
129    char *envp[] = {
130        "TERM=vt100",
131        "TERMINFO=/etc/terminfo",
132        "HOME=/",
133        "PS1=\\u@\\h:\\w\\$ ",
134        "PATH=/usr/bin:/bin:/usr/sbin:/sbin:/jffs/usr/bin:/jffs/bin:/jffs/usr/sbin:/jffs/sbin",
135        "LD_LIBRARY_PATH=/usr/lib:/lib:/jffs/usr/lib:/jffs/lib",
136        "SHELL=" SHELL,
137        "USER=root",
138        tz,
139        NULL
140    };
141    int sig;
142
143    /*
144     * Wait for user input
145     */
146    // cprintf("Hit enter to continue...");
147    if( waitfor( STDIN_FILENO, timeout ) <= 0 )
148        return 0;
149
150    switch ( ( pid = fork(  ) ) )
151    {
152        case -1:
153            perror( "fork" );
154            return 0;
155        case 0:
156            /*
157             * Reset signal handlers set for parent process
158             */
159            for( sig = 0; sig < ( _NSIG - 1 ); sig++ )
160                signal( sig, SIG_DFL );
161
162            /*
163             * Reopen console
164             */
165            console_init(  );
166            // if (ret) exit(0); //no console running
167            /*
168             * Pass on TZ
169             */
170            snprintf( tz, sizeof( tz ), "TZ=%s", getenv( "TZ" ) );
171
172            /*
173             * Now run it.  The new program will take over this PID, so
174             * nothing further in init.c should be run.
175             */
176#ifdef HAVE_REGISTER
177            if( isregistered_real(  ) )
178#endif
179            {
180                execve( SHELL, ( char *[] )
181                        {
182                        "/bin/login", NULL}
183                        , envp );
184            }
185#ifdef HAVE_REGISTER
186            else
187            {
188                envp[6] = "SHELL=/sbin/regshell";
189                execve( "/sbin/regshell", ( char *[] )
190                        {
191                        "/sbin/regshell", NULL}, envp );
192            }
193#endif
194
195            /*
196             * We're still here? Some error happened.
197             */
198            perror( SHELL );
199            exit( errno );
200        default:
201            if( nowait )
202                return pid;
203            else
204            {
205                waitpid( pid, NULL, 0 );
206                return 0;
207            }
208    }
209}
210
211void shutdown_system( void )
212{
213    int sig;
214
215    /*
216     * Disable signal handlers
217     */
218    for( sig = 0; sig < ( _NSIG - 1 ); sig++ )
219        signal( sig, SIG_DFL );
220
221    /*
222     * Blink led before reboot
223     */
224    diag_led( DIAG, START_LED );
225    led_control( LED_DIAG, LED_ON );
226
227    cprintf( "Sending SIGTERM to all processes\n" );
228    kill( -1, SIGTERM );
229    sync(  );
230    sleep( 5 );
231
232    cprintf( "Sending SIGKILL to all processes\n" );
233    kill( -1, SIGKILL );
234    sync(  );
235    sleep( 1 );
236
237#ifdef HAVE_RB500
238    eval( "umount", "/" );
239#endif
240}
241
242static int fatal_signals[] = {
243    SIGQUIT,
244    SIGILL,
245#ifndef HAVE_RB500
246    SIGABRT,
247#endif
248    SIGFPE,
249    SIGPIPE,
250    SIGBUS,
251    // SIGSEGV, // Don't shutdown, when Segmentation fault.
252    SIGSYS,
253    SIGTRAP,
254    SIGPWR,
255    SIGTERM,                    /* reboot */
256    // SIGUSR1, /* halt */ // We use the for some purpose
257};
258
259void fatal_signal( int sig )
260{
261    char *message = NULL;
262
263    switch ( sig )
264    {
265        case SIGQUIT:
266            message = "Quit";
267            break;
268        case SIGILL:
269            message = "Illegal instruction";
270            break;
271        case SIGABRT:
272            message = "Abort";
273            break;
274        case SIGFPE:
275            message = "Floating exception";
276            break;
277        case SIGPIPE:
278            message = "Broken pipe";
279            break;
280        case SIGBUS:
281            message = "Bus error";
282            break;
283        case SIGSEGV:
284            message = "Segmentation fault";
285            break;
286        case SIGSYS:
287            message = "Bad system call";
288            break;
289        case SIGTRAP:
290            message = "Trace trap";
291            break;
292        case SIGPWR:
293            message = "Power failure";
294            break;
295        case SIGTERM:
296            message = "Terminated";
297            break;
298            // case SIGUSR1: message = "User-defined signal 1"; break;
299    }
300
301    if( message )
302        cprintf( "%s....................................\n", message );
303    else
304        cprintf( "Caught signal %d.......................................\n",
305                 sig );
306
307    shutdown_system(  );
308    sleep( 2 );
309
310    /*
311     * Halt on SIGUSR1
312     */
313    reboot( sig == SIGUSR1 ? RB_HALT_SYSTEM : RB_AUTOBOOT );
314    loop_forever(  );
315}
316
317static void reap( int sig )
318{
319    pid_t pid;
320
321    while( ( pid = waitpid( -1, NULL, WNOHANG ) ) > 0 )
322        cprintf( "Reaped %d\n", pid );
323}
324
325void signal_init( void )
326{
327    int i;
328
329    for( i = 0; i < sizeof( fatal_signals ) / sizeof( fatal_signals[0] );
330         i++ )
331        signal( fatal_signals[i], fatal_signal );
332
333    signal( SIGCHLD, reap );
334}
335
336/*
337 * States
338 */
339enum
340{
341    RESTART,
342    STOP,
343    START,
344    TIMER,
345    USER,
346    IDLE,
347#ifdef HAVE_X86
348    REBOOT,
349#endif
350};
351
352static int state = START;
353static int signalled = -1;
354
355/*
356 * Signal handling
357 */
358static void rc_signal( int sig )
359{
360    if( state == IDLE )
361    {
362        if( sig == SIGHUP )
363        {
364            lcdmessage( "Signal RESTART" );
365            printf( "signalling RESTART\n" );
366            signalled = RESTART;
367        }
368        else if( sig == SIGUSR2 )
369        {
370            lcdmessage( "Signal START" );
371            printf( "signalling START\n" );
372            signalled = START;
373        }
374        else if( sig == SIGINT )
375        {
376            lcdmessage( "Signal STOP" );
377            printf( "signalling STOP\n" );
378            signalled = STOP;
379        }
380        else if( sig == SIGALRM )
381        {
382            lcdmessage( "Signal TIMER" );
383            printf( "signalling TIMER\n" );
384            signalled = TIMER;
385        }
386#ifdef HAVE_X86
387        else if( sig == SIGTERM )
388        {
389            lcdmessage( "Signal Reboot" );
390            printf( "signalling REBOOT\n" );
391            signalled = REBOOT;
392        }
393#endif
394        else if( sig == SIGUSR1 )
395        {                       // Receive from WEB
396            lcdmessage( "Signal USER" );
397            printf( "signalling USER1\n" );
398            signalled = USER;
399        }
400
401    }
402}
403
404/*
405 * Timer procedure
406 */
407int do_timer( void )
408{
409    // do_ntp();
410    return 0;
411}
412
413static int noconsole = 0;
414
415/*
416 * Main loop
417 */
418int main( int argc, char **argv )
419{
420    sigset_t sigset;
421    pid_t shell_pid = 0;
422    uint boardflags;
423
424    // setenv("PATH",
425    // "/sbin:/bin:/usr/sbin:/usr/bin:/jffs/sbin:/jffs/bin:/jffs/usr/sbin:/jffs/usr/bin",
426    //
427    //
428    //
429    //
430    //
431    //
432    //
433    // 1);
434    // system("/etc/nvram/nvram");
435    /*
436     * Basic initialization
437     */
438    cprintf( "console init\n" );
439    if( console_init(  ) )
440        noconsole = 1;
441    cprintf( "init lcd\n" );
442    initlcd(  );
443    cprintf( "first message\n" );
444    lcdmessage( "System Start" );
445    cprintf( "start service\n" );
446    fprintf( stderr, "starting Architecture code for " ARCHITECTURE "\n" );
447    start_service( "sysinit" );
448    cprintf( "setup signals\n" );
449    /*
450     * Setup signal handlers
451     */
452    signal_init(  );
453    signal( SIGHUP, rc_signal );
454    signal( SIGUSR1, rc_signal );       // Start single service from WEB, by
455    // honor
456    signal( SIGUSR2, rc_signal );
457    signal( SIGINT, rc_signal );
458    signal( SIGALRM, rc_signal );
459#ifdef HAVE_X86
460    signal( SIGTERM, rc_signal );
461#endif
462    sigemptyset( &sigset );
463
464    /*
465     * Give user a chance to run a shell before bringing up the rest of the
466     * system
467     */
468
469    if( !noconsole )
470        ddrun_shell( 1, 0 );
471    cprintf( "setup nvram\n" );
472
473    start_service( "nvram" );
474
475    /*
476     * Restore defaults if necessary
477     */
478    int brand = getRouterBrand(  );
479
480#ifdef HAVE_SKYTEL
481    nvram_set( "vlan0ports", "0 1 2 3 4 5*" );
482    nvram_set( "vlan1ports", "" );
483#else
484
485    if( brand == ROUTER_WRT600N || brand == ROUTER_WRT610N )
486    {
487        nvram_set( "vlan2hwname", "et0" );
488    }
489
490#endif
491    start_service( "restore_defaults" );
492
493    /*
494     * Add vlan
495     */
496    boardflags = strtoul( nvram_safe_get( "boardflags" ), NULL, 0 );
497    nvram_set( "wanup", "0" );
498
499#ifndef HAVE_RB500
500    switch ( brand )
501    {
502        case ROUTER_WRT600N:
503        case ROUTER_WRT610N:
504        case ROUTER_ASUS_WL500GD:
505        case ROUTER_ASUS_WL550GE:
506        case ROUTER_MOTOROLA:
507        case ROUTER_RT480W:
508        case ROUTER_WRT350N:
509        case ROUTER_BUFFALO_WZRG144NH:
510        case ROUTER_DELL_TRUEMOBILE_2300_V2:
511            start_service( "config_vlan" );
512            break;
513        default:
514            if( check_vlan_support(  ) )
515            {
516                start_service( "config_vlan" );
517            }
518            break;
519
520    }
521#endif
522
523    set_ip_forward( '1' );
524    system( "/etc/preinit" );   // sets default values for ip_conntrack
525    system( "/bin/echo 0 > /proc/sys/net/ipv4/tcp_westwood" );
526    system( "/bin/echo 1 > /proc/sys/net/ipv4/tcp_vegas_cong_avoid" );
527    system( "/bin/echo 3 > /proc/sys/net/ipv4/tcp_vegas_alpha" );
528    system( "/bin/echo 3 > /proc/sys/net/ipv4/tcp_vegas_beta" );
529    system( "/bin/echo vegas > /proc/sys/net/ipv4/tcp_congestion_control" );
530
531#ifdef HAVE_JFFS2
532    start_service( "jffs2" );
533#endif
534#ifdef HAVE_MMC
535    start_service( "mmc" );
536#endif
537
538    start_service( "mkfiles" );
539    char *hostname;
540
541    /*
542     * set hostname to wan_hostname or router_name
543     */
544    if( strlen( nvram_safe_get( "wan_hostname" ) ) > 0 )
545        hostname = nvram_safe_get( "wan_hostname" );
546    else if( strlen( nvram_safe_get( "router_name" ) ) > 0 )
547        hostname = nvram_safe_get( "router_name" );
548    else
549        hostname = "dd-wrt";
550
551    sethostname( hostname, strlen( hostname ) );
552    stop_service( "httpd" );
553
554    // create loginprompt
555    FILE *fp = fopen( "/tmp/loginprompt", "wb" );
556
557#ifndef HAVE_MAKSAT
558#ifndef HAVE_MSSID
559#ifdef DIST
560    if( strlen( DIST ) > 0 )
561        fprintf( fp,
562                 "DD-WRT v23 SP3 %s (c) 2008 NewMedia-NET GmbH\nRelease: "
563                 BUILD_DATE " (SVN revision: %s)\n", DIST, SVN_REVISION );
564    else
565        fprintf( fp,
566                 "DD-WRT v23 SP3 custom (c) 2008 NewMedia-NET GmbH\nRelease: "
567                 BUILD_DATE " (SVN revision: %s)\n", SVN_REVISION );
568#else
569    fprintf( fp,
570             "DD-WRT v23 SP3 custom (c) 2008 NewMedia-NET GmbH\nRelease: "
571             BUILD_DATE " (SVN revision: %s)\n", SVN_REVISION );
572#endif
573#else
574#ifdef DIST
575    if( strlen( DIST ) > 0 )
576        fprintf( fp,
577                 "DD-WRT v24 %s (c) 2008 NewMedia-NET GmbH\nRelease: "
578                 BUILD_DATE " (SVN revision: %s)\n", DIST, SVN_REVISION );
579    else
580        fprintf( fp,
581                 "DD-WRT v24 custom (c) 2008 NewMedia-NET GmbH\nRelease: "
582                 BUILD_DATE " (SVN revision: %s)\n", SVN_REVISION );
583#else
584    fprintf( fp,
585             "DD-WRT v24 custom (c) 2008 NewMedia-NET GmbH\nRelease: "
586             BUILD_DATE " (SVN revision: %s)\n", SVN_REVISION );
587#endif
588#endif
589#endif
590
591    fclose( fp );
592    /*
593     * Loop forever
594     */
595    for( ;; )
596    {
597        switch ( state )
598        {
599            case USER:          // Restart single service from WEB of tftpd,
600                // by honor
601                lcdmessage( "RESTART SERVICES" );
602                cprintf( "USER1\n" );
603                start_single_service(  );
604#ifdef HAVE_CHILLI
605                start_service( "chilli" );
606#endif
607#ifdef HAVE_WIFIDOG
608                start_service( "wifidog" );
609#endif
610
611                state = IDLE;
612                break;
613
614            case RESTART:
615                lcdmessage( "RESTART SYSTEM" );
616#ifdef HAVE_OVERCLOCKING
617                start_service( "overclocking" );
618#endif
619                cprintf( "RESET NVRAM VARS\n" );
620                nvram_set( "wl0_lazy_wds", nvram_safe_get( "wl_lazy_wds" ) );
621#ifndef HAVE_MSSID
622                nvram_set( "wl0_akm", nvram_safe_get( "wl_akm" ) );
623                if( nvram_match( "wl_wep", "tkip" ) )
624                {
625                    nvram_set( "wl_crypto", "tkip" );
626                }
627                else if( nvram_match( "wl_wep", "aes" ) )
628                {
629                    nvram_set( "wl_crypto", "aes" );
630                }
631                else if( nvram_match( "wl_wep", "tkip+aes" ) )
632                {
633                    nvram_set( "wl_crypto", "tkip+aes" );
634                }
635                if( nvram_match( "wl_wep", "restricted" ) )
636                    nvram_set( "wl_wep", "enabled" );   // the nas need this
637                // value, the
638                // "restricted" is no
639                // longer need.
640                // (20040624 by
641                // honor)
642#endif
643
644                cprintf( "RESTART\n" );
645
646#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880)
647                eval( "wlconf", nvram_safe_get( "wl0_ifname" ), "down" );
648#ifdef HAVE_MSSID
649                char *next;
650                char var[80];
651                char *vifs = nvram_safe_get( "wl0_vifs" );
652
653                if( vifs != NULL )
654                    foreach( var, vifs, next )
655                {
656                    eval( "ifconfig", var, "down" );
657                }
658#endif
659#endif
660
661                /*
662                 * Fall through
663                 */
664            case STOP:
665                lcdmessage( "STOPPING SERVICES" );
666                cprintf( "STOP\n" );
667                killall( "udhcpc", SIGKILL );
668                setenv( "PATH",
669                        "/sbin:/bin:/usr/sbin:/usr/bin:/jffs/sbin:/jffs/bin:/jffs/usr/sbin:/jffs/usr/bin",
670                        1 );
671                setenv( "LD_LIBRARY_PATH",
672                        "/lib:/usr/lib:/jffs/lib:/jffs/usr/lib:/mmc/lib:/mmc/usr/lib:",
673                        1 );
674                cprintf( "STOP SERVICES\n" );
675
676                stop_services(  );
677                stop_service( "radio_timer" );
678#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880)
679                stop_service( "nas" );
680#endif
681                cprintf( "STOP WAN\n" );
682                stop_service( "ttraff" );
683                stop_service( "wan" );
684                cprintf( "STOP LAN\n" );
685#ifdef HAVE_MADWIFI
686                stop_service( "stabridge" );
687#endif
688#ifdef HAVE_RSTP
689                eval( "killall", "rstpd" );
690                unlink( "/tmp/.rstp_server" );
691#endif
692#ifdef HAVE_VLANTAGGING
693                stop_service( "bridging" );
694#endif
695#ifdef HAVE_BONDING
696                stop_service( "bonding" );
697#endif
698
699                stop_service( "lan" );
700#ifdef HAVE_VLANTAGGING
701                stop_service( "bridgesif" );
702                stop_service( "vlantagging" );
703#endif
704
705#ifndef HAVE_RB500
706                stop_service( "resetbutton" );
707#endif
708                start_service( "create_rc_shutdown" );
709                system( "/tmp/.rc_shutdown" );
710                if( state == STOP )
711                {
712                    state = IDLE;
713                    break;
714                }
715                /*
716                 * Fall through
717                 */
718            case START:
719                lcdmessage( "START SERVICES" );
720                nvram_set( "wl0_lazy_wds", nvram_safe_get( "wl_lazy_wds" ) );
721#ifndef HAVE_MSSID
722                nvram_set( "wl0_akm", nvram_safe_get( "wl_akm" ) );
723#endif
724                cprintf( "START\n" );
725                setenv( "PATH",
726                        "/sbin:/bin:/usr/sbin:/usr/bin:/jffs/sbin:/jffs/bin:/jffs/usr/sbin:/jffs/usr/bin",
727                        1 );
728                setenv( "LD_LIBRARY_PATH",
729                        "/lib:/usr/lib:/jffs/lib:/jffs/usr/lib:/mmc/lib:/mmc/usr/lib:",
730                        1 );
731#ifdef HAVE_IPV6
732                start_service( "ipv6" );
733#endif
734#ifndef HAVE_RB500
735                start_service( "resetbutton" );
736#endif
737                start_service( "setup_vlans" );
738#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880)
739                start_service( "wlconf" );
740#endif
741
742#ifdef HAVE_VLANTAGGING
743                start_service( "bridging" );
744#endif
745                start_service( "lan" );
746#ifdef HAVE_BONDING
747                start_service( "bonding" );
748#endif
749#ifdef HAVE_REGISTER
750                start_service( "mkfiles" );
751#endif
752#ifdef HAVE_MADWIFI
753                start_service( "stabridge" );
754#endif
755
756                cprintf( "start services\n" );
757                start_services(  );
758
759                cprintf( "start wan boot\n" );
760                start_service( "wan_boot" );
761                start_service( "ttraff" );
762
763                cprintf( "diag STOP LED\n" );
764                diag_led( DIAG, STOP_LED );
765                cprintf( "set led release wan control\n" );
766                SET_LED( RELEASE_WAN_CONTROL );
767
768#ifdef HAVE_VLANTAGGING
769                start_service( "vlantagging" );
770                start_service( "bridgesif" );
771#endif
772               
773#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880)
774#ifdef HAVE_RADIOOFF
775                if( nvram_match( "radiooff_button", "1" )
776                    && nvram_match( "radiooff_boot_off", "1" ) )
777                {
778                    eval( "wl", "-i", get_wl_instance_name( 0 ), "radio",
779                          "off" );
780                }
781                else
782#endif
783                    start_service( "nas" );
784#ifdef HAVE_MSSID
785                start_service( "guest_nas" );
786#endif
787#endif
788
789                start_service( "radio_timer" );
790
791                cprintf( "create rc file\n" );
792#ifdef HAVE_REGISTER
793                if( isregistered_real(  ) )
794#endif
795                {
796                    start_service( "create_rc_startup" );
797                    chmod( "/tmp/.rc_startup", 0700 );
798                    system( "/tmp/.rc_startup" );
799                    system( "/etc/init.d/rcS" );        // start openwrt
800                    // startup script
801                    // (siPath impl)
802                    cprintf( "start modules\n" );
803                    start_service( "modules" );
804#ifdef HAVE_MILKFISH
805                    start_service( "milkfish_boot" );
806#endif
807                    if( nvram_invmatch( "rc_custom", "" ) )     // create
808                        // custom
809                        // script
810                    {
811                        nvram2file( "rc_custom", "/tmp/custom.sh" );
812                        chmod( "/tmp/custom.sh", 0700 );
813                    }
814                }
815
816#ifdef HAVE_CHILLI
817                start_service( "chilli" );
818#endif
819#ifdef HAVE_WIFIDOG
820                start_service( "wifidog" );
821#endif
822                cprintf( "start syslog\n" );
823#ifdef HAVE_SYSLOG
824                startstop( "syslog" );
825#endif
826#ifdef HAVE_RSTP
827                // just experimental for playing
828                eval( "brctl", "stp", "br0", "off" );
829                eval( "rstpd" );
830                eval( "rstpctl", "rstp", "br0", "on" );
831#endif
832
833                system( "/etc/postinit&" );
834
835                led_control( LED_DIAG, LED_OFF );
836                lcdmessage( "System Ready" );
837                /*
838                 * Fall through
839                 */
840            case TIMER:
841                cprintf( "TIMER\n" );
842                do_timer(  );
843                /*
844                 * Fall through
845                 */
846            case IDLE:
847                cprintf( "IDLE\n" );
848                state = IDLE;
849                /*
850                 * Wait for user input or state change
851                 */
852                while( signalled == -1 )
853                {
854                    if( !noconsole
855                        && ( !shell_pid || kill( shell_pid, 0 ) != 0 ) )
856                        shell_pid = ddrun_shell( 0, 1 );
857                    else
858                        sigsuspend( &sigset );
859
860                }
861                state = signalled;
862                signalled = -1;
863                break;
864#ifdef HAVE_X86
865            case REBOOT:
866                lcdmessage( "System Reboots!" );
867                system( "reboot" );
868                break;
869#endif
870            default:
871                cprintf( "UNKNOWN\n" );
872                return 0;
873        }
874
875    }
876
877}
Note: See TracBrowser for help on using the repository browser.