Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make -c useful again #88

Merged
merged 13 commits into from
Aug 16, 2016
Merged

Make -c useful again #88

merged 13 commits into from
Aug 16, 2016

Conversation

demonbane
Copy link
Collaborator

This changes the behavior of the -c option to make it useful for cron users with or without the -q option. Without -q, output will only be generated if something is actually done. With -q, output will only be generated in the event of an error. In both cases, exit codes will be "normalized" so that systemd doesn't get false alarms.

There are also a handful of other commits here for random code cleanup that I did as part of this work. I intentionally didn't squash these so that if anyone has a problem with some of the changes we can easily do a git revert.

Closes #84

@demonbane
Copy link
Collaborator Author

Any feedback on this or are you still reviewing?

@@ -327,6 +331,11 @@ keypair() {

# Setup an cronexit handler so we cleanup
function cleanup {
if [ "${CRON}" = yes -a "${rawexit}" -ne 5 -a -f "${stdoutlog}" ]; then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use upper-case variables

@mrworf
Copy link
Owner

mrworf commented Aug 16, 2016

Sorry for the lag, was on a mini-vacation and didn't have much (if any) internet.
Awesome job cleaning it up, had just a few comments otherwise looks good.

cronexit 1
fi
fi


# Remove any ~ or other oddness in the path we're given
DOWNLOADDIR="$(eval cd ${DOWNLOADDIR// /\\ } ; if [ $? -eq 0 ]; then pwd; fi)"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a reason for doing this, and I think it relates to the use of ~ in the path. Without eval, ~ doesn't work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to investigate this one further. My command-line tests with eval removed were fine, but I want to check for any edge cases where it might break.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gets tricky when you source a file where a variable is assigned a path with ~ in it, that's what I can remember anyway. Doing it on cmdline is different since bash might be expanding it for you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason my tests ended up working was, in fact, due to expansion. When I tried single-quotes or variables it ended up breaking.

So I spent way too much time after that looking for an alternative and what it's come down to is either using an overly-complicated block of code, or just accepting the fact that the value of DOWNLOADDIR could, theoretically, be an attack vector for an injection attack, but it's just not worth obsessing over.

So this is how I learned to stop worrying and love the eval. ¯\_(ツ)_/¯

@@ -275,7 +275,7 @@ fi

# Remove any ~ or other oddness in the path we're given
DOWNLOADDIR="$(cd ${DOWNLOADDIR// /\\ } && pwd)"
if [ -z "${DOWNLOADDIR}" ]; then
if [ ! -d "${DOWNLOADDIR}" ]; then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't "" point to current directory and be somewhat unexpected since that should never happen? Because if cd fails, then I think downloaddir will be blank, right?

Copy link
Collaborator Author

@demonbane demonbane Aug 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A null string only points to current directory for things like cd. For tests, it's treated as a "literal" null string which has no path equivalent.

$ [ -d "" ] || echo nope
nope
$

And while you're right that downloaddir would be blank if cd failed anyway, checking to see if a directory path is a valid directory seemed more readable to me than checking if a directory path is an empty string.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, tested it too after I wrote the comment and ! -d "" will fail, so all good.

@demonbane
Copy link
Collaborator Author

I think this covers most of it. Does everything else look good?

@mrworf mrworf merged commit 482f1d2 into mrworf:master Aug 16, 2016
@demonbane demonbane deleted the cron-changes branch August 17, 2016 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants