Ignore:
Timestamp:
Nov 25, 2009, 12:47:40 PM (14 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Added basic and non-working python interpreter
File:
1 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/server.c

    r4026 r4033  
    212212
    213213
    214    
     214
    215215    screen_list->last_key_time = 0;
    216216    screen_list->attached = 0;
     
    220220
    221221    server_init(screen_list);
     222#ifdef USE_PYTHON
     223    python_init(screen_list);
     224#endif
    222225
    223226    for (;;)
     
    300303    free_screen_list(screen_list);
    301304
     305#ifdef USE_PYTHON
     306    python_close(screen_list);
     307#endif
     308   
    302309    exit(0);
    303310}
     
    453460    if (screen_list->help)
    454461    {
    455         return help_handle_key(screen_list, c); 
     462        return help_handle_key(screen_list, c);
    456463    }
    457464#ifdef USE_PYTHON
    458         if(screen_list->python_command)
    459     {
    460         return python_command_handle_key(screen_list, c);   
    461     }
    462 #endif
    463    
     465    if (screen_list->python_command)
     466    {
     467        return python_command_handle_key(screen_list, c);
     468    }
     469#endif
     470
    464471    /* CTRL-A has been pressed before, handle this as a command, except that
    465      CTRL-A a sends literal CTRL-A */
     472       CTRL-A a sends literal CTRL-A */
    466473    if (screen_list->command && (c != 'a'))
    467474    {
     
    527534}
    528535
     536
     537int install_fds(struct screen_list *screen_list)
     538{
     539    int fd;
     540    close(0);
     541    close(1);
     542    close(2);
     543    fd = open("/dev/null", O_RDWR, 0);
     544    if (fd < 0)
     545    {
     546        perror("Failed to open /dev/null");
     547        return -2;
     548    }
     549    dup2(fd, 0);
     550#ifndef DEBUG
     551    dup2(fd, 1);
     552    dup2(fd, 2);
     553    if (fd > 2)
     554        close(fd);
     555#else
     556    if (fd != 0)
     557        close(fd);
     558    screen_list->outfd =
     559        open("/tmp/neercs-debug.txt", O_TRUNC | O_RDWR | O_CREAT,
     560             S_IRUSR | S_IWUSR);
     561    dup2(screen_list->outfd, 1);
     562    dup2(screen_list->outfd, 2);
     563    if (screen_list->outfd > 2)
     564        close(screen_list->outfd);
     565#endif
     566        return 0;
     567}
     568
    529569int start_server(struct screen_list *screen_list)
    530570{
     
    539579    if (pid == 0)
    540580    {
    541         int fd;
    542         close(0);
    543         close(1);
    544         close(2);
    545         fd = open("/dev/null", O_RDWR, 0);
    546         if (fd < 0)
    547         {
    548             perror("Failed to open /dev/null");
    549             return -2;
    550         }
    551         dup2(fd, 0);
    552 #ifndef DEBUG
    553         dup2(fd, 1);
    554         dup2(fd, 2);
    555         if (fd > 2)
    556             close(fd);
    557 #else
    558         if (fd != 0)
    559             close(fd);
    560         fd = open("/tmp/neercs-debug.txt", O_TRUNC | O_RDWR | O_CREAT,
    561                   S_IRUSR | S_IWUSR);
    562         dup2(fd, 1);
    563         dup2(fd, 2);
    564         if (fd > 2)
    565             close(fd);
    566 #endif
     581        int r = install_fds(screen_list);
     582        if(r) return r;
    567583        setsid();
    568584
     
    570586        /* Never returns */
    571587    }
    572    
     588
    573589    return 0;
    574590}
Note: See TracChangeset for help on using the changeset viewer.