Subversion Repositories public

Rev

Rev 100 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 100 Rev 108
Line 3... Line 3...
3
/**
3
/**
4
 * \file icd-main.cpp
4
 * \file icd-main.cpp
5
 *
5
 *
6
 * inotify cron system
6
 * inotify cron system
7
 *
7
 *
8
 * Copyright (C) 2006, 2007, 2008 Lukas Jelinek, <lukas@aiken.cz>
8
 * Copyright (C) 2006, 2007, 2008, 2012 Lukas Jelinek, <lukas@aiken.cz>
9
 *
9
 *
10
 * This program is free software; you can use it, redistribute
10
 * This program is free software; you can use it, redistribute
11
 * it and/or modify it under the terms of the GNU General Public
11
 * it and/or modify it under the terms of the GNU General Public
12
 * License, version 2 (see LICENSE-GPL).
12
 * License, version 2 (see LICENSE-GPL).
13
 *  
13
 *  
-
 
14
 * Credits:
-
 
15
 *   Christian Ruppert (new include to build with GCC 4.4+)
-
 
16
 *
14
 */
17
 */
15
18
16
#include <map>
19
#include <map>
17
#include <signal.h>
20
#include <signal.h>
18
#include <wait.h>
21
#include <wait.h>
Line 21... Line 24...
21
#include <dirent.h>
24
#include <dirent.h>
22
#include <syslog.h>
25
#include <syslog.h>
23
#include <errno.h>
26
#include <errno.h>
24
#include <sys/poll.h>
27
#include <sys/poll.h>
25
#include <sys/stat.h>
28
#include <sys/stat.h>
-
 
29
#include <cstdio>
26
#include <cstring>
30
#include <cstring>
27
31
28
#include "inotify-cxx.h"
32
#include "inotify-cxx.h"
29
#include "appinst.h"
33
#include "appinst.h"
30
#include "appargs.h"
34
#include "appargs.h"
Line 77... Line 81...
77
char g_cldPipeBuf[CHILD_PIPE_BUF_LEN];
81
char g_cldPipeBuf[CHILD_PIPE_BUF_LEN];
78
82
79
/// Daemonize true/false
83
/// Daemonize true/false
80
bool g_daemon = true;
84
bool g_daemon = true;
81
85
-
 
86
/// Second to wait on EAGAIN
-
 
87
#define POLL_EAGAIN_WAIT 3
-
 
88
82
/// Handles a signal.
89
/// Handles a signal.
83
/**
90
/**
84
 * For SIGTERM and SIGINT it sets the program finish variable.
91
 * For SIGTERM and SIGINT it sets the program finish variable.
85
 * For SIGCHLD it writes a character into the notification pipe
92
 * For SIGCHLD it writes a character into the notification pipe
86
 * (this is a workaround made due to disability to reliably
93
 * (this is a workaround made due to disability to reliably
Line 446... Line 453...
446
      if (res > 0) {
453
      if (res > 0) {
447
        if (ed.ProcessEvents())
454
        if (ed.ProcessEvents())
448
          UserTable::FinishDone();
455
          UserTable::FinishDone();
449
      }
456
      }
450
      else if (res < 0) {
457
      else if (res < 0) {
451
        if (errno != EINTR)
458
        switch (errno) {
-
 
459
          case EINTR:   // syscall interrupted - continue polling
-
 
460
            break;
-
 
461
          case EAGAIN:  // not enough resources - wait a moment and try again
-
 
462
            syslog(LOG_WARNING, "polling failed due to resource shortage, retrying later...");
-
 
463
            sleep(POLL_EAGAIN_WAIT);
-
 
464
            break;
-
 
465
          default:
452
          throw InotifyException("polling failed", errno, NULL);
466
            throw InotifyException("polling failed", errno, NULL);
-
 
467
        }
453
      }
468
      }
454
     
469
     
455
    }
470
    }
456
   
471
   
457
    free_tables(&ed);
472
    free_tables(&ed);