systemctl: improve readability of start_unit()
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>
Fri, 18 Aug 2017 12:18:09 +0000 (13:18 +0100)
committerAlan Jenkins <alan.christopher.jenkins@gmail.com>
Thu, 31 Aug 2017 13:05:28 +0000 (14:05 +0100)
commit913c19161a8235f8e89fe31132196ad5af33c269
treed0275f4802d1d9ce9f86edf4d3a5d9809cf4fe86
parentf886603b7eba6a11b7b48d8b6b04a05aaa960b1a
systemctl: improve readability of start_unit()

start_unit() is a little tangled.  There's an easy part we can untangle,
then readers can concentrate on the more necessary complexity.

* Derive (method, action, mode) more clearly, as disjoint cases based on
  the command.  Don't rely on action_table[_ACTION_INVALID].target being
  implicitly initialized to NULL.

  verb_to_method() is now only used on one case, but not because I strongly
  object to the implicit "StartUnit" cases.  It's more a syntax problem.
  I think the old code takes me longer to understand, because the call
  comes just above a similar-looking call to verb_to_action(), but the
  results of the two functions are used in different ways.  It also helps
  that the new code ends up having a more regular form, for the 4 different
  cases.

  These changes cost 6 extra lines.

* Add an assertion to confirm that we do not pass mode=NULL.
src/systemctl/systemctl.c