incron  0.5.10
Defines | Functions | Variables
icd-main.cpp File Reference

inotify cron daemon main file More...

#include <map>
#include <signal.h>
#include <wait.h>
#include <fcntl.h>
#include <pwd.h>
#include <dirent.h>
#include <syslog.h>
#include <errno.h>
#include <sys/poll.h>
#include <sys/stat.h>
#include <cstdio>
#include <cstring>
#include "inotify-cxx.h"
#include "appinst.h"
#include "appargs.h"
#include "incron.h"
#include "incrontab.h"
#include "usertable.h"
#include "incroncfg.h"

Defines

#define INCRON_LOG_OPTS   (LOG_CONS | LOG_PID)
 Logging options (console as fallback, log PID)
#define INCRON_LOG_FACIL   LOG_CRON
 Logging facility (use CRON)
#define INCROND_VERSION   INCROND_NAME " " INCRON_VERSION
 incrond version string
#define INCROND_DESCRIPTION
 incrontab description string
#define INCROND_HELP
 incrontab help string
#define CHILD_PIPE_BUF_LEN   32
#define POLL_EAGAIN_WAIT   3
 Second to wait on EAGAIN.

Functions

void on_signal (int signo)
 Handles a signal.
void load_tables (EventDispatcher *pEd) throw (InotifyException)
 Attempts to load all (user and system) incron tables.
void free_tables (EventDispatcher *pEd)
 Deallocates all memory used by incron tables and unregisters them from the dispatcher.
void prepare_pipe ()
 Prepares a 'dead/done child' notification pipe.
void init_poll_array (struct pollfd pfd[], int pipefd, int infd)
 Checks whether a parameter string is a specific command.
int main (int argc, char **argv)
 Main application function.

Variables

SUT_MAP g_ut
 User name to user table mapping table.
volatile bool g_fFinish = false
 Finish program yes/no.
int g_cldPipe [2]
 Pipe for notifying about dead children.
char g_cldPipeBuf [CHILD_PIPE_BUF_LEN]
bool g_daemon = true
 Daemonize true/false.

Detailed Description

inotify cron daemon main file

inotify cron system

Copyright (C) 2006, 2007, 2008, 2012 Lukas Jelinek, <lukas@aiken.cz>

This program is free software; you can use it, redistribute it and/or modify it under the terms of the GNU General Public License, version 2 (see LICENSE-GPL).

Credits: Christian Ruppert (new include to build with GCC 4.4+)


Define Documentation

#define CHILD_PIPE_BUF_LEN   32
#define INCRON_LOG_FACIL   LOG_CRON

Logging facility (use CRON)

#define INCRON_LOG_OPTS   (LOG_CONS | LOG_PID)

Logging options (console as fallback, log PID)

#define INCROND_DESCRIPTION
Value:
"incrond - inotify cron daemon\n" \
                            "(c) Lukas Jelinek, 2006, 2007, 2008"

incrontab description string

#define INCROND_HELP
Value:
INCROND_DESCRIPTION "\n\n" \
          "usage: incrond [<options>]\n\n" \
          "<operation> may be one of the following:\n" \
          "These options may be used:\n" \
          "  -?, --about                  gives short information about program\n" \
          "  -h, --help                   prints this help text\n" \
          "  -n, --foreground             runs on foreground (no daemonizing)\n" \
          "  -k, --kill                   terminates running instance of incrond\n" \
          "  -f <FILE>, --config=<FILE>   overrides default configuration file  (requires root privileges)\n" \
          "  -V, --version                prints program version\n\n" \
          "For reporting bugs please use http://bts.aiken.cz\n"

incrontab help string

#define INCROND_VERSION   INCROND_NAME " " INCRON_VERSION

incrond version string

#define POLL_EAGAIN_WAIT   3

Second to wait on EAGAIN.


Function Documentation

void free_tables ( EventDispatcher pEd)

Deallocates all memory used by incron tables and unregisters them from the dispatcher.

Parameters:
[in]pEdevent dispatcher
void init_poll_array ( struct pollfd  pfd[],
int  pipefd,
int  infd 
)

Checks whether a parameter string is a specific command.

The string is accepted if it equals either the short or long form of the command.

Parameters:
[in]schecked string
[in]shortCmdshort form of command
[in]longCmdlong form of command
Returns:
true = string accepted, false = otherwise Initializes a poll array.
Parameters:
[out]pfdpoll structure array
[in]pipefdpipe file descriptor
[in]infdinotify infrastructure file descriptor
void load_tables ( EventDispatcher pEd) throw (InotifyException)

Attempts to load all (user and system) incron tables.

Loaded tables are registered for processing events.

Parameters:
[in]pEdinotify event dispatcher
Exceptions:
InotifyExceptionthrown if base table directory cannot be read
int main ( int  argc,
char **  argv 
)

Main application function.

Parameters:
[in]argcargument count
[in]argvargument array
Returns:
0 on success, 1 on error
Attention:
In daemon mode, it finishes immediately.
void on_signal ( int  signo)

Handles a signal.

For SIGTERM and SIGINT it sets the program finish variable. For SIGCHLD it writes a character into the notification pipe (this is a workaround made due to disability to reliably wait for dead children).

Parameters:
[in]signosignal number
void prepare_pipe ( )

Prepares a 'dead/done child' notification pipe.

This function returns no value at all and on error it throws an exception.


Variable Documentation

int g_cldPipe[2]

Pipe for notifying about dead children.

char g_cldPipeBuf[CHILD_PIPE_BUF_LEN]
bool g_daemon = true

Daemonize true/false.

volatile bool g_fFinish = false

Finish program yes/no.

User name to user table mapping table.