git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] gc: use temporary file for editing crontab

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Aug 23, 2022, 21:15 UTC
Message-ID
<YwVDcO/V+zx2iy4I@tapette.crustytoothpaste.net>
In-Reply-To
<9e737b4b-4a17-09d5-6452-4ca5eef3d9da@github.com>
On 2022-08-23 at 17:06:03, Derrick Stolee wrote:
Show 15 quoted lines
> On 8/23/2022 5:12 AM, Johannes Schindelin wrote:
> > Hi brian,
> > 
> > On Tue, 23 Aug 2022, brian m. carlson wrote:
> 
> >> +	tmpedit = mks_tempfile_t(".git_cron_edit_tmpXXXXXX");
> >> +	if (!tmpedit)
> >> +		return error(_("failed to create crontab temporary file"));
> > 
> > It might make sense to use the same `goto out;` pattern here, to make it
> > easier to reason about the early exit even six years from now.
> > 
> > We do not even have to guard the `close_tempfile_gently()` behind an `if
> > (tempfile)` conditional because that function handles `NULL` parameters
> > gently.

I can do that. I'll need to make sure we initialize the pointer to NULL first.

> This is focused only on the cron integration, which is not used on Windows,
> so I'm not worried about that.

Correct. The only place this could go wrong is Cygwin, but I believe it has the proper behaviour (and if not, lots of stuff will be broken).

> I was initially worried that we lost the fclose(cron_in), but of course it
> is handled by the close_tempfile_gently() at the end.

Yup. I originally called fclose here and glibc screamed at me about a double-free, so the fclose definitely should be removed. I'll mention this in the commit message as well.

Show 7 quoted lines
> Here's the crux of the matter: we are no longer using stdin but
> instead passing an argument to point to a file with our desired
> schedule. I tested that this worked on my machine, and I'm glad
> this use is the POSIX standard.
> 
> There is something wrong with this patch: it needs to update
> t/helper/test-crontab.c in order to pass t7900-maintenance.sh.
Will fix.
> While the memory release is nice, I also think it would be good to use
> delete_tempfile() so the temporary file is deleted within this method,
> not waiting until the end of the process to do that cleanup.
Sounds good.  I'll include that in a v2.
-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA
Previous: Derrick StoleeNext: Junio C Hamano
Message 13 of 19 in “git maintenance broken on FreeBSD”
  1. Renato BotelhoAug 12, 2022
  2. Đoàn Trần Công DanhAug 12, 2022
  3. Todd ZullingerAug 13, 2022
  4. Junio C HamanoAug 13, 2022
  5. Đoàn Trần Công DanhAug 13, 2022
  6. Junio C HamanoAug 13, 2022
  7. brian m. carlsonAug 13, 2022
  8. Derrick StoleeAug 15, 2022
  9. Junio C HamanoAug 15, 2022
  10. gc: use temporary file for editing crontabbrian m. carlson, Aug 23, 2022
  11. Johannes SchindelinAug 23, 2022
  12. Derrick StoleeAug 23, 2022
  13. brian m. carlsonAug 23, 2022
  14. Junio C HamanoAug 24, 2022
  15. gc: use temporary file for editing crontabbrian m. carlson, Aug 28, 2022
  16. Junio C HamanoAug 29, 2022
  17. Renato BotelhoAug 29, 2022
  18. Derrick StoleeAug 30, 2022
  19. test-crontab: minor memory and error handling fixesJeff King, Aug 30, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.