summaryrefslogtreecommitdiff
path: root/dss.c (follow)
Commit message (Collapse)AuthorAge
* Switch back to variadic log macros.HEADpumasterAndre Noll2025-03-23
| | | | | | | | | | | | | This essentially reverts commit 66cdd5bc99a5 which aimed to make the dss log facility C89 conform. While this was a worthwhile goal in 2012, it has little value today, since in 2025 we can safely assume a C99 compliant compiler. The patch was created with git revert -Xours 66cdd5bc followed by manual tweaks to make it compile again.
* Dedoxify the source.Andre Noll2025-02-01
| | | | | | The doxygen comments actually make the source code harder to read, because they tend to document the obvious. Besides, they are not used uniformly accross the code base anyway.
* New subcommand: help.Andre Noll2024-07-18
| | | | | It's sometimes handy to just type e.g. "dss help run" to see the synopsis and the options of the ls subcommand.
* build: Dynamic dependency creation and versioning.Andre Noll2024-07-02
| | | | | | | This gets rid of Makefile.deps in favor of one auto-generated .d file per .c file, and adds version-gen.sh, a shell script executed by make(1) which tries to determine the version number that is going to be incorporated into the executable via the generated version.c.
* Compute ipc key only once.Andre Noll2024-05-23
| | | | | It's easier if dss.c passes the hash of the the config file path to the ipc functions than to pass a char pointer.
* Resolve config file path only once.Andre Noll2024-05-23
| | | | | | | | Currently we call get_config_file_name() before each call call to a public function of ipc.c because those functions compute the IPC key from the filename. This is unnecessary and caused several bugs. Clean up this mess by computing the filename only once and store it in a global variable.
* Fix --config-file for relative paths.Andre Noll2023-11-07
| | | | | | | | | | | | | | | | | | | | | | 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.
* Avoid duplicate error message.Andre Noll2020-05-17
| | | | | | 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().
* Merge branch 'refs/heads/t/prune'Andre Noll2019-11-07
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Introduce prune --disk-space.Andre Noll2019-09-21
| | | | | | | | | | | | | | 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.
| * Revamp com_prune().Andre Noll2019-09-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Factor out find_removable_snapshot().Andre Noll2019-09-21
| | | | | | | | | | | | | | | | | | | | 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().
| * prune Simplify rm exit code logic.Andre Noll2019-09-21
| | | | | | | | | | We can rely on the fact that wait_for_remove_process() sets snapshot_removal_status to the correct value on success.
| * find_oldest_removable_snapshot(): Improve log message.Andre Noll2019-09-21
| | | | | | | | | | | | 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.
| * prune: Print a message if there is nothing to prune.Andre Noll2019-09-21
| | | | | | | | | | | | 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.
| * prune: Fail gracefully if pre-rm hook fails.Andre Noll2019-09-21
| | | | | | | | | | | | 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.
* | Fix logic to append slash to the source directory.Andre Noll2019-10-25
| | | | | | | | | | | | This bug was introduced recently in commit dd3f58c0bdf1 (create_rsync_argv(): Allocate correctly sized arg array) which redefined N.
* | Simplify split_args().Andre Noll2019-10-13
|/ | | | | Both callers pass the same value for the delimiters, so we can remove the last argument of the function.
* Merge branch 'refs/heads/t/multiple-source-dirs'Andre Noll2019-09-18
|\ | | | | | | | | | | | | | | 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.
| * create_rsync_argv(): Allocate correctly sized arg array.Andre Noll2019-09-03
| | | | | | | | | | | | 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.
| * Support multiple source directories.Andre Noll2018-06-08
| | | | | | | | | | | | | | | | | | | | | | 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>
* | Remove stale comment.Andre Noll2019-02-10
| | | | | | | | | | | | 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 *.
* | Improve comment of snapshot_currently_being_removed.Andre Noll2019-02-10
|/ | | | The old comment did not provide any information at all..
* Fixed typo.Sanja Jasek2018-06-04
| | | | Signed-off-by: Andre Noll <maan@tuebingen.mpg.de>
* Add missing newline to --version output.Andre Noll2017-11-19
|
* run: Don't kill children twice.Andre Noll2017-11-19
| | | | | | | | | | | | | | | 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.
* Fix compute_next_snapshot_time().Andre Noll2017-11-19
| | | | | | | | | | | | | | | | | 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.
* Silence a bogus scan-build warning.Andre Noll2017-11-19
| | | | | | | 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.
* Replace license boilerplate with single line SPDX comments.Andre Noll2017-11-19
| | | | | | | | | | | | | | | | | | | | 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.
* Merge branch 'refs/heads/t/kill-w'Andre Noll2017-11-18
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * kill: New option --wait.Andre Noll2017-11-11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * run: Wait for children to die.Andre Noll2017-11-02
| | | | | | | | | | | | | | | | 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.
* | Merge branch 'refs/heads/t/exit-hook'Andre Noll2017-11-17
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | Allow word-splitting for exit hook.Andre Noll2017-11-07
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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().
* | Merge branch 'refs/heads/t/ls-incomplete-duration'Andre Noll2017-11-16
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | ls: Print current duration of incomplete snapshots.Andre Noll2017-11-06
| |/ | | | | | | | | | | | | | | | | 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.
* | Merge branch 'refs/heads/t/mountpoint'Andre Noll2017-11-15
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | New option: --mountpoint.Andre Noll2017-10-21
| |/ | | | | | | | | | | | | | | | | 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).
* | Merge branch 'refs/heads/t/short-log'Andre Noll2017-11-14
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | Subcommand sensitive logging.Andre Noll2017-10-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | Save the subcommand pointer in a global variable.Andre Noll2017-10-28
| | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | main(): Don't initialize user data pointer.Andre Noll2017-10-28
| |/ | | | | | | | | | | It is never used uninitialized. The unnecessary initialization only hides the warning from the compiler if it ever should ever be used uninitialized.
* | find_orphaned_snapshot(): Improve log message.Andre Noll2017-11-14
| | | | | | | | | | | | 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.
* | Add log message to send_signal().Andre Noll2017-11-14
| | | | | | | | Sending a signal is a significant event which deserves a log message.
* | Merge branch 'refs/heads/t/configtest'Andre Noll2017-11-13
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | show_subcommand_summary(): Increase column width.Andre Noll2017-11-04
| | | | | | | | | | | | | | | Since the new configtest command is 10 characters long, there was no whitespace between the command name and the short description.
| * | New subcommand: configtest.Andre Noll2017-10-28
| |/ | | | | | | | | | | | | | | 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.
* | Merge branch 'maint'Andre Noll2017-11-13
|\ \ | |/ |/| | | | | * maint: Fix snapshot removal reason.
| * Fix snapshot removal reason.maintAndre Noll2017-11-13
| | | | | | | | | | If the oldest snapshot has to be removed because disk space is low, we currently log "orphaned" as the reason, which is incorrect.
* | Implement --checksum.Andre Noll2017-07-13
| | | | | | | | | | | | | | | | | | 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.