Subversion Repositories public

Rev

Rev 79 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 79 Rev 100
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 Lukas Jelinek, <lukas@aiken.cz>
8
 * Copyright (C) 2006, 2007, 2008 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
 *  
Line 21... Line 21...
21
#include <dirent.h>
21
#include <dirent.h>
22
#include <syslog.h>
22
#include <syslog.h>
23
#include <errno.h>
23
#include <errno.h>
24
#include <sys/poll.h>
24
#include <sys/poll.h>
25
#include <sys/stat.h>
25
#include <sys/stat.h>
-
 
26
#include <cstring>
26
27
27
#include "inotify-cxx.h"
28
#include "inotify-cxx.h"
28
#include "appinst.h"
29
#include "appinst.h"
29
#include "appargs.h"
30
#include "appargs.h"
30
31
Line 43... Line 44...
43
/// incrond version string
44
/// incrond version string
44
#define INCROND_VERSION INCROND_NAME " " INCRON_VERSION
45
#define INCROND_VERSION INCROND_NAME " " INCRON_VERSION
45
46
46
/// incrontab description string
47
/// incrontab description string
47
#define INCROND_DESCRIPTION "incrond - inotify cron daemon\n" \
48
#define INCROND_DESCRIPTION "incrond - inotify cron daemon\n" \
48
                            "(c) Lukas Jelinek, 2006, 2007"
49
                            "(c) Lukas Jelinek, 2006, 2007, 2008"
49
50
50
/// incrontab help string
51
/// incrontab help string
51
#define INCROND_HELP INCROND_DESCRIPTION "\n\n" \
52
#define INCROND_HELP INCROND_DESCRIPTION "\n\n" \
52
          "usage: incrond [<options>]\n\n" \
53
          "usage: incrond [<options>]\n\n" \
53
          "<operation> may be one of the following:\n" \
54
          "<operation> may be one of the following:\n" \
Line 56... Line 57...
56
          "  -h, --help                   prints this help text\n" \
57
          "  -h, --help                   prints this help text\n" \
57
          "  -n, --foreground             runs on foreground (no daemonizing)\n" \
58
          "  -n, --foreground             runs on foreground (no daemonizing)\n" \
58
          "  -k, --kill                   terminates running instance of incrond\n" \
59
          "  -k, --kill                   terminates running instance of incrond\n" \
59
          "  -f <FILE>, --config=<FILE>   overrides default configuration file  (requires root privileges)\n" \
60
          "  -f <FILE>, --config=<FILE>   overrides default configuration file  (requires root privileges)\n" \
60
          "  -V, --version                prints program version\n\n" \
61
          "  -V, --version                prints program version\n\n" \
61
          "For reporting bugs please use http:://bts.aiken.cz\n"
62
          "For reporting bugs please use http://bts.aiken.cz\n"
62
63
63
64
64
65
65
/// User name to user table mapping table
66
/// User name to user table mapping table
66
SUT_MAP g_ut;
67
SUT_MAP g_ut;
Line 97... Line 98...
97
    case SIGCHLD:
98
    case SIGCHLD:
98
      // first empty pipe (to prevent internal buffer overflow)
99
      // first empty pipe (to prevent internal buffer overflow)
99
      do {} while (read(g_cldPipe[0], g_cldPipeBuf, CHILD_PIPE_BUF_LEN) > 0);
100
      do {} while (read(g_cldPipe[0], g_cldPipeBuf, CHILD_PIPE_BUF_LEN) > 0);
100
     
101
     
101
      // now write one character
102
      // now write one character
102
      write(g_cldPipe[1], "X", 1);
103
      if (write(g_cldPipe[1], "X", 1) <= 0) {
-
 
104
        syslog(LOG_WARNING, "cannot send SIGCHLD token to notification pipe");
-
 
105
      }
103
      break;
106
      break;
104
    default:;
107
    default:;
105
  }
108
  }
106
}
109
}
107
110
Line 380... Line 383...
380
    goto error;
383
    goto error;
381
  }
384
  }
382
 
385
 
383
  try {
386
  try {
384
    if (g_daemon)
387
    if (g_daemon)
385
      daemon(0, 0);
388
      if (daemon(0, 0) == -1) {
-
 
389
        syslog(LOG_CRIT, "daemonizing failed: (%i) %s", errno, strerror(errno));
-
 
390
        fprintf(stderr, "daemonizing failed: (%i) %s\n", errno, strerror(errno));
-
 
391
        ret = 1;
-
 
392
        goto error;
-
 
393
      }
386
 
394
 
387
    try {
395
    try {
388
    if (!app.Lock()) {
396
    if (!app.Lock()) {
389
      syslog(LOG_CRIT, "another instance of incrond already running");
397
      syslog(LOG_CRIT, "another instance of incrond already running");
390
      if (!g_daemon)
398
      if (!g_daemon)