author | Olivier Brunel
<jjk@jjacky.com> 2018-01-24 22:06:06 UTC |
committer | Olivier Brunel
<jjk@jjacky.com> 2018-01-25 10:23:58 UTC |
parent | 300793149246b2498b22132ca69671e8eb678670 |
doc/aa-enable.pod | +15 | -14 |
doc/anopa-rc.pod | +1 | -1 |
src/anopa/aa-enable.c | +43 | -36 |
src/anopa/common.h | +1 | -1 |
diff --git a/doc/aa-enable.pod b/doc/aa-enable.pod index 587d0b5..52bdad4 100644 --- a/doc/aa-enable.pod +++ b/doc/aa-enable.pod @@ -25,8 +25,8 @@ C<s6-svscan -a REPODIR/.scandir> afterwards. =item B<-c, --set-crash> I<CRASH> -Create a symlink I<REPODIR/.scandir/.s6-svscan/crash> that points to I<CRASH>. -This is what B<s6-svscan> will exec into if it crashes. +Copy I<CRASH> as I<REPODIR/.scandir/.s6-svscan/crash>. This is what +B<s6-svscan> will exec into if it crashes. =item B<-D, --double-output> @@ -40,9 +40,10 @@ removed in the next version; You should use B<--log-file> instead. =item B<-f, --set-finish> I<FINISH> -Create a symlink I<REPODIR/.scandir/.s6-svscan/finish> that points to I<FINISH>. -This is what B<s6-svscan> will exec into when it's done. This would usually -point to B<aa-stage3>(1). +Copy I<FINISH> as I<REPODIR/.scandir/.s6-svscan/finish>. This is what +B<s6-svscan> will exec into when it's done. + +This would usually point to B<aa-stage3>(1). =item B<-h, --help> @@ -50,9 +51,9 @@ Show help screen and exit. =item B<-i, --set-init> I<INIT> -Create a symlink I<REPODIR/.anopa/init> that points to I<INIT>. When using -B<aa-stage1>(1) this is what will be executed to actually start all the services -and bring the system to readiness. +Copy I<INIT> as I<REPODIR/.anopa/init>. When using B<aa-stage1>(1) this is what +will be executed to actually start all the services and bring the system to +readiness. This would usually point to B<aa-stage2>(1). @@ -89,15 +90,15 @@ 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. +Copy I<POSTSTOP> as I<REPODIR/.anopa/post-stop>. 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. +Copy I<POSTSTART> as I<REPODIR/.anopa/post-start>. 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). diff --git a/doc/anopa-rc.pod b/doc/anopa-rc.pod index f92e508..37dbfa7 100644 --- a/doc/anopa-rc.pod +++ b/doc/anopa-rc.pod @@ -56,7 +56,7 @@ of the following flags : +------+------+-------------------------------------------+----------------+ | 16 | 8 | At least one failed service was essential | aa-start only | +------+------+-------------------------------------------+----------------+ - | 32 | 16 | At least one symlink couldn't be created | aa-enable only | + | 32 | 16 | At least one file copy failed (--set-*) | aa-enable only | +------+------+-------------------------------------------+----------------+ | 64 | 32 | Failed to alarm s6-svscan | aa-enable only | +------+------+-------------------------------------------+----------------+ diff --git a/src/anopa/aa-enable.c b/src/anopa/aa-enable.c index 3666c5c..3d73e3b 100644 --- a/src/anopa/aa-enable.c +++ b/src/anopa/aa-enable.c @@ -46,6 +46,7 @@ #include <anopa/scan_dir.h> #include <anopa/enable_service.h> #include <anopa/ga_list.h> +#include <anopa/copy_file.h> #include <anopa/stats.h> #include <anopa/err.h> #include "util.h" @@ -56,10 +57,10 @@ #define SCANDIR_CRASH SVSCANDIR "/crash" #define SCANDIR_FINISH SVSCANDIR "/finish" -#define SYMLINKDIR ".anopa" -#define POST_START SYMLINKDIR "/post-start" -#define POST_STOP SYMLINKDIR "/post-stop" -#define INIT SYMLINKDIR "/init" +#define ANOPADIR ".anopa" +#define POST_START ANOPADIR "/post-start" +#define POST_STOP ANOPADIR "/post-stop" +#define INIT ANOPADIR "/init" #define SOURCE_ETC "/etc/anopa/services" #define SOURCE_USR "/usr/lib/services" @@ -200,6 +201,27 @@ it_list (direntry *d, void *data) return 0; } +static int +copy_file (const char *src, const char *dst) +{ + if (aa_copy_file (src, dst, 0744, AA_CP_OVERWRITE) < 0) + { + int e = errno; + + aa_put_err ("Failed to copy ", NULL, 0); + aa_bs (AA_ERR, src); + aa_bs (AA_ERR, " as "); + aa_bs (AA_ERR, dst); + aa_bs (AA_ERR, ": "); + aa_bs (AA_ERR, strerror (e)); + aa_end_err (); + + return 0; + } + + return 1; +} + static void dieusage (int rc) { @@ -212,11 +234,11 @@ 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" - " -i, --set-init TARGET Create symlink REPODIR/.anopa/init 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" + " -i, --set-init INIT Copy INIT as REPODIR/" INIT "\n" + " -p, --set-post-start POST Copy POST as REPODIR/" POST_START "\n" + " -P, --set-post-stop POST Copy POST as REPODIR/" POST_STOP "\n" + " -f, --set-finish FINISH Copy FINISH as REPODIR/" SCANDIR_FINISH "\n" + " -c, --set-crash CRASH Copy CRASH as REPODIR/" SCANDIR_CRASH "\n" " -a, --alarm-s6 Alarm s6-svscan when done\n" " -N, --no-needs Don't auto-enable services from 'needs'\n" " -W, --no-wants Don't auto-enable services from 'wants'\n" @@ -459,36 +481,21 @@ main (int argc, char * const argv[]) if (!(flags & AA_FLAG_UPGRADE_SERVICEDIR)) { if ((set_init || 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_init && symlink (set_init, INIT) < 0) - { - aa_put_err ("Failed to create symlink " INIT, strerror (errno), 1); - rc |= RC_ST_SYMLINK; - } - if (set_post_start && symlink (set_post_start, POST_START) < 0) - { - 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; - } + && mkdir (ANOPADIR, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) + aa_put_err ("Failed to create " ANOPADIR, strerror (errno), 1); + if (set_init && !copy_file (set_init, INIT)) + rc |= RC_ST_COPY_FILE; + if (set_post_start && !copy_file (set_post_start, POST_START)) + rc |= RC_ST_COPY_FILE; + if (set_post_stop && !copy_file (set_post_stop, POST_STOP)) + rc |= RC_ST_COPY_FILE; if ((set_crash || set_finish) && mkdir (SVSCANDIR, S_IRWXU) < 0) aa_put_err ("Failed to create " SVSCANDIR, strerror (errno), 1); - if (set_crash && symlink (set_crash, SCANDIR_CRASH) < 0) - { - aa_put_err ("Failed to create symlink " SCANDIR_CRASH, strerror (errno), 1); - rc |= RC_ST_SYMLINK; - } - if (set_finish && symlink (set_finish, SCANDIR_FINISH) < 0) - { - aa_put_err ("Failed to create symlink " SCANDIR_FINISH, strerror (errno), 1); - rc |= RC_ST_SYMLINK; - } + if (set_crash && !copy_file (set_crash, SCANDIR_CRASH)) + rc |= RC_ST_COPY_FILE; + if (set_finish && !copy_file (set_finish, SCANDIR_FINISH)) + rc |= RC_ST_COPY_FILE; } if (alarm_s6) diff --git a/src/anopa/common.h b/src/anopa/common.h index 1847f38..2881539 100644 --- a/src/anopa/common.h +++ b/src/anopa/common.h @@ -34,7 +34,7 @@ enum RC_ST_FAILED = 1 << 3, /* at least 1 service failed */ RC_ST_ESSENTIAL = 1 << 4, /* at least 1 failed service was essential (start) */ /* enable only: */ - RC_ST_SYMLINK = 1 << 5, /* at least 1 symlink couldn't be created */ + RC_ST_COPY_FILE = 1 << 5, /* at least 1 file copy failed */ RC_ST_ALARM_S6 = 1 << 6 /* failed to alarm s6 */ };