dmon:dmon.git
12 years agoRelease v0.3.6 v0.3.6
Adrian Perez [Thu, 30 Sep 2010 01:27:17 +0000 (03:27 +0200)]
Release v0.3.6

12 years agoUpdate manual page with "-r" option
Adrian Perez [Thu, 30 Sep 2010 01:23:40 +0000 (03:23 +0200)]
Update manual page with "-r" option

Add section on the manual page describing the option for setting process
limits to keep it up to date with the implementation.

12 years agoBuild by default optimized for size (-Os)
Adrian Perez [Thu, 30 Sep 2010 01:15:57 +0000 (03:15 +0200)]
Build by default optimized for size (-Os)

12 years agoMake safe_setrlimit() print limit names on failure
Adrian Perez [Thu, 30 Sep 2010 01:13:07 +0000 (03:13 +0200)]
Make safe_setrlimit() print limit names on failure

This uses limit_name() to make error messages more meaningful.

12 years agoImplement setting process limits
Adrian Perez [Thu, 30 Sep 2010 01:00:25 +0000 (03:00 +0200)]
Implement setting process limits

This is done by using parse_limit_arg(), saving items to arrays, and doing
limit setup in the child once it was spawned, but before file redirection,
and other tweaks done before execvp().

12 years agoImplement parse_limit_arg() and limit_name()
Adrian Perez [Thu, 30 Sep 2010 00:24:41 +0000 (02:24 +0200)]
Implement parse_limit_arg() and limit_name()

Convenience functions to parse "limit=value" arguments, as passed to the
"-r" command line flag. As a bonus, limit_name() can be used to get the name
of a limit given its numeric value.

12 years agoAdd length_of macro to util.h
Adrian Perez [Thu, 30 Sep 2010 00:24:07 +0000 (02:24 +0200)]
Add length_of macro to util.h

12 years agoNew safe_setrlimit() function
Adrian Perez [Wed, 29 Sep 2010 22:42:43 +0000 (00:42 +0200)]
New safe_setrlimit() function

Hides using "struct rlimit", and aborts program execution when errors occur.
This is a convenience function which will be used to control process limits.

12 years agoRelease v0.3.5 v0.3.5
Adrian Perez [Mon, 27 Sep 2010 00:32:47 +0000 (02:32 +0200)]
Release v0.3.5

12 years agoAdd "-i" and remove "-?" in manual page
Adrian Perez [Mon, 27 Sep 2010 00:22:10 +0000 (02:22 +0200)]
Add "-i" and remove "-?" in manual page

Updates the manual page to state the current behavior of dmon. The "-i"
option was added, along with a clarification about how to specify time
intervals using suffixes. The "-?" option is no longer valid.

12 years agoRemove "-?" as valid command line flag
Adrian Perez [Mon, 27 Sep 2010 00:13:58 +0000 (02:13 +0200)]
Remove "-?" as valid command line flag

The getopt() uses the "?" as character for signalling an invalid command
line option, so dmon must not use it by itself.

12 years agoMove "-1" in help message to exec constraints section
Adrian Perez [Mon, 27 Sep 2010 00:12:03 +0000 (02:12 +0200)]
Move "-1" in help message to exec constraints section

The option controls process execution, so it belongs to the "process
execution constraints" epigraph in the help text.

12 years agoImplement sleeping an interval between succesful runs
Adrian Perez [Mon, 27 Sep 2010 00:08:02 +0000 (02:08 +0200)]
Implement sleeping an interval between succesful runs

Add a new "-i" flag, which is passed a time interval. When the process exits
with a zero return code, then the wait is done before the next run. This can
be used to make dmon behave as el-cheapo cron daemon. As it makes no sense
using this option along with "-1", an error is given back to the user when
both options are passed in the command line.

12 years agoRefactored code for better reusability of functions
Adrian Perez [Sun, 26 Sep 2010 23:02:15 +0000 (01:02 +0200)]
Refactored code for better reusability of functions

- Move parse_float_arg() and parse_time_arg() to util.[hc]
- Move become_daemon() to util.[hc]
- Moved safe_sleep() to util.[hc]
- Factor out task_t handling code to task.[hc]

12 years agoExplictly ignore return value of write() in iolib
Adrian Perez [Mon, 13 Sep 2010 22:56:08 +0000 (00:56 +0200)]
Explictly ignore return value of write() in iolib

When building with -D_FORTIFY_SOURCE=1 the compiler will complain about the
return value for write() --inside the die() macro-- being ignored. In this
particular case we want it to be actually ignored because it is unknown
whether the call would succeed, and also we do not care because the program
will abort execution afterwards.

12 years agoAvoid warning about signed vs. unsigned comparisons
Adrian Perez [Mon, 13 Sep 2010 22:54:32 +0000 (00:54 +0200)]
Avoid warning about signed vs. unsigned comparisons

Second argument to format_ulong() and format_ullong() was declared as "int",
when in fact those functions are never called with negative values. By
changing the declaration to use "unsigned" instead will make the compiler
not complain.

12 years agoHandle errors when creating command<->log pipes
Adrian Perez [Mon, 13 Sep 2010 22:52:58 +0000 (00:52 +0200)]
Handle errors when creating command<->log pipes

When calling pipe() to create the pipe put in between the main process and
the logging process, the return value was not being taken into account. This
makes dmon die() in failure.

12 years agoNew "strip" target in Makefile
Adrian Perez [Wed, 8 Sep 2010 02:12:35 +0000 (04:12 +0200)]
New "strip" target in Makefile

Allows for "make strip". Also works properly with "make MULTICALL=1 strip".

12 years agoSupport building all tools as a multicall binary
Adrian Perez [Mon, 6 Sep 2010 12:24:36 +0000 (14:24 +0200)]
Support building all tools as a multicall binary

This enables building all tools into a single executable, being the tools
chosen by inspecting argv[0]. This is good to save space i.e. in embedded
devices and also some memory because of sharability of the text segment.

To make such a build, just pass MULTICALL=1 to Make.

12 years agoRelease v0.3.4 v0.3.4
Adrian Perez [Sun, 5 Sep 2010 17:10:43 +0000 (19:10 +0200)]
Release v0.3.4

12 years agoutil: Use primary group for the user
Adrian Perez [Sun, 5 Sep 2010 17:06:15 +0000 (19:06 +0200)]
util: Use primary group for the user

Changed name_to_uid() to be name_to_uidgid(), so we get the primary group to
which we do setgid() from the password database entry, this way we ensure
that the group always exists and that it is the primary group of the user.

Apart from removing the potential flaw of a group named exactly like the
specified user, this behavior is more predictable and it is likely that
users would expect dmon to work like this.

12 years agoRelease v0.3.3 v0.3.3
Adrian Perez [Sun, 5 Sep 2010 16:31:04 +0000 (18:31 +0200)]
Release v0.3.3

12 years agoSet additional groups prior to execution
Adrian Perez [Sun, 5 Sep 2010 16:27:50 +0000 (18:27 +0200)]
Set additional groups prior to execution

Implements setting additional groups passed to -u/-U as a colon-separated
list. This is done using setgroups(2) before dropping privileges.

12 years agoUpdate manual pages for -u/-U
Adrian Perez [Sun, 5 Sep 2010 16:17:19 +0000 (18:17 +0200)]
Update manual pages for -u/-U

Keep manual page up-to-date with the latest change to how parsing is done
for -u/-U.

12 years agoDo -u/-U in terms of parse_uidgids() removing -g/-G
Adrian Perez [Sun, 5 Sep 2010 16:12:44 +0000 (18:12 +0200)]
Do -u/-U in terms of parse_uidgids() removing -g/-G

This used parse_uidgids() to get the user and group list for the -u and -U
options. This makes -g and -G unnecessary because now groups are specified
as a colon-separated list to -u/-U.

12 years agoutil: Add function to parse uid[:gid[:gid...]] lists
Adrian Perez [Sun, 5 Sep 2010 15:49:05 +0000 (17:49 +0200)]
util: Add function to parse uid[:gid[:gid...]] lists

This adds a function parse_uidgids() which will parse lists with an UID and
any number of GIDs separated by colons.

12 years agoRelease v0.3.2
Adrian Perez [Fri, 3 Sep 2010 09:12:37 +0000 (11:12 +0200)]
Release v0.3.2

12 years agoAdded COPYING and (simple) README
Adrian Perez [Fri, 3 Sep 2010 09:01:10 +0000 (11:01 +0200)]
Added COPYING and (simple) README

The README for the moment refers to the DMon blog post and the manual pages.
That should suffice for now.

12 years agoRenamed dsyslog to dlog to avoid file collisions
Adrian Perez [Fri, 3 Sep 2010 08:50:54 +0000 (10:50 +0200)]
Renamed dsyslog to dlog to avoid file collisions

Another project called dsyslog (http://nenolod.net/projects/dsyslog/)
already exists, and it would be impossible to it installed alongside dmon
because we have a binary called that way. Solution is to rename it to
something else, so "dsyslog" was renamed to "dslog".

12 years agoRelease v0.3.1 v0.3.1
Adrian Perez [Wed, 1 Sep 2010 14:52:55 +0000 (16:52 +0200)]
Release v0.3.1

12 years agoFix: Do not handle SIGSTOP, it is forbidden by POSIX.1
Adrian Perez [Wed, 1 Sep 2010 14:48:59 +0000 (16:48 +0200)]
Fix: Do not handle SIGSTOP, it is forbidden by POSIX.1

Installing a signal handler for SIGSTOP is not supported in POSIX.1, and in
the (rare) platforms where it is allowed, behavior is undefined and most
likely the handler will be never invoked.

With this patch we avoid handling it at all.

12 years agoRelease v0.3 v0.3
Adrian Perez [Thu, 26 Aug 2010 21:06:05 +0000 (23:06 +0200)]
Release v0.3

12 years agoUpdate manual page with the -L/-l options, plus example
Adrian Perez [Thu, 26 Aug 2010 20:59:25 +0000 (22:59 +0200)]
Update manual page with the -L/-l options, plus example

12 years agoFix: SIGSTOP signal must be forwarded with -S/-s
Adrian Perez [Thu, 26 Aug 2010 20:48:21 +0000 (22:48 +0200)]
Fix: SIGSTOP signal must be forwarded with -S/-s

Moved the definition of SIGTOP to the upper part of the forward_signals
array, so the signal handler is installed for it as well. This fixes that
signal not being forwarded to the child processes.

12 years agoImplement process pause/resume depending on load average
Adrian Perez [Thu, 26 Aug 2010 20:44:31 +0000 (22:44 +0200)]
Implement process pause/resume depending on load average

Passing the "-L" option will enable load average tracking. Once per second
dmon will check the system's load average, and when it goes over the given
value, it will send SIGSTOP to the main process, effectively pausing it.
Once the load falls below the value specified with "-l" (or half the high
level, if not given) then dmon will send SIGCONT to resume the process.

12 years agoutil: Implement iterruptible_sleep()
Adrian Perez [Thu, 26 Aug 2010 19:12:29 +0000 (21:12 +0200)]
util: Implement iterruptible_sleep()

This is a version of sleep() which does not mess SIGALRM, which can be
interrupted by signals, in which event it will return zero.

12 years agoCategorize help output of dmon
Adrian Perez [Thu, 26 Aug 2010 18:41:07 +0000 (20:41 +0200)]
Categorize help output of dmon

This makes easier to spot which option of process execution/monitorization
one is searching for when invoking the help message with "dmon -h".

12 years agoUpdate manual page with setid/setgid options
Adrian Perez [Wed, 25 Aug 2010 15:35:49 +0000 (17:35 +0200)]
Update manual page with setid/setgid options

This adds the description of the setid/setgid command line options, and an
usage example in the manual page for dmon.

12 years agoImplement setuid/setgid when spawning child processes
Adrian Perez [Wed, 25 Aug 2010 15:18:23 +0000 (17:18 +0200)]
Implement setuid/setgid when spawning child processes

* New "uid" and "gid" fields in task structures.
* Adds options -u/-U/-g/-G for setting user/group credentials, both for main
  command and logging command.
* Master process does not drop privileges. Doing that would make impossible
  for it to respawn child processes with the desired credentials.

12 years agoHelper name_to_uid() & name_to_gid() functions
Adrian Perez [Wed, 25 Aug 2010 00:31:04 +0000 (02:31 +0200)]
Helper name_to_uid() & name_to_gid() functions

Those functions take both a string which may be a number or a user/group
name, and return the associated UID/GID number converted.

12 years agodmon: Do not wait the first time a process is started
Adrian Perez [Wed, 11 Aug 2010 22:05:25 +0000 (00:05 +0200)]
dmon: Do not wait the first time a process is started

Now dmon keeps track of the moment at which a command was started to
determine whether to sleep for 1s before respawning. The initial value
of the variable makes dmon to *not* sleep before executing commands for
first time. This is intended behavior. Using some kind of back-off for
respawns would be nice, but that would involve having an additional
counter, so for the moment this solution is good enough.

12 years agoutil: Handle passing zero to safe_sleep
Adrian Perez [Wed, 11 Aug 2010 21:30:04 +0000 (23:30 +0200)]
util: Handle passing zero to safe_sleep

Return directly when zero is passed. This way we ensure that zero is a valid
value, and for implementations which incur in a system call, it is avoided.

12 years agoRelease v0.2 v0.2
Adrian Perez [Wed, 4 Aug 2010 00:40:46 +0000 (02:40 +0200)]
Release v0.2

12 years agodmon: Sleep second before exec'ing to prevent DoS
Adrian Perez [Wed, 4 Aug 2010 00:35:15 +0000 (02:35 +0200)]
dmon: Sleep second before exec'ing to prevent DoS

This will inconditionally sleep for one second before doing stream
redirection and exec() for spawned childs, to have some time before
fork+exec combos, thus providing some alleviation for possible DoS
attacks.

12 years agoutil: Fix header to say "util" instead of "dmon-util"
Adrian Perez [Wed, 4 Aug 2010 00:17:46 +0000 (02:17 +0200)]
util: Fix header to say "util" instead of "dmon-util"

12 years agodmon: Print error message when no command is specified
Adrian Perez [Tue, 3 Aug 2010 21:01:09 +0000 (23:01 +0200)]
dmon: Print error message when no command is specified

If no command is given in the command line, issue an error and exit instead
of blindly trying to start a null command.

12 years agodmon: Implement timeout for process running time
Adrian Perez [Tue, 3 Aug 2010 20:55:15 +0000 (22:55 +0200)]
dmon: Implement timeout for process running time

When a timeout is specified, with "-t SECONDS", then if the command takes
longer to complete, it will be terminated by sending the SIGTERM/SIGCONT
combo, and then respawned. This can be used to run processes that must be
enforced to keep their running time below a given value.

As a bonus, suffixes for the argument to "-t" may be given: (w)eeks, (d)ays,
(h)ours and (m)inutes.

12 years agodmon: Implement -1 (run once) switch
Adrian Perez [Fri, 30 Jul 2010 21:17:51 +0000 (23:17 +0200)]
dmon: Implement -1 (run once) switch

If the program exits with success code (i.e. zero) it is not respawnd and
dmon will close itself. Otherwise the process is respawned as usual.

12 years agoDebian packaging files v0.1
Adrian Perez [Fri, 30 Jul 2010 04:50:46 +0000 (06:50 +0200)]
Debian packaging files

12 years agoAdd manual page for dmon
Adrian Perez [Fri, 30 Jul 2010 04:39:38 +0000 (06:39 +0200)]
Add manual page for dmon

12 years agodmon: Implement daemonization and PID file writing
Adrian Perez [Fri, 30 Jul 2010 04:12:37 +0000 (06:12 +0200)]
dmon: Implement daemonization and PID file writing

* Now by default dmon will daemonize itself before launching its childs. The
  "-n" option may be passed to stay in foreground.
* The "-p" option is now honored and the PID will be written to the
  specified file.

12 years agodlog: Do not create log file with execution bit set
Adrian Perez [Fri, 30 Jul 2010 03:44:02 +0000 (05:44 +0200)]
dlog: Do not create log file with execution bit set

12 years agoAvoid building debug functions
Adrian Perez [Fri, 30 Jul 2010 03:41:09 +0000 (05:41 +0200)]
Avoid building debug functions

12 years agoImplement signal handling and process respawning
Adrian Perez [Fri, 30 Jul 2010 03:38:50 +0000 (05:38 +0200)]
Implement signal handling and process respawning

* Died processes are now respawned by default.
* Signals can now be passed to both the log command and the main command.
* Children processes are properly reaped.

12 years agoMigrate to new task_t control structure
Adrian Perez [Fri, 30 Jul 2010 02:12:30 +0000 (04:12 +0200)]
Migrate to new task_t control structure

A new task_t data type holds all information related to a process,
and a set of higher-level task_*() functions is added. Apart from
that cleanup, no additional functionality is added.

12 years agoSupport omitting log file path on dlog
Adrian Perez [Fri, 30 Jul 2010 01:35:12 +0000 (03:35 +0200)]
Support omitting log file path on dlog

If a log file path is not given, then lines are printed back to standard
output. This may be useful to add timestamps to lines.

12 years agoAdd dlog manual page
Adrian Perez [Fri, 30 Jul 2010 01:00:35 +0000 (03:00 +0200)]
Add dlog manual page

12 years agoImplement dlog utility
Adrian Perez [Fri, 30 Jul 2010 00:56:16 +0000 (02:56 +0200)]
Implement dlog utility

12 years agoFix file headers, rename dmon-util.* -> util.*
Adrian Perez [Fri, 30 Jul 2010 00:33:38 +0000 (02:33 +0200)]
Fix file headers, rename dmon-util.* -> util.*

12 years agoAdd dsyslog manual page
Adrian Perez [Fri, 30 Jul 2010 00:29:25 +0000 (02:29 +0200)]
Add dsyslog manual page

12 years agoRewrite code in terms of iolib.[hc]
Adrian Perez [Fri, 30 Jul 2010 00:15:00 +0000 (02:15 +0200)]
Rewrite code in terms of iolib.[hc]

This makes utilities not use the heavyweight stdio buffers from libc,
but a lighter version.

12 years agoAdd support for @e/@E formatters in iolib.[hc]
Adrian Perez [Fri, 30 Jul 2010 00:14:41 +0000 (02:14 +0200)]
Add support for @e/@E formatters in iolib.[hc]

12 years agoAdd vformat() function to iolib.[hc]
Adrian Perez [Fri, 30 Jul 2010 00:14:10 +0000 (02:14 +0200)]
Add vformat() function to iolib.[hc]

12 years agoProper indentation and modelines
Adrian Perez [Thu, 29 Jul 2010 23:57:14 +0000 (01:57 +0200)]
Proper indentation and modelines

12 years agoClose standard output after initialization
Adrian Perez [Thu, 29 Jul 2010 23:53:18 +0000 (01:53 +0200)]
Close standard output after initialization

The standard output stream can be safely closed, because after
initialization (which could print messages to stdout when -h/-? are
passed) all possible messages are error messages, and those go to
standard error instead.

12 years agoImplementation of dsyslog
Adrian Perez [Thu, 29 Jul 2010 23:42:02 +0000 (01:42 +0200)]
Implementation of dsyslog

"dsyslog" will read lines from standard input, and then send each line to
the system logger.

12 years agoExpand tabs in indentation
Adrian Perez [Thu, 29 Jul 2010 22:32:55 +0000 (00:32 +0200)]
Expand tabs in indentation

12 years agoInitial import
Adrian Perez [Thu, 29 Jul 2010 22:28:21 +0000 (00:28 +0200)]
Initial import