dss.git
2 months agoMerge branch 'master' into next next pu
Andre Noll [Mon, 29 Jan 2024 17:27:01 +0000 (18:27 +0100)]
Merge branch 'master' into next

* master:
  Fix --config-file for relative paths.

5 months agoFix --config-file for relative paths. master
Andre Noll [Tue, 19 Sep 2023 14:31:49 +0000 (16:31 +0200)]
Fix --config-file for relative paths.

The dss lock works by first turning the given config file path
argument into a canonical absolute path using dss_realpath(), then
hashing this absolute path to obtain a key ID for semget(2).

If the given path is relative, we have to compute the ID before
changing to the destination directory because dss_realpath() needs to
call stat(2) to detect symlinks, and this system call will fail if the
current working directory has changed. This is currently not the case
as we change to the destination directory early in check_config().

If dss_realpath() fails, we silently use the unmodified path argument
for hashing to deal with the case that the default config does not
exist. As a result, if relative paths are given, the key ID depends
on whether or not change_to_dest_dir() was called. This is the case
for the run subcommanmd, but not for the kill subcommand. Thus the
kill subcommand does not work as expected if a relative path is given.

Fix this by grabbing the lock before changing the working directory
in all cases.

6 months agoMerge branch 'master' into next
Andre Noll [Tue, 19 Sep 2023 14:46:14 +0000 (16:46 +0200)]
Merge branch 'master' into next

* master:
  Avoid duplicate error message.
  dss-1.0.1.

3 years agoAvoid duplicate error message.
Andre Noll [Sun, 17 May 2020 15:08:33 +0000 (17:08 +0200)]
Avoid duplicate error message.

If parse_config_file() encounters an error, it logs the error *and*
returns the error code, which causes the error message to be logged
again. Fix this by removing the log statement from parse_config_file().

4 years agodss-1.0.1. v1.0.1
Andre Noll [Fri, 8 Nov 2019 13:24:27 +0000 (14:24 +0100)]
dss-1.0.1.

4 years agoMerge branch 'master' into next
Andre Noll [Thu, 7 Nov 2019 11:31:36 +0000 (12:31 +0100)]
Merge branch 'master' into next

* master:

4 years agoMerge branch 'refs/heads/t/prune'
Andre Noll [Thu, 7 Nov 2019 11:31:02 +0000 (12:31 +0100)]
Merge branch 'refs/heads/t/prune'

A couple of cleanups and unifications for the snapshot pruning code,
which is executed by the prune and run subcommands. With the patches
applied, both subcommands behave identically, i.e. they consider
the same set of snapshots as candidates for pruning. Also the prune
command gained the new --disk-space option to force it to act as if
disk space was high or low.

Cooking for six weeks.

* refs/heads/t/prune:
  Introduce prune --disk-space.
  Revamp com_prune().
  Factor out find_removable_snapshot().
  prune Simplify rm exit code logic.
  find_oldest_removable_snapshot(): Improve log message.
  prune: Print a message if there is nothing to prune.
  get_snapshot_list(): Add comment about sorting.
  prune: Fail gracefully if pre-rm hook fails.

4 years agoMerge branch 'refs/heads/t/svg-logo'
Andre Noll [Wed, 30 Oct 2019 09:58:12 +0000 (10:58 +0100)]
Merge branch 'refs/heads/t/svg-logo'

Cooking for about a month. The web page has been updated today to
use the new logo.

* refs/heads/t/svg-logo:
  Redo the logo as svg.

4 years agoMerge branch 'master' into next
Andre Noll [Fri, 25 Oct 2019 11:40:09 +0000 (13:40 +0200)]
Merge branch 'master' into next

* master:
  daemon_init(): Do not set umask to zero.
  Fix logic to append slash to the source directory.

4 years agodaemon_init(): Do not set umask to zero.
Andre Noll [Fri, 25 Oct 2019 11:34:49 +0000 (13:34 +0200)]
daemon_init(): Do not set umask to zero.

We don't need this because we actively want rsync to respect the file
creation mask. This does not matter in the common case of a single
source directory because the permission bits will be copied from the
source directory anyway. However, for multiple source directories it
does matter because with umask(0) the top level snapshot directory
is created with mode 777.

4 years agoFix logic to append slash to the source directory.
Andre Noll [Fri, 25 Oct 2019 11:29:50 +0000 (13:29 +0200)]
Fix logic to append slash to the source directory.

This bug was introduced recently in commit dd3f58c0bdf1
(create_rsync_argv(): Allocate correctly sized arg array) which
redefined N.

4 years agoMerge branch 'master' into next
Andre Noll [Sun, 13 Oct 2019 04:05:17 +0000 (06:05 +0200)]
Merge branch 'master' into next

* master:
  Simplify split_args().

4 years agoSimplify split_args().
Andre Noll [Wed, 6 Feb 2019 16:37:25 +0000 (17:37 +0100)]
Simplify split_args().

Both callers pass the same value for the delimiters, so we can
remove the last argument of the function.

4 years agoMerge branch 'refs/heads/t/prune' into next
Andre Noll [Sat, 21 Sep 2019 13:12:42 +0000 (15:12 +0200)]
Merge branch 'refs/heads/t/prune' into next

* refs/heads/t/prune:
  Introduce prune --disk-space.
  Revamp com_prune().
  Factor out find_removable_snapshot().
  prune Simplify rm exit code logic.
  find_oldest_removable_snapshot(): Improve log message.
  prune: Print a message if there is nothing to prune.
  get_snapshot_list(): Add comment about sorting.
  prune: Fail gracefully if pre-rm hook fails.

4 years agoIntroduce prune --disk-space.
Andre Noll [Thu, 7 Feb 2019 22:05:34 +0000 (23:05 +0100)]
Introduce prune --disk-space.

The new option takes a mandatory argument of the set {check, high,
low}. The latter two make the command act as if disk space was
high/low without actually performing the check. This is mostly useful
for debugging.

4 years agoRevamp com_prune().
Andre Noll [Sun, 1 Sep 2019 17:34:54 +0000 (19:34 +0200)]
Revamp com_prune().

The prune subcommand implements its own logic for picking the snapshot
to remove. The algorithm is similar but not identical to how the run
subcommand gets rid of snapshots.

This patch eliminates this inconsistency by changing com_prune()
to call the find_removable_snapshot() helper which was introduced in
the previous commit.

Since find_removable_snapshot() returns a dynamically allocated string
via the "why" pointer, we have to introduce another label for freeing
this memory.

The patch also improves the help text of the prune subcommand slightly.

4 years agoFactor out find_removable_snapshot().
Andre Noll [Thu, 7 Feb 2019 19:49:19 +0000 (20:49 +0100)]
Factor out find_removable_snapshot().

Both the run and the prune subcommand contain code for picking a
suitable snapshot to remove, with slightly different semantics.

This is a preparatory patch for eliminating the differences between
the two implementations. It introduces a new helper which can be
shared. After this patch, only the run subcommand uses the helper. A
subsequent patch will convert the second caller, com_prune().

4 years agoprune Simplify rm exit code logic.
Andre Noll [Sun, 1 Sep 2019 17:31:40 +0000 (19:31 +0200)]
prune Simplify rm exit code logic.

We can rely on the fact that wait_for_remove_process() sets
snapshot_removal_status to the correct value on success.

4 years agofind_oldest_removable_snapshot(): Improve log message.
Andre Noll [Sun, 10 Feb 2019 11:05:27 +0000 (12:05 +0100)]
find_oldest_removable_snapshot(): Improve log message.

The other three functions which return a candidate for removal print
one debug message but not the name of the selected snapshot, so make
find_oldest_removable_snapshot() follow this pattern too.

4 years agoprune: Print a message if there is nothing to prune.
Andre Noll [Thu, 7 Feb 2019 18:05:24 +0000 (19:05 +0100)]
prune: Print a message if there is nothing to prune.

When the prune subcommand finds there are no snapshots to prune, the
command stays silent, which is confusing. Make it print "nothing to
prune" in this case.

4 years agoget_snapshot_list(): Add comment about sorting.
Andre Noll [Sun, 10 Feb 2019 11:05:40 +0000 (12:05 +0100)]
get_snapshot_list(): Add comment about sorting.

Callers rely on the returned snapshot list being sorted by creation
time, so let's document this fact.

4 years agoprune: Fail gracefully if pre-rm hook fails.
Andre Noll [Sun, 1 Sep 2019 17:29:39 +0000 (19:29 +0200)]
prune: Fail gracefully if pre-rm hook fails.

In this case wait_for_remove_process() returns non-negative and we
miss to set the exit code, making the command appear to succeed even
if the rm process has not been created.

4 years agoMerge branch 'refs/heads/t/svg-logo' into next
Andre Noll [Wed, 18 Sep 2019 08:34:35 +0000 (10:34 +0200)]
Merge branch 'refs/heads/t/svg-logo' into next

* refs/heads/t/svg-logo:
  Redo the logo as svg.

4 years agoMerge branch 'master' into next
Andre Noll [Wed, 18 Sep 2019 08:34:34 +0000 (10:34 +0200)]
Merge branch 'master' into next

* master:

4 years agoRedo the logo as svg.
Andre Noll [Sat, 19 Jan 2019 11:16:24 +0000 (12:16 +0100)]
Redo the logo as svg.

Scalable vector graphics are much nicer for web pages than bitmaps. The
mklogo script can be removed and there is no more dependency on
ImageMagick. What a deal.

The new logo was made with vi. It is a bit smaller than the old logo
but looks similar.

4 years agoMerge branch 'refs/heads/t/multiple-source-dirs'
Andre Noll [Wed, 18 Sep 2019 08:33:29 +0000 (10:33 +0200)]
Merge branch 'refs/heads/t/multiple-source-dirs'

Was cooking for more than a year.

* refs/heads/t/multiple-source-dirs:
  create_rsync_argv(): Allocate correctly sized arg array.
  Support multiple source directories.

4 years agoMerge branch 'refs/heads/t/multiple-source-dirs' into next
Andre Noll [Tue, 3 Sep 2019 09:12:30 +0000 (11:12 +0200)]
Merge branch 'refs/heads/t/multiple-source-dirs' into next

* refs/heads/t/multiple-source-dirs:
  create_rsync_argv(): Allocate correctly sized arg array.

4 years agocreate_rsync_argv(): Allocate correctly sized arg array.
Andre Noll [Tue, 3 Sep 2019 09:09:14 +0000 (11:09 +0200)]
create_rsync_argv(): Allocate correctly sized arg array.

In the calculation of the length of the argv array we did not take
into account that --source-dir may be given multiple times. This can
result in an invalid write at the end of the allocated space.

5 years agoMerge branch 'master' into next
Andre Noll [Mon, 11 Feb 2019 19:58:09 +0000 (20:58 +0100)]
Merge branch 'master' into next

* master:
  Remove stale comment.
  Improve comment of snapshot_currently_being_removed.

5 years agoMerge remote-tracking branch 'refs/remotes/bthcx/next' into next
Andre Noll [Sun, 10 Feb 2019 12:55:26 +0000 (13:55 +0100)]
Merge remote-tracking branch 'refs/remotes/bthcx/next' into next

* refs/remotes/bthcx/next:

5 years agoMerge branch 'master' into next
Andre Noll [Sun, 10 Feb 2019 12:52:45 +0000 (13:52 +0100)]
Merge branch 'master' into next

* master:
  Add link to author homepage.

5 years agoRemove stale comment.
Andre Noll [Thu, 7 Feb 2019 20:41:22 +0000 (21:41 +0100)]
Remove stale comment.

This comment went stale ten years ago in commit 360bcc95d588 (Clean
up snapshot removal logic) which changed the type of the return value
of find_redundant_snapshot() from int to struct snapshot *.

5 years agoImprove comment of snapshot_currently_being_removed.
Andre Noll [Thu, 7 Feb 2019 20:40:43 +0000 (21:40 +0100)]
Improve comment of snapshot_currently_being_removed.

The old comment did not provide any information at all..

5 years agoMerge branch 'master' into next
Andre Noll [Sat, 9 Feb 2019 18:32:26 +0000 (19:32 +0100)]
Merge branch 'master' into next

* master:
  Add link to author homepage.

5 years agoAdd link to author homepage.
Andre Noll [Sat, 19 Jan 2019 18:47:14 +0000 (19:47 +0100)]
Add link to author homepage.

People who like dss might also be interested in other projects of
the author.

5 years agoSupport multiple source directories.
Andre Noll [Wed, 6 Jun 2018 13:08:24 +0000 (15:08 +0200)]
Support multiple source directories.

rsync is capable of copying multiple source directories to a single
destination, but this is currently not supported by dss. This commit
adds this functionality. The implementation is straight-forward,
except that we don't want to add a trailing slash to every source
directory. The new comment in dss.c explains this in more detail.

Suggested-By: Sanja Jasek <sanja.jasek@tuebingen.mpg.de>
Tested-By: Sanja Jasek <sanja.jasek@tuebingen.mpg.de>
5 years agoFixed typo.
Sanja Jasek [Fri, 1 Jun 2018 19:53:03 +0000 (21:53 +0200)]
Fixed typo.

Signed-off-by: Andre Noll <maan@tuebingen.mpg.de>
6 years agodss-1.0.0. v1.0.0
Andre Noll [Sun, 19 Nov 2017 02:01:05 +0000 (03:01 +0100)]
dss-1.0.0.

6 years agoAdd missing newline to --version output.
Andre Noll [Sun, 19 Nov 2017 01:59:15 +0000 (02:59 +0100)]
Add missing newline to --version output.

6 years agorun: Don't kill children twice.
Andre Noll [Tue, 14 Nov 2017 03:12:02 +0000 (04:12 +0100)]
run: Don't kill children twice.

When handle_signal(), the signal dispatcher of the run subcommand,
detects that SIGINT or SIGTERM was received, it calls kill_children()
to terminate any running rsync or rm processes. It then returns
negative which terminates the select loop. However, after select_loop()
returns, kill_children() is called again. Also the error message is
logged twice.

Not a biggie, but let's get rid of this redundancy by removing the
first call to kill_children().

Since handle_signal() is only called from com_run(), this patch
affects only the run subcommand.

6 years agoFix compute_next_snapshot_time().
Andre Noll [Tue, 14 Nov 2017 02:19:58 +0000 (03:19 +0100)]
Fix compute_next_snapshot_time().

The function computes the average idle time between snapshots and adds
this value to the completion time of the last snapshot to obtain the
start time for the next snapshot.

However, if the last snapshot happens to be incomplete, its completion
time is set to -1. Hence the computed next snapshot time is going to
be in the past, so we start the next snapshot immediately.

Although this is incorrect, the bug is benign because the correct next
snapshot time should also be in the past since we decided earlier to
create the snapshot which was now found incomplete.

Fix this by using the completion time of the last _complete_ snapshot
instead.

6 years agoipc.c: Remove a dead store.
Andre Noll [Tue, 14 Nov 2017 02:18:10 +0000 (03:18 +0100)]
ipc.c: Remove a dead store.

scan-build correctly points out that the value stored to 'name'
is never read.

6 years agoSilence a bogus scan-build warning.
Andre Noll [Tue, 14 Nov 2017 02:14:47 +0000 (03:14 +0100)]
Silence a bogus scan-build warning.

We never pass a NULL pointer to create_snapshot(), but scan-build
is unable to prove this and claims that the array access results in
a  null pointer dereference. The added assertion helps the reader of
the code, and it quietens scan-build.

6 years agoReplace license boilerplate with single line SPDX comments.
Andre Noll [Mon, 6 Nov 2017 00:12:41 +0000 (01:12 +0100)]
Replace license boilerplate with single line SPDX comments.

This gets rid of existing copyright templates in favor of just the
one-liner SPDX (Software Package Data Exchange) notice. All files are
licensed under the GPL-2.0, so the same tag is added to each file. No
copyright is changed by this commit.

Several files (mostly the very short ones) did not contain a license
text so far. By default all files without license information are
under the default license of this package, which is GPL version 2.
This commit adds the missing SPDX line so that now all files except
dss.css, index.html.in, INSTALL, NEWS and README have it.

We also remove author and copyright year, since the author is the same
everywhere, and the year hasn't been updated any more since at least
six years. Accurate information is available from the git log.

The COPYING file can also be removed because the license text at
https://spdx.org/licenses/GPL-2.0.html is immutable.

6 years agoMerge branch 'refs/heads/t/kill-w'
Andre Noll [Sat, 18 Nov 2017 14:54:03 +0000 (15:54 +0100)]
Merge branch 'refs/heads/t/kill-w'

Two patches which make life easier for shutdown scripts which need
to terminate the dss process, but would like to wait until the exit
hook completed.

The merge conflicted in dss.suite, but this was trivial to fix.

Cooking for a week.

* refs/heads/t/kill-w:
  kill: New option --wait.
  run: Wait for children to die.

6 years agoMerge branch 'refs/heads/t/exit-hook'
Andre Noll [Fri, 17 Nov 2017 15:41:27 +0000 (16:41 +0100)]
Merge branch 'refs/heads/t/exit-hook'

A fix for a long standing issue with the exit hook.

Cooking for a week.

* refs/heads/t/exit-hook:
  Allow word-splitting for exit hook.

6 years agoMerge branch 'refs/heads/t/ls-incomplete-duration'
Andre Noll [Thu, 16 Nov 2017 19:57:34 +0000 (20:57 +0100)]
Merge branch 'refs/heads/t/ls-incomplete-duration'

A simple patch which improves the ls output.

Cooking for 10 days.

* refs/heads/t/ls-incomplete-duration:
  ls: Print current duration of incomplete snapshots.

6 years agoMerge branch 'refs/heads/t/mountpoint'
Andre Noll [Wed, 15 Nov 2017 18:09:06 +0000 (19:09 +0100)]
Merge branch 'refs/heads/t/mountpoint'

A new main option which aborts dss if the destination file system is
not mounted.

Cooking for two weeks.

* refs/heads/t/mountpoint:
  New option: --mountpoint.

6 years agoMerge branch 'refs/heads/t/short-log'
Andre Noll [Tue, 14 Nov 2017 15:08:52 +0000 (16:08 +0100)]
Merge branch 'refs/heads/t/short-log'

A few patches which change dss_log() to only print the time stamp
and the function if dss is executing the "run" subcommand.

Cooking for a week.

* refs/heads/t/short-log:
  Subcommand sensitive logging.
  Save the subcommand pointer in a global variable.
  main(): Don't initialize user data pointer.

6 years agofind_orphaned_snapshot(): Improve log message.
Andre Noll [Sat, 11 Nov 2017 05:24:47 +0000 (06:24 +0100)]
find_orphaned_snapshot(): Improve log message.

It is kind of obvious that find_orphaned_snapshot() looks for, well,
orphaned snapshots. The new message at least gives the user a vague
idea what this means.

6 years agoAdd log message to send_signal().
Andre Noll [Tue, 14 Nov 2017 02:39:30 +0000 (03:39 +0100)]
Add log message to send_signal().

Sending a signal is a significant event which deserves a log message.

6 years agoRemove a noisy log message.
Andre Noll [Sat, 11 Nov 2017 20:34:41 +0000 (21:34 +0100)]
Remove a noisy log message.

This message does not add any information and just spams the log
file. Remove it.

6 years agoFix bad grammar "allows <infinitive>".
Andre Noll [Tue, 7 Nov 2017 23:06:17 +0000 (00:06 +0100)]
Fix bad grammar "allows <infinitive>".

In standard English, the verb "allows" can never take an infinitive as
its direct object.

6 years agogcc-compat.h: Remove _static_inline_ macro.
Andre Noll [Mon, 6 Nov 2017 00:52:03 +0000 (01:52 +0100)]
gcc-compat.h: Remove _static_inline_ macro.

The only purpose of this macro is to have a way to include static
inline functions into the doxygen source code documentation (but omit
normal static functions in .c files).  Since dss does not use doxygen,
the macro is pointless.

Remove the equally pointless documentation of dss_rename(), one
of the two users of _static_inline_, while converting it to plain
static inline.

6 years agoClean up gcc-compat.h.
Andre Noll [Mon, 6 Nov 2017 00:47:37 +0000 (01:47 +0100)]
Clean up gcc-compat.h.

It contained three macros which are no longer used.

6 years agoMerge branch 'refs/heads/t/configtest'
Andre Noll [Mon, 13 Nov 2017 16:46:57 +0000 (17:46 +0100)]
Merge branch 'refs/heads/t/configtest'

A single patch which adds the new configtest subcommand, plus a fixup
for a formatting issue which was noticed only after the branch had
already been merged to next.

* refs/heads/t/configtest:
  show_subcommand_summary(): Increase column width.
  New subcommand: configtest.

6 years agoMerge branch 'maint'
Andre Noll [Mon, 13 Nov 2017 16:23:14 +0000 (17:23 +0100)]
Merge branch 'maint'

* maint:
  Fix snapshot removal reason.

6 years agoFix snapshot removal reason. maint
Andre Noll [Sat, 11 Nov 2017 05:16:51 +0000 (06:16 +0100)]
Fix snapshot removal reason.

If the oldest snapshot has to be removed because disk space is low,
we currently log "orphaned" as the reason, which is incorrect.

6 years agokill: New option --wait.
Andre Noll [Sun, 15 Oct 2017 16:08:47 +0000 (18:08 +0200)]
kill: New option --wait.

Simply running "dss kill" during system shutdown to terminate the
dss process does not work as expected because the kill subcommand
exits after the signal has been sent, which might be long before the
targeted dss process terminates.

For example, the dss main process might be running its exit hook to
inform the system administrator about the fact that the dss service
is going down when the shutdown procedure already has deactivated the
network. Or the shutdown procedure kills the exit hook with SIGKILL
during its normal "killing remaining processes" phase before file
systems are unmounted.

With the --wait option, the kill subcommand will not return until the
dss process has died or the timeout expires. We hardcode the timeout
in send_signal() for the time being. It can be made configurable if
this turns out to be necessary.

6 years agoAllow word-splitting for exit hook.
Andre Noll [Sun, 15 Oct 2017 18:29:39 +0000 (20:29 +0200)]
Allow word-splitting for exit hook.

All hooks except the exit hook are run via dss_exec_cmdline_pid(),
which performs word splitting to create the argument vector for
exec(2). For the exit hook, however, we build the argument vector
manually, so the command line for the exit hook is not split.

This commit removes this inconsistency. However, we can't use
dss_exec_cmdline_pid() here because we need to append the error string
which caused dss to exit to the argument vector as a single argument,
and this string may well contain whitespace characters.

Hence we run split_args() on the argument to --exit-hook to obtain
an argument vector, append the error string as another element,
and then run dss_exec().

6 years agoUpdate .gitignore.
Andre Noll [Mon, 6 Nov 2017 09:54:44 +0000 (10:54 +0100)]
Update .gitignore.

We never had .a files in the tree, and the .cmdline.[ch] files went
away when we switched to lopsub. The generated index.html was always
missing.

Moreover, let's add *.swp, the swap files created by vim to recover
crashed editing sessions.

6 years agoREADME/INSTALL: Fix typo: snaphot.
Andre Noll [Mon, 6 Nov 2017 02:34:39 +0000 (03:34 +0100)]
README/INSTALL: Fix typo: snaphot.

The typo in README was introduced two years ago in commit 05e75054
(README: Explain that there are no incremental backups) while the
one in INSTALL is more than five years old, see commit a0b6810b (doc:
Add a second example config file).

6 years agoINSTALL: Switch to https for rsync link.
Andre Noll [Mon, 6 Nov 2017 02:20:24 +0000 (03:20 +0100)]
INSTALL: Switch to https for rsync link.

The http link gives 502 (Couldn't parse server headers) at the moment
while https works.

6 years agoNEWS: Fix lopsub link.
Andre Noll [Mon, 6 Nov 2017 02:12:14 +0000 (03:12 +0100)]
NEWS: Fix lopsub link.

The tilde caused the URL to 404.

6 years agoMerge branch 'refs/heads/t/im-logo'
Andre Noll [Mon, 6 Nov 2017 00:27:30 +0000 (01:27 +0100)]
Merge branch 'refs/heads/t/im-logo'

One commit which changes the way dss.png is built and another one
which adds the generated dss.png to .gitignore.

* refs/heads/t/im-logo:
  Add dss.png to .gitignore.
  Replace dss.dia by a shell script.

6 years agols: Print current duration of incomplete snapshots.
Andre Noll [Sun, 15 Oct 2017 19:11:46 +0000 (21:11 +0200)]
ls: Print current duration of incomplete snapshots.

Currently the duration of incomplete (and orphaned) snapshots is shown
as 0:00. It's more interesting to see for how long the snapshot is
already being created, so print the difference of the current time
and the start time instead.

Fix an overlong line and a whitespace issue while at it.

6 years agoshow_subcommand_summary(): Increase column width.
Andre Noll [Sat, 4 Nov 2017 12:13:48 +0000 (13:13 +0100)]
show_subcommand_summary(): Increase column width.

Since the new configtest command is 10 characters long, there was no
whitespace between the command name and the short description.

6 years agorun: Wait for children to die.
Andre Noll [Mon, 16 Oct 2017 15:36:51 +0000 (17:36 +0200)]
run: Wait for children to die.

When the select loop returns and dss is about to terminate, it sends
SIGTERM to any running rm or rsync processes and exits. It does not
wait for these processes to die, however. This is trivial to implement,
and it makes life easier for shutdown scripts which like to proceed
with unmounting file systems.

6 years agoNew subcommand: configtest.
Andre Noll [Sun, 15 Oct 2017 13:03:08 +0000 (15:03 +0200)]
New subcommand: configtest.

Similar to the identically named subcommand of apache2ctl. This is
trivial to implement because we only need to describe the subcommand
in dss.suite and create a command handler which prints an OK message
and returns success. If the config file contains errors, we abort
earlier anyway.

6 years agoSubcommand sensitive logging.
Andre Noll [Tue, 17 Oct 2017 17:19:51 +0000 (19:19 +0200)]
Subcommand sensitive logging.

It's kind of silly to log the current time and the function name for
subcommands other than "run", since these commands run only for a
short time.

This commit changes dss_log() to only print this additional information
when dss run is being executed.

6 years agoSave the subcommand pointer in a global variable.
Andre Noll [Tue, 17 Oct 2017 17:11:07 +0000 (19:11 +0200)]
Save the subcommand pointer in a global variable.

This is needed for subcommand sensitive logging which will be
introduced in a subsequent commit. For now it allows to drop the
argument of check_config(), which is good given that handle_sighup()
already played dirty games by "knowing" it is only called from the
run subcommand.

6 years agomain(): Don't initialize user data pointer.
Andre Noll [Tue, 17 Oct 2017 16:59:42 +0000 (18:59 +0200)]
main(): Don't initialize user data pointer.

It is never used uninitialized. The unnecessary initialization only
hides the warning from the compiler if it ever should ever be used
uninitialized.

6 years agoNew option: --mountpoint.
Andre Noll [Mon, 16 Oct 2017 15:19:08 +0000 (17:19 +0200)]
New option: --mountpoint.

The new option applies to run, create, ls and prune. The feature
could be implemented as a pre-create hook, but since it is so common,
it makes sense to add it to dss proper.

As for the implementation we simply check that "." and ".." are on
different devices (or are identical).

6 years agoMerge branch 'refs/heads/t/lopsub'
Andre Noll [Sun, 15 Oct 2017 12:51:29 +0000 (14:51 +0200)]
Merge branch 'refs/heads/t/lopsub'

Conversion to lopsub and a few other improvements on top of it.

* refs/heads/t/lopsub:
  INSTALL: Explain how to use CPPFLAGS and LDFLAGS.
  build: Introduce DSS_CPPFLAGS.
  build: Fix cc command which creates dependencies,
  build: Combine CFLAGS and DEBUG_CFLAGS.
  Implement --checksum.
  run: Improve error diagnostics for chdir(2) failure.
  run: Improve error message if dss is already running.
  run: Fix exit status in case another dss process is running.
  build: Add target install and install-strip.
  Convert dss to lopsub.
  Remove --no-resume.

6 years agoRevert "ipc.c: Use ftok() instead of SuperFastHash."
Andre Noll [Wed, 6 Sep 2017 12:57:28 +0000 (14:57 +0200)]
Revert "ipc.c: Use ftok() instead of SuperFastHash."

This reverts commit c92370affe722f38a85a41d1b5524e4a102b8f4d.

This was not a good idea because ftok(3) hashes, among other
information, the inode number of the file, and this number changes
every time the configuration file is edited.

The revert conflicted slightly to the commit which renamed
get_key_or_die() to get_key() and changed the type of the return
value to key_t, but the conflict was easy to resolve.

6 years agoipc: Improve error diagnostics for kill.
Andre Noll [Sun, 16 Apr 2017 10:48:58 +0000 (12:48 +0200)]
ipc: Improve error diagnostics for kill.

If dss is not running, the kill command prints "No such file or
directory" because the call to semget(2) fails with ENOENT. This
message is a bit misleading, so let's return -E_NOT_RUNNING in this
case instead.

6 years agoAdd dss.png to .gitignore.
Andre Noll [Thu, 13 Jul 2017 19:03:48 +0000 (21:03 +0200)]
Add dss.png to .gitignore.

It's a generated file which should never be under version control.

6 years agoReplace dss.dia by a shell script.
Andre Noll [Sun, 30 Apr 2017 00:33:57 +0000 (02:33 +0200)]
Replace dss.dia by a shell script.

The dia command line tool misaligns the text on the dss logo, and the
dia application started to segfault on my home box after a library
upgrade.

This patch replaces the dia source file by the mklogo bash script
which runs the convert utility of ImageMagick to write the dss logo
in png format to stdout.

The result looks almost identical.

6 years agoINSTALL: Explain how to use CPPFLAGS and LDFLAGS.
Andre Noll [Thu, 13 Jul 2017 20:51:45 +0000 (22:51 +0200)]
INSTALL: Explain how to use CPPFLAGS and LDFLAGS.

6 years agobuild: Introduce DSS_CPPFLAGS.
Andre Noll [Thu, 13 Jul 2017 17:43:04 +0000 (19:43 +0200)]
build: Introduce DSS_CPPFLAGS.

As with CFLAGS, it is good practice to leave CPPFLAGS unset in the
Makefile and append it to the cc command after our own flags, to give
the user a chance to override our settings.

This patch initializes DSS_CPPFLAGS with the VERSION_STRING define
which was part of the receipe and adds -Wunused macros, which is a
preprocessor flag rather than a compiler flag.

DSS_CPPFLAGS and CPPFLAGS are added to the two relevant commands,
in addition to the existing DSS_CFLAGS and CFLAGS.

6 years agobuild: Fix cc command which creates dependencies,
Andre Noll [Thu, 13 Jul 2017 17:33:52 +0000 (19:33 +0200)]
build: Fix cc command which creates dependencies,

The command to create Makefile.deps was hardcoded as gcc in Makefile.
This patch changes the command to $(CC) and adds the usual set of
flags which we use for compiling.

6 years agobuild: Combine CFLAGS and DEBUG_CFLAGS.
Andre Noll [Thu, 13 Jul 2017 17:21:11 +0000 (19:21 +0200)]
build: Combine CFLAGS and DEBUG_CFLAGS.

We needed two sets of flags for gengetopt because the C code generated
by gengetopt would not compile cleanly with our rather strict set of
flags. With lopsub this is no longer necessary.

Moreover, it is considered good practice to not set CFLAGS at all but
to append the contents of this variable to the compile command. This
way the user may set the variable to override some of the options.

This commit gets rid of CFLAGS in favor of DSS_CFLAGS, which is just
the union of the CFLAGS and the DEBUG_CFLAGS variables we had before.

6 years agoImplement --checksum.
Andre Noll [Mon, 17 Apr 2017 17:06:37 +0000 (19:06 +0200)]
Implement --checksum.

It is considered good practice to run rsync with --checksum from time
to time. This patch implements the feature via the new --checksum
option.

The probabilistic approach was chosen so that dss does not need to
remember which snapshots were created with --checksum.

6 years agorun: Improve error diagnostics for chdir(2) failure.
Andre Noll [Sun, 16 Apr 2017 10:01:42 +0000 (12:01 +0200)]
run: Improve error diagnostics for chdir(2) failure.

In run mode, if the destination directory does not exist, dss prints
"No such file or directory" and exits, without telling the user (a)
it was a failed chdir(2) call that caused the error, and (b) the name
of the directory. This patch adds an error message containing this
information.

Since there is only one caller of dss_chdir(), let's get rid
of this public function in file.c and call chdir() directly from
change_to_dest_dir() of dss.c.

6 years agorun: Improve error message if dss is already running.
Andre Noll [Fri, 17 Jun 2016 07:29:12 +0000 (09:29 +0200)]
run: Improve error message if dss is already running.

The current error message, "child terminated unexpectedly", is not
very comprehensive.

The most likely reason for the child to terminate is that it could not
obtain the semaphore lock because another dss process is running. This
commit adds a test to com_run() that check this condition in the
parent before the child process is born. This way, if another process
is holding the lock, we can fail with a nice error message that also
includes the pid of the process that holds the lock.

6 years agorun: Fix exit status in case another dss process is running.
Andre Noll [Thu, 16 Jun 2016 21:21:08 +0000 (23:21 +0200)]
run: Fix exit status in case another dss process is running.

In daemon mode, we must acquire the semaphore lock in the child process
because the child does not inherit semaphore adjustments. Currently
the parent exits successfully after the fork, so the command appears
to succeed even if the child dies immediately because it was unable
to acquire the lock because another dss process is holding the lock.

This commit introduces a mechanism which enables the parent to tell
whether the child completed its setup successfully. We create a
pipe prior to calling fork(2), and let the child write to one end
of the pipe after setup is complete and just before it enters the
main select loop. The parent reads from the other end of the pipe
and exits once the read(2) call returns. If the child dies early,
read(2) returns zero, indicating failure.

6 years agobuild: Add target install and install-strip.
Andre Noll [Sun, 16 Apr 2017 11:56:09 +0000 (13:56 +0200)]
build: Add target install and install-strip.

It has always been a bit clumsy to copy the executable and the
manual page to their proper locations by hand, so this commit adds
the two standard targets "install" and "install-strip" which install
both files.

The installation prefix defaults to /usr/local and can be set with
PREFIX. Moreover, there is DESTDIR which may be given to prepend
another directory (useful for for "staged installs", where the
installed files are not placed directly into their expected location
but are instead copied into a temporary location).

6 years agoConvert dss to lopsub.
Andre Noll [Fri, 6 May 2016 14:18:24 +0000 (16:18 +0200)]
Convert dss to lopsub.

This commit ditches gengetopt for the command line and config file
parsers in favor of the lopsub library. Hence from now on, lopsub
must be installed in order to compile dss while gengetopt is no
longer needed.

The mutually exclusive gengetopt group options --create, --prune, --ls,
--run, --kill and --reload are replaced by lopsub subcommands. However,
the --reload and --kill options have been combined to the new "kill"
subcommand which allows to send arbitrary signals to a running dss
process.

Due to the conversion, the syntax of the dss command changes
slightly. For example,

dss --run

becomes

dss run

while

dss -Rdc foo

needs to be spelled as

dss -c foo -- run -d

so that -d is regarded as an option to the "run" subcommand rather
than an option to dss.

With lopsub each subcommand has its own command line and config file
parser. Options to subcommands can be added to the configuration file
like this:

[run]
daemon
logfile=/var/log/dss.log

As for the implementation, the bulk of the changes is the conversion
of dss.ggo to the new dss.suite. The necessary adjustments to the
code are relatively simple. In particular, only dss.c needs to be
changed while all other .c files don't require any modifications.

The examples in INSTALL are adjusted to the new syntax. The commit also
drops support for Mac OS and Solaris, since lopsub is not supported
on these platforms yet.

6 years agoipc: Combine mutex_lock() and lock_dss().
Andre Noll [Sun, 16 Apr 2017 10:37:01 +0000 (12:37 +0200)]
ipc: Combine mutex_lock() and lock_dss().

The former function is only called by the latter, and both are short,
so let's combine them.

6 years agoipc: Prefer key_t over int for System V IPC keys.
Andre Noll [Fri, 17 Feb 2017 14:40:58 +0000 (15:40 +0100)]
ipc: Prefer key_t over int for System V IPC keys.

get_key() calls ftok(3), which returns a key_t value. key_t is also
the type which semget(2), the only function which receives the key via
mutex_get(), expects. It's stupid to convert the key_t from ftok(3)
into an int, only to convert it back to key_t later.

This patch changes ipc.c to use key_t everywhere. However, in
mutex_get() we print a log message containing the value of the key,
so the format string must be adjusted accordingly. Unfortunately,
on Linux, key_t is the same as int while on FreeBSD and NetBSD it is
defined as long. To avoid a warning from the compiler we use "%lx"
in the format string and cast the value to long.

6 years agoipc.c: Use ftok() instead of SuperFastHash.
Andre Noll [Fri, 17 Feb 2017 14:29:52 +0000 (15:29 +0100)]
ipc.c: Use ftok() instead of SuperFastHash.

ftok(3) uses the identity of the named file to generate a key_t type
System V IPC key, which is easier than computing the key by hashing
the (resolved) pathname of the config file. This change allows to
get rid of the realpath() and the super_fast_hash() implementation.

If ftok(3) fails, presumably because the underlying call to stat(2)
fails, we now simply return a phony identifier, similar to what we did
before in this case. This eliminates the only possible failure path
in get_key_or_die(), so this function is renamed to get_key().

7 years agoRemove --no-resume.
Andre Noll [Mon, 9 May 2016 09:03:45 +0000 (11:03 +0200)]
Remove --no-resume.

There is no real reason for this option. Resuming a previously
cancelled snapshot is generally a very good idea, so the option is
kind of pointless. Remove it.

7 years agodss-0.1.7. v0.1.7
Andre Noll [Sun, 16 Apr 2017 11:43:20 +0000 (13:43 +0200)]
dss-0.1.7.

A couple of fixes and improvements have accumulated over the last
year, so here's dss-0.1.7. Most likely this is going to be the last
0.1.x release.

7 years agoDon't shadow cmdline_parser_params in main().
Andre Noll [Sun, 16 Apr 2017 11:25:10 +0000 (13:25 +0200)]
Don't shadow cmdline_parser_params in main().

This avoids

dss.c:1519:32: warning: declaration of 'params' shadows a previous local [-Wshadow]

The warning is harmless, though.

7 years agoipc.c: Uninline get_key_or_die().
Andre Noll [Fri, 17 Feb 2017 14:36:50 +0000 (15:36 +0100)]
ipc.c: Uninline get_key_or_die().

This function is rather big, so it's not clear whether it should
be inlined or not. Without the inline attribute, that's up to the
compiler to decide.

7 years agoipc.c: Constify parameter of get_key_or_die().
Andre Noll [Fri, 17 Feb 2017 14:15:10 +0000 (15:15 +0100)]
ipc.c: Constify parameter of get_key_or_die().

The function only reads from the location pointed at by the config_file
variable.

7 years agoipc: Fix error code returned by mutex_lock().
Andre Noll [Sun, 16 Apr 2017 10:18:11 +0000 (12:18 +0200)]
ipc: Fix error code returned by mutex_lock().

In the error case do_semop() already returns the error code which
corresponds to errno.

7 years agoImprove log message for snapshot creation.
Andre Noll [Tue, 23 Aug 2016 11:26:25 +0000 (13:26 +0200)]
Improve log message for snapshot creation.

The log message that prints the name of the snapshot which is going to
be recycled is kind of interesting and deserves the "notice" severity.

The "creating new snapshot" message is a bit misleading in case we
decided to recycle a snapshot, so drop the word "new".

7 years agoipc: Simplify mutex_try_lock().
Andre Noll [Fri, 17 Jun 2016 07:18:40 +0000 (09:18 +0200)]
ipc: Simplify mutex_try_lock().

There is no need to actually obtain the lock. A single semaphore
operation will do just fine. With sem_op equal to zero and IPC_NOWAIT
the semop() call returns immediately, and the return value tells
whether the semaphore value was zero.

Rename the (static) function to mutex_is_locked() to indicate that
it performs only read-only operations on the semaphore set.

7 years agoipc: Make pid pointer optional.
Andre Noll [Thu, 16 Jun 2016 21:06:29 +0000 (23:06 +0200)]
ipc: Make pid pointer optional.

This changes get_dss_pid() to handle the case where the caller passed
a NULL pid pointer. Conversely, if pid is not NULL, we now make sure
to initialize the given address in all cases.

The single caller currently never passes NULL, so this change is just
defensive programming, protecting against future users. Be liberal
in what you accept, be strict in what you return..