Re: [PATCH v3 3/4] maintenance: use launchctl on macOS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/13/2020 3:19 PM, Eric Sunshine wrote:
> On Fri, Nov 13, 2020 at 9:00 AM Derrick Stolee via GitGitGadget
> <gitgitgadget@xxxxxxxxx> wrote:
>> [...]
>> The solution is to switch from cron to the Apple-recommended [1]
>> 'launchd' tool.
>> [...]
>> Signed-off-by: Derrick Stolee <dstolee@xxxxxxxxxxxxx>
>> ---
>> diff --git a/builtin/gc.c b/builtin/gc.c
>> @@ -1491,6 +1491,200 @@ static int maintenance_unregister(void)
>> +static int boot_plist(int enable, const char *filename)
>> +{
>> +       struct child_process child = CHILD_PROCESS_INIT;
>> +       child.no_stderr = 1;
>> +       child.no_stdout = 1;
>> +       if (start_command(&child))
>> +               die(_("failed to start launchctl"));
> 
> Not necessarily worth a re-roll -- in fact, it could be done atop this
> series to avoid holding this series up -- but this too-succinct error
> reporting won't help users diagnose the failure. An alternative would
> be to capture stdout and stderr and only print them if the command
> fails. Perhaps something like this:
> 
>     struct strbuf out = STRBUF_INIT;
>     struct strbuf err = STRBUF_INIT;
>     ...
>     if (pipe_command(child, NULL, 0, &out, 0, &err, 0) {
>         if (out.len && err.len)
>             strbuf_addstr(&out, "; ");
>         strbuf_addbuf(&out, &err);
>         die(_("launchctl failed: %s"), out.buf);
>     }

We would also want to pass a "die_on_failure" into the method, since
in the 'git maintenance start' case we don't want to report a failure
when 'launchctl bootout' fails before we call 'launchctl bootstrap'.

> By the way, won't this die() be a problem when schedule_plist() calls
> boot_plist() to remove the old scheduled tasks before calling it again
> to register the new ones? If the old ones don't exist, then it will
> die() unnecessarily and never register the new ones. Or am I
> misunderstanding? (I'm guessing that I must be misunderstanding since
> the test script presumably passes.)

This die() is only if the process cannot _start_, for example due to
launchctl not existing on $PATH. The result from finish_command()
would be non-zero when we bootout a plist that doesn't exist.

>> diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
>> @@ -389,12 +389,54 @@ test_expect_success 'stop from existing schedule' '
>> +test_expect_success MACOS_MAINTENANCE 'start and stop macOS maintenance' '
>> +       write_script print-args "#!/bin/sh\necho \$* >>args" &&
> 
> write_script() takes the script body as stdin, not as an argument, and
> you don't need to specify /bin/sh. What you have here works by
> accident only because write_script() takes an optional second argument
> specifying the shell to use in place of the default /bin/sh.
> Nevertheless, it should really be written:
> 
>     write_script print-args <<-\EOF
>     echo $*
>     EOF
> 
> Patch [4/4] uses write_script() correctly.

Ah. Sorry for misunderstanding. That explains why it works this way
on macOS but it did _not_ work that way on Windows.

>> +       rm -f args &&
>> +       GIT_TEST_CRONTAB="./print-args" git maintenance start &&
>> +
>> +       # start registers the repo
>> +       git config --get --global maintenance.repo "$(pwd)" &&
>> +
>> +       # ~/Library/LaunchAgents
>> +       ls "$HOME/Library/LaunchAgents" >actual &&
> 
> Not sure what the comment above the `ls` is meant to be conveying.
> Could be dropped but not itself worth a re-roll.
> 
>> +       cat >expect <<-\EOF &&
>> +       org.git-scm.git.daily.plist
>> +       org.git-scm.git.hourly.plist
>> +       org.git-scm.git.weekly.plist
>> +       EOF
>> +       test_cmp expect actual &&
>> +
>> +       rm expect &&
>> +       for frequency in hourly daily weekly
>> +       do
>> +               PLIST="$HOME/Library/LaunchAgents/org.git-scm.git.$frequency.plist" &&
>> +               xmllint --noout "$PLIST" &&
>> +               grep schedule=$frequency "$PLIST" &&
>> +               echo "bootout gui/$UID $PLIST" >>expect &&
>> +               echo "bootstrap gui/$UID $PLIST" >>expect || return 1
>> +       done &&
> 
> This is still relying upon $UID picked up from the users environment
> (as far as I can tell), which seems fragile. As mentioned in my first
> review, it probably would be more robust to compute UID manually the
> same way git-maintenance itself does.

Sorry, I missed this comment from v1 when reapplying the changes for v3.

>> +       test_cmp expect args &&
>> +
>> +       rm -f args &&
>> +       GIT_TEST_CRONTAB="./print-args" git maintenance stop &&
> 
> Minor: No need for the quotes around ./print-args (though they don't
> hurt either, and certainly not worth re-rolling just to drop them, and
> it's subjective so don't drop them just for my sake).

Thank you for your continued attention and patience.
-Stolee



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux