author | Olivier Brunel
<jjk@jjacky.com> 2018-01-24 21:41:05 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2018-01-25 10:08:07 UTC |
parent | 48a291dbf12ffe10d1544a4f1f7fb37743129a64 |
doc/aa-enable.pod | +18 | -33 |
doc/aa-stage0.pod | +1 | -1 |
doc/aa-stage2.pod | +1 | -1 |
doc/aa-stage3.pod | +1 | -1 |
doc/aa-stage4.pod | +1 | -1 |
src/anopa/aa-enable.c | +28 | -43 |
src/scripts/aa-stage0 | +2 | -2 |
src/scripts/aa-stage2 | +2 | -2 |
src/scripts/aa-stage3 | +2 | -2 |
src/scripts/aa-stage4 | +2 | -2 |
diff --git a/doc/aa-enable.pod b/doc/aa-enable.pod index 5433cf3..651bb86 100644 --- a/doc/aa-enable.pod +++ b/doc/aa-enable.pod @@ -4,44 +4,15 @@ aa-enable - Enable services, i.e. copy servicedirs to repodir =head1 SYNOPSIS -B<aa-enable> [B<-D>] [B<-O> I<FILE|FD>] [B<-r> I<REPODIR>] [B<-0> I<POSTSTAGE0>] -[B<-2> I<POSTSTAGE2>] [B<-3> I<POSTSTAGE3>] [B<-4> I<POSTSTAGE4>] [B<-c> -I<CRASH>] [B<-f> I<FINISH>] [B<-k> I<SERVICE>] [B<-S> I<SOURCEDIR>] [B<-s> -I<SOURCEDIR>] [B<-l> I<LISTDIR>] [B<-N>] [B<-W>] [B<-u>] [B<-a>] -[B<--no-supervise>] [B<-q>] [I<SERVICE...>] +B<aa-enable> [B<-D>] [B<-O> I<FILE|FD>] [B<-r> I<REPODIR>] [B<-p> I<POSTSTART>] +[B<-P> I<POSTSTOP>] [B<-c> I<CRASH>] [B<-f> I<FINISH>] [B<-k> I<SERVICE>] [B<-S> +I<SOURCEDIR>] [B<-s> I<SOURCEDIR>] [B<-l> I<LISTDIR>] [B<-N>] [B<-W>] [B<-u>] +[B<-a>] [B<--no-supervise>] [B<-q>] [I<SERVICE...>] =head1 OPTIONS =over -=item B<-0, --set-post-stage0> I<POSTSTAGE0> - -Create a symlink I<REPODIR/.anopa/post-stage0> that points to I<POSTSTAGE0>. -This is executed by B<aa-stage0> after B<aa-start>(1) completed, with its return -code as first argument. - -This could point to B<aa-post-stage0>(1). - -=item B<-2, --set-post-stage2> I<POSTSTAGE2> - -Create a symlink I<REPODIR/.anopa/post-stage2> that points to I<POSTSTAGE2>. -This is executed by B<aa-stage2> after B<aa-start>(1) completed, with its return -code as first argument. - -This could point to B<aa-post-stage2>(1). - -=item B<-3, --set-post-stage3> I<POSTSTAGE3> - -Create a symlink I<REPODIR/.anopa/post-stage3> that points to I<POSTSTAGE3>. -This is executed by B<aa-stage3> after B<aa-stop>(1) completed, with its return -code as first argument. - -=item B<-4, --set-post-stage4> I<POSTSTAGE4> - -Create a symlink I<REPODIR/.anopa/post-stage4> that points to I<POSTSTAGE4>. -This is executed by B<aa-stage4> after B<aa-stop>(1) completed, with its return -code as first argument. - =item B<-a, --alarm-s6> Alarms B<s6-svscan> as last step; This obviously assumes there is a running @@ -108,6 +79,20 @@ file or file descriptor. I<FILE|FD> can either be a (previously opened for writing) file descriptor (must be > 2), or a file which will then be opened in append mode. +=item B<-P, --set-post-stop> I<POSTSTOP> + +Create a symlink I<REPODIR/.anopa/post-stop> that points to I<POSTSTOP>. +When using B<aa-stage3>(1) and/or B<aa-stage4>(1) this is executed after +B<aa-stop>(1) completed, with its return code as first argument. + +=item B<-p, --set-post-start> I<POSTSTART> + +Create a symlink I<REPODIR/.anopa/post-start> that points to I<POSTSTART>. +When using B<aa-stage0>(1) and/or B<aa-stage2>(1) this is executed after +B<aa-start>(1) completed, with its return code as first argument. + +This could point to B<aa-post-stage0>(1) or B<aa-post-stage2>(1). + =item B<-q, --quiet> Don't print enabled service names. diff --git a/doc/aa-stage0.pod b/doc/aa-stage0.pod index 4d4130e..db15b11 100644 --- a/doc/aa-stage0.pod +++ b/doc/aa-stage0.pod @@ -31,7 +31,7 @@ I</root-fs/sys> and I</root-fs/run> It is also up to them to load required kernel modules in order to do so. After B<aa-start>(1) has run, and if it exists, B<aa-stage0>(1) will execute -I</services/.anopa/post-stage0> with B<aa-start>(1)'s return code as +I</services/.anopa/post-start> with B<aa-start>(1)'s return code as argument. This allows to e.g. open a shell if something went terribly wrong. Note that file descriptor 3 will remain open for writing and connected to the diff --git a/doc/aa-stage2.pod b/doc/aa-stage2.pod index afb4044..6113c75 100644 --- a/doc/aa-stage2.pod +++ b/doc/aa-stage2.pod @@ -20,7 +20,7 @@ listdir, unless argument B<aa> was specified on kernel command line, in which case I</etc/anopa/listdirs/ARGVALUE> is used as listdir intead. After B<aa-start>(1) has run, and if it exists, B<aa-stage2>(1) will execute -I</run/services/.anopa/post-stage2> with B<aa-start>(1)'s return code as +I</run/services/.anopa/post-start> with B<aa-start>(1)'s return code as argument. This allows to e.g. open a shell if something went terribly wrong. Note that file descriptor 3 will remain open for writing and connected to the diff --git a/doc/aa-stage3.pod b/doc/aa-stage3.pod index 1bdfca4..5d72669 100644 --- a/doc/aa-stage3.pod +++ b/doc/aa-stage3.pod @@ -20,7 +20,7 @@ B<s6-supervise> process of that service will be sent command 'x' so it simply exits when the supervised process will. After B<aa-stop>(1) has run, and if it exists, B<aa-stage3>(1) will execute -I</run/services/.anopa/post-stage3> with B<aa-stop>(1)'s return code as +I</run/services/.anopa/post-stop> with B<aa-stop>(1)'s return code as argument. This allows to e.g. open a shell if something went terribly wrong. Note that file descriptor 3 will remain open for writing and connected to the diff --git a/doc/aa-stage4.pod b/doc/aa-stage4.pod index ab0bf56..fd28fe0 100644 --- a/doc/aa-stage4.pod +++ b/doc/aa-stage4.pod @@ -22,7 +22,7 @@ all API file systems in there: I</root-fs/dev>, I</root-fs/proc>, I</root-fs/sys> and I</root-fs/run> After B<aa-stop>(1) has run, and if it exists, B<aa-stage4>(1) will execute -I</services/.anopa/post-stage4> with B<aa-stop>(1)'s return code as +I</services/.anopa/post-stop> with B<aa-stop>(1)'s return code as argument. This allows to e.g. open a shell if something went terribly wrong. Note that obviously by this point there's no more logger, and unlike at other diff --git a/src/anopa/aa-enable.c b/src/anopa/aa-enable.c index c54c4a3..0ed1b31 100644 --- a/src/anopa/aa-enable.c +++ b/src/anopa/aa-enable.c @@ -57,7 +57,8 @@ #define SCANDIR_FINISH SVSCANDIR "/finish" #define SYMLINKDIR ".anopa" -#define POST_STAGE SYMLINKDIR "/post-stage" +#define POST_START SYMLINKDIR "/post-start" +#define POST_STOP SYMLINKDIR "/post-stop" #define SOURCE_ETC "/etc/anopa/services" #define SOURCE_USR "/usr/lib/services" @@ -210,10 +211,8 @@ dieusage (int rc) " -k, --skip-down SERVICE Don't create file 'down' for SERVICE\n" " -u, --upgrade Upgrade service dirs instead of creating them\n" " -l, --listdir DIR Use DIR to list services to enable\n" - " -0, --set-post-stage0 TARGET Create anopa symlink post-stage0 to TARGET\n" - " -2, --set-post-stage2 TARGET Create anopa symlink post-stage2 to TARGET\n" - " -3, --set-post-stage3 TARGET Create anopa symlink post-stage3 to TARGET\n" - " -4, --set-post-stage4 TARGET Create anopa symlink post-stage4 to TARGET\n" + " -p, --set-post-start TARGET Create symlink REPODIR/.anopa/post-start to TARGET\n" + " -P, --set-post-stop TARGET Create symlink REPODIR/.anopa/post-stop to TARGET\n" " -f, --set-finish TARGET Create s6-svscan symlink finish to TARGET\n" " -c, --set-crash TARGET Create s6-svscan symlink crash to TARGET\n" " -a, --alarm-s6 Alarm s6-svscan when done\n" @@ -234,7 +233,8 @@ main (int argc, char * const argv[]) const char *path_list = NULL; const char *set_crash = NULL; const char *set_finish = NULL; - const char *set_post_stage[] = { NULL, NULL, NULL, NULL }; + const char *set_post_start = NULL; + const char *set_post_stop = NULL; int i; int r; int rc = RC_OK; @@ -248,10 +248,6 @@ main (int argc, char * const argv[]) { int extra = 0; struct option longopts[] = { - { "set-post-stage0", required_argument, NULL, '0' }, - { "set-post-stage2", required_argument, NULL, '2' }, - { "set-post-stage3", required_argument, NULL, '3' }, - { "set-post-stage4", required_argument, NULL, '4' }, { "alarm-s6", no_argument, NULL, 'a' }, { "set-crash", required_argument, NULL, 'c' }, { "double-output", no_argument, NULL, 'D' }, @@ -261,6 +257,8 @@ main (int argc, char * const argv[]) { "listdir", required_argument, NULL, 'l' }, { "no-needs", no_argument, NULL, 'N' }, { "log-file", required_argument, NULL, 'O' }, + { "set-post-stop", required_argument, NULL, 'P' }, + { "set-post-start", required_argument, NULL, 'p' }, { "quiet", no_argument, NULL, 'q' }, { "repodir", required_argument, NULL, 'r' }, { "reset-source", required_argument, NULL, 'S' }, @@ -273,21 +271,11 @@ main (int argc, char * const argv[]) }; int c; - c = getopt_long (argc, argv, "0:2:3:4:ac:Df:hk:l:NO:qr:S:s:uVW", longopts, NULL); + c = getopt_long (argc, argv, "ac:Df:hk:l:NO:P:p:qr:S:s:uVW", longopts, NULL); if (c == -1) break; switch (c) { - case '2': - case '3': - case '4': - --c; - /* fall through */ - case '0': - c -= '0'; - set_post_stage[c] = optarg; - break; - case 'a': alarm_s6 = 1; break; @@ -324,6 +312,14 @@ main (int argc, char * const argv[]) aa_set_log_file_or_die (optarg); break; + case 'P': + set_post_stop = optarg; + break; + + case 'p': + set_post_start = optarg; + break; + case 'q': quiet = 1; break; @@ -454,29 +450,18 @@ main (int argc, char * const argv[]) if (!(flags & AA_FLAG_UPGRADE_SERVICEDIR)) { - int mk = 0; - const char *ps[] = { POST_STAGE "0", POST_STAGE "2", POST_STAGE "3", POST_STAGE "4" }; - - for (i = 0; i < 4; ++i) + if ((set_post_start || set_post_stop) + && mkdir (SYMLINKDIR, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) + aa_put_err ("Failed to create " SYMLINKDIR, strerror (errno), 1); + if (set_post_start && symlink (set_post_start, POST_START) < 0) { - if (!mk && set_post_stage[i]) - { - if (mkdir (SYMLINKDIR, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) - aa_put_err ("Failed to create " SYMLINKDIR, strerror (errno), 1); - else - mk = 1; - } - if (set_post_stage[i] && symlink (set_post_stage[i], ps[i]) < 0) - { - int e = errno; - - aa_put_err ("Failed to create symlink ", NULL, 0); - aa_bs (AA_ERR, ps[i]); - aa_bs (AA_ERR, ": "); - aa_bs (AA_ERR, strerror (e)); - aa_end_err (); - rc |= RC_ST_SYMLINK; - } + aa_put_err ("Failed to create symlink " POST_START, strerror (errno), 1); + rc |= RC_ST_SYMLINK; + } + if (set_post_stop && symlink (set_post_stop, POST_STOP) < 0) + { + aa_put_err ("Failed to create symlink " POST_STOP, strerror (errno), 1); + rc |= RC_ST_SYMLINK; } if ((set_crash || set_finish) && mkdir (SVSCANDIR, S_IRWXU) < 0) diff --git a/src/scripts/aa-stage0 b/src/scripts/aa-stage0 index d2046ca..b7bf54f 100755 --- a/src/scripts/aa-stage0 +++ b/src/scripts/aa-stage0 @@ -47,8 +47,8 @@ foreground { foreground { emptyenv -c s6-setsid aa-ctty -O3 -s aa-start -O3 -r /services -l onboot } - if { aa-test -e /services/.anopa/post-stage0 } - importas -u RC ? emptyenv -c /services/.anopa/post-stage0 $RC + if { aa-test -e /services/.anopa/post-start } + importas -u RC ? emptyenv -c /services/.anopa/post-start $RC } # if "break" was specified on kernel cmdline, let's open a shell diff --git a/src/scripts/aa-stage2 b/src/scripts/aa-stage2 index fe66e18..c9a3c1e 100755 --- a/src/scripts/aa-stage2 +++ b/src/scripts/aa-stage2 @@ -50,5 +50,5 @@ importas -u LISTDIR LISTDIR foreground { emptyenv -c s6-setsid aa-ctty -O3 aa-start -O3 -l /etc/anopa/listdirs/${LISTDIR} } -if { aa-test -e /run/services/.anopa/post-stage2 } -importas -u RC ? emptyenv -c /run/services/.anopa/post-stage2 $RC +if { aa-test -e /run/services/.anopa/post-start } +importas -u RC ? emptyenv -c /run/services/.anopa/post-start $RC diff --git a/src/scripts/aa-stage3 b/src/scripts/aa-stage3 index fdf91d1..7911deb 100755 --- a/src/scripts/aa-stage3 +++ b/src/scripts/aa-stage3 @@ -51,8 +51,8 @@ foreground { foreground { emptyenv -c s6-setsid aa-ctty -O3 -s aa-stop -O3 -aak uncaught-logs -t20 } - if { aa-test -e /run/services/.anopa/post-stage3 } - importas -u RC ? emptyenv -c /run/services/.anopa/post-stage3 $RC + if { aa-test -e /run/services/.anopa/post-stop } + importas -u RC ? emptyenv -c /run/services/.anopa/post-stop $RC } # Now stop the catch-all logger (its supervisor will then exit) foreground { emptyenv -c s6-setsid aa-stop -O3 uncaught-logs } diff --git a/src/scripts/aa-stage4 b/src/scripts/aa-stage4 index 8e09547..a201e8d 100755 --- a/src/scripts/aa-stage4 +++ b/src/scripts/aa-stage4 @@ -26,8 +26,8 @@ foreground { aa-echo -B "Stage 4: Unmounting root file system..." } foreground { foreground { emptyenv -c aa-stop -r /services -a } - if { aa-test -e /services/.anopa/post-stage4 } - importas -u RC ? emptyenv -c /services/.anopa/post-stage4 $RC + if { aa-test -e /services/.anopa/post-stop } + importas -u RC ? emptyenv -c /services/.anopa/post-stop $RC } # At this point everything should be unmounted, so we need to remount what's