-
Notifications
You must be signed in to change notification settings - Fork 51
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
cron: avoid use of json-c and xzmalloc #1143
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1143 +/- ##
==========================================
+ Coverage 77.55% 77.57% +0.02%
==========================================
Files 157 157
Lines 28699 28756 +57
==========================================
+ Hits 22257 22308 +51
- Misses 6442 6448 +6
|
This is excellent cleanup. I'll give it a bit more thorough review on monday, but looks good so far. I was going to say something about calloc/strdup not setting errno, but according to the man page they do per UNIX98! Ugh, I had been assuming they didn't. I will need to mend my ways and fix some code. |
437a4b1
to
ed1d105
Compare
Well you caught me, I just assumed they set errno appropriately. Thanks for checking on it. I've pushed a rebase on current master. Also, I noticed that the cron module appeared to be the last user of |
Hm, one build failed with a |
One other review comment since at one point this came up in discussion: the jansson unpack |
Thanks for double checking on that. |
Add a function to set a single integer value for any time unit member of a cronodate object. This is a convenience function to prevent requiring a single integer to be converted to a string and passed in as a range, which is then converted right back to an integer.
Test new API function cronodate_set_integer().
Promote arguments and options that should be encoded as numbers in JSON usint tonumber() where appropriate. Jansson seems to be less forgiving about encoding numbers as strings when parsing message payloads.
Remove calls to xzmalloc() and xstrdup in favor of straight malloc(). Return errors to caller (when possible) instead of using oom() etc to abort when memory allocations fail.
Drop use of json-c and shortjson.h in cron module in favor of jansson.
Fix missing free of `typename` member of cron entry object. Also, remove unnecessary const qualifier on this member.
Allow datetime 'ranges' to be numeric arguments as well as string ranges in the cron datetime handler. This is required because the lua frontend flux-cron(1) utility always encodes numbers that are integers as JSON ints.
Avoid implicit rounding in timespec_to_double in both cron.c and task.c. For the cron task timestamps, rename the local function round_timespec_to_double() to be honest about what we're doing, and expand the comment to explain why. For other cron timestamps, just drop the rounding for now. If it an inconvenience in the future (unlikely), the rounding can be copied from task.c as an example. Resolves flux-framework#1131
For efficiency, make cron_task_run() take a json_t object instead of a char ** environment array. This will allow cron entry to store the optional environment array as a JSON object, and avoid conversion from JSON to character array and back again.
Allow optional cwd and environment to be passed in during cron.create, and store these as part of the cron entry, to be sent along with each cron task invocation.
Add --preserve-env and --working-dir=DIR options to send current environment as cron task environment, and DIR as current working directory.
Add documentation for the --preserve-env and --working-dir options to the 'event' 'interval' 'tab' and 'at' subcommands.
Add tests for --preserve-env and --working-dir options.
Enhance check for cron module loaded with sync enabled. Ensure both sync event and sync_epsilon match what was passed on the cmdline.
Jadd_bool no longer has any users. Remove it.
To save time, add --disable-romio to mpich build in travis-ci.
Is this one ready? |
Yes, unless there was more someone wanted me to do... |
LGTM. |
This PR updates the cron module to use jansson instead of json-c, removes other uses of xzmalloc that would result in calls to
oom()
and friends, and fixes some other leaks and issues found along the way.A new function for was added to the cronodate interface to allow adding non-range integers to a cronodate object, for cases where arguments to cron "datetime" entries are encoded by the caller as numbers and not strings (as is done for ranges, e.g. "0-3" or glob "*"). The datetime argument parser was then updated to check for whether individual arguments were encoded as strings or numbers, and uses the appropriate function
cronodate_set
orcronodate_set_integer
. This is required because unlike json-c, jansson doesn't allow decoding a number value as a string.This PR is based on top of #1142, becuase otherwise I couldn't get successful builds in my own branch. I'll rebase if that PR gets merged.