author | Olivier Brunel
<jjk@jjacky.com> 2015-07-17 16:39:48 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2015-07-21 12:35:51 UTC |
parent | 9eaeb0a0e08802604bf732d5b9997c15d7b13afa |
doc/aa-start.pod | +3 | -0 |
src/anopa/aa-start.c | +5 | -2 |
src/include/anopa/service.h | +3 | -2 |
src/libanopa/service.c | +27 | -17 |
src/libanopa/service_internal.h | +1 | -0 |
src/libanopa/service_start.c | +4 | -4 |
diff --git a/doc/aa-start.pod b/doc/aa-start.pod index 639b163..5e0a955 100644 --- a/doc/aa-start.pod +++ b/doc/aa-start.pod @@ -34,6 +34,9 @@ I</etc/anopa/listdirs/> Only print the name of the services, but do not start anything. +Specify a second time to list services that need to be up instead of those that +would be started, i.e. include those already up. + =item B<-r, --repodir> I<dir> Use I<dir> as repository directory. This is where servicedirs will be looked diff --git a/src/anopa/aa-start.c b/src/anopa/aa-start.c index 9df069f..2c08943 100644 --- a/src/anopa/aa-start.c +++ b/src/anopa/aa-start.c @@ -122,7 +122,7 @@ add_service (const char *name) if (type < 0) r = type; else - r = aa_mark_service (si, type == AA_SERVICE_FROM_MAIN, no_wants, load_fail_cb); + r = aa_mark_service (mode, si, type == AA_SERVICE_FROM_MAIN, no_wants, load_fail_cb); if (r < 0) { if (r == -ERR_UNKNOWN) @@ -273,7 +273,10 @@ main (int argc, char * const argv[]) break; case 'n': - mode |= AA_MODE_IS_DRY; + if (mode & AA_MODE_IS_DRY) + mode |= AA_MODE_IS_DRY_FULL; + else + mode |= AA_MODE_IS_DRY; break; case 'r': diff --git a/src/include/anopa/service.h b/src/include/anopa/service.h index f14a640..ffd34ff 100644 --- a/src/include/anopa/service.h +++ b/src/include/anopa/service.h @@ -56,7 +56,8 @@ typedef enum AA_MODE_START = (1 << 0), AA_MODE_STOP = (1 << 1), AA_MODE_STOP_ALL = (1 << 2), - AA_MODE_IS_DRY = (1 << 3) + AA_MODE_IS_DRY = (1 << 3), + AA_MODE_IS_DRY_FULL = (1 << 4) } aa_mode; typedef enum @@ -107,7 +108,7 @@ extern void aa_free_services (aa_close_fd_fn close_fd_fn); extern int aa_add_name (const char *name); extern int aa_get_service (const char *name, int *si, int new_in_main); extern void aa_unmark_service (int si); -extern int aa_mark_service (int si, int in_main, int no_wants, aa_load_fail_cb lf_cb); +extern int aa_mark_service (aa_mode mode, int si, int in_main, int no_wants, aa_load_fail_cb lf_cb); extern int aa_preload_service (int si); extern int aa_ensure_service_loaded (int si, aa_mode mode, int no_wants, aa_load_fail_cb lf_cb); extern int aa_prepare_mainlist (aa_prepare_cb prepare_cb, aa_exec_cb exec_cb); diff --git a/src/libanopa/service.c b/src/libanopa/service.c index d0f3a48..b12a30c 100644 --- a/src/libanopa/service.c +++ b/src/libanopa/service.c @@ -178,7 +178,12 @@ int aa_ensure_service_loaded (int si, aa_mode mode, int no_wants, aa_load_fail_cb lf_cb) { stralloc sa = STRALLOC_ZERO; - struct it_data it_data = { .si = si, .no_wants = no_wants, .lf_cb = lf_cb }; + struct it_data it_data = { + .mode = mode, + .si = si, + .no_wants = no_wants, + .lf_cb = lf_cb + }; int r; if (aa_service (si)->ls == AA_LOAD_DONE || aa_service (si)->ls == AA_LOAD_ING) @@ -215,23 +220,28 @@ aa_ensure_service_loaded (int si, aa_mode mode, int no_wants, aa_load_fail_cb lf || svst->event == AA_EVT_STOPPING_FAILED || svst->event == AA_EVT_STOP_FAILED); - if ((mode & AA_MODE_START) && is_up) - { - /* if already good, we "fail" because there's no need to load the - * service, it's already good. This error will be silently ignored - * */ - aa_service (si)->ls = AA_LOAD_FAIL; - /* this isn't actually true, but we won't save it to file */ - svst->code = ERR_ALREADY_UP; - return -ERR_ALREADY_UP; - } - else if ((mode & (AA_MODE_STOP | AA_MODE_STOP_ALL)) && !is_up) + /* DRY_FULL means process (i.e. list) even services that are already in + * the right state, so skip that bit then */ + if (!(mode & AA_MODE_IS_DRY_FULL)) { - /* if not up, we "fail" because we can't stop it */ - aa_service (si)->ls = AA_LOAD_FAIL; - /* this isn't actually true, but we won't save it to file */ - svst->code = ERR_NOT_UP; - return -ERR_NOT_UP; + if ((mode & AA_MODE_START) && is_up) + { + /* if already good, we "fail" because there's no need to load the + * service, it's already good. This error will be silently ignored + * */ + aa_service (si)->ls = AA_LOAD_FAIL; + /* this isn't actually true, but we won't save it to file */ + svst->code = ERR_ALREADY_UP; + return -ERR_ALREADY_UP; + } + else if ((mode & (AA_MODE_STOP | AA_MODE_STOP_ALL)) && !is_up) + { + /* if not up, we "fail" because we can't stop it */ + aa_service (si)->ls = AA_LOAD_FAIL; + /* this isn't actually true, but we won't save it to file */ + svst->code = ERR_NOT_UP; + return -ERR_NOT_UP; + } } } diff --git a/src/libanopa/service_internal.h b/src/libanopa/service_internal.h index 0244731..14bda36 100644 --- a/src/libanopa/service_internal.h +++ b/src/libanopa/service_internal.h @@ -31,6 +31,7 @@ extern aa_exec_cb _exec_cb; struct it_data { + aa_mode mode; int si; int no_wants; aa_load_fail_cb lf_cb; diff --git a/src/libanopa/service_start.c b/src/libanopa/service_start.c index 72bdf04..a207777 100644 --- a/src/libanopa/service_start.c +++ b/src/libanopa/service_start.c @@ -47,11 +47,11 @@ aa_unmark_service (int si) } int -aa_mark_service (int si, int in_main, int no_wants, aa_load_fail_cb lf_cb) +aa_mark_service (aa_mode mode, int si, int in_main, int no_wants, aa_load_fail_cb lf_cb) { int r; - r = aa_ensure_service_loaded (si, AA_MODE_START, no_wants, lf_cb); + r = aa_ensure_service_loaded (si, mode, no_wants, lf_cb); if (r < 0) { if (in_main) @@ -85,7 +85,7 @@ _it_start_needs (direntry *d, void *data) if (type < 0) r = type; else - r = aa_mark_service (sni, type == AA_SERVICE_FROM_MAIN, + r = aa_mark_service (it_data->mode, sni, type == AA_SERVICE_FROM_MAIN, it_data->no_wants, it_data->lf_cb); if (r == -ERR_ALREADY_UP) return 0; @@ -138,7 +138,7 @@ _it_start_wants (direntry *d, void *data) if (type < 0) r = type; else - r = aa_mark_service (swi, type == AA_SERVICE_FROM_MAIN, + r = aa_mark_service (it_data->mode, swi, type == AA_SERVICE_FROM_MAIN, it_data->no_wants, it_data->lf_cb); if (r == -ERR_ALREADY_UP) return 0;