Skip to content

Commit

Permalink
suspend pre / post logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Schleizer committed Mar 18, 2016
1 parent 89de971 commit 95850f6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
11 changes: 9 additions & 2 deletions usr/lib/sdwdate/clock-fix
@@ -1,19 +1,26 @@
#!/bin/bash

set -x
set -e

if [ ! "$(id -u)" = "0" ]; then
echo "ERROR: Must run as root!" >&2
echo "$0 ERROR: Must run as root!" >> /var/log/sdwdate.log
exit 2
fi

if [ -d "/usr/lib/qubes" ]; then
randomized_unix_time="$(timeout --kill-after="5" "5" /usr/lib/qubes/qrexec-client-vm dom0 qubes.GetRandomizedTime)"
else
echo "ERROR: Not implemented in Non-Qubes-Whonix. See: https://www.whonix.org/wiki/Troubleshooting#Clock_Fix" >&2
echo "$0 INFO: Clock fix after resume not implemented in Non-Qubes-Whonix. See: https://www.whonix.org/wiki/Troubleshooting#Clock_Fix" >> /var/log/sdwdate.log
exit 3
fi

echo "$0 INFO: date before roughly fixing it: $(date -u)" >> /var/log/sdwdate.log

date --set "@$randomized_unix_time" >/dev/null

echo "$0 INFO: date after roughly fixing it : $(date -u)" >> /var/log/sdwdate.log

echo "$0 INFO: Restarting sdwdate..." >> /var/log/sdwdate.log
service sdwdate restart
echo "$0 INFO: Done, restarted sdwdate." >> /var/log/sdwdate.log
9 changes: 8 additions & 1 deletion usr/lib/sdwdate/suspend-post
@@ -1,14 +1,21 @@
#!/bin/bash

set -x
set -e

if [ ! "$(id -u)" = "0" ]; then
echo "ERROR: Must run as root!" >&2
echo "$0 ERROR: Must run as root!" >> /var/log/sdwdate.log
exit 2
fi

## Do not interfere with the clock if the service was stopped.
if test -f /var/run/sdwdate/was_running.status ; then
echo "$0 INFO: Deleting /var/run/sdwdate/was_running.status..." >> /var/log/sdwdate.log
rm -f /var/run/sdwdate/was_running.status
echo "$0 INFO: Done, deleted /var/run/sdwdate/was_running.status." >> /var/log/sdwdate.log
echo "$0 INFO: Running /usr/lib/sdwdate/clock-fix..."
/usr/lib/sdwdate/clock-fix || true
echo "$0 INFO: Done with /usr/lib/sdwdate/clock-fix."
else
echo "$0 INFO: File /var/run/sdwdate/was_running.status did not exist, meaning we previously did not stop sdwdate so not starting it now." >> /var/log/sdwdate.log
fi
9 changes: 8 additions & 1 deletion usr/lib/sdwdate/suspend-pre
@@ -1,13 +1,20 @@
#!/bin/bash

set -x
set -e

if [ ! "$(id -u)" = "0" ]; then
echo "ERROR: Must run as root!" >&2
echo "$0 ERROR: Must run as root!" >> /var/log/sdwdate.log
exit 2
fi

if service sdwdate status >/dev/null ; then
echo "$0 INFO: Creating /var/run/sdwdate/was_running.status..." >> /var/log/sdwdate.log
touch /var/run/sdwdate/was_running.status
echo "$0 INFO: Done, created /var/run/sdwdate/was_running.status." >> /var/log/sdwdate.log
echo "$0 INFO: Stopping sdwdate..." >> /var/log/sdwdate.log
service sdwdate stop
echo "$0 INFO: Done, stopped sdwdate." >> /var/log/sdwdate.log
else
echo "$0 INFO: sdwdate was not running, no need to stop it." >> /var/log/sdwdate.log
fi

0 comments on commit 95850f6

Please sign in to comment.