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

[PATCH v2 4/6] maintenance: cleanup $XDG_CONFIG_HOME/systemd/user

From
Max Gautier <mg@max.gautier.name>
Date
Mar 22, 2024, 22:11 UTC
Message-ID
<20240322221327.12204-5-mg@max.gautier.name>
In-Reply-To
<20240322221327.12204-1-mg@max.gautier.name>

Before commit 976640edbb (maintenance: use packaged systemd units, 2024-03-21), we we're putting systemd unit files in $XDG_CONFIG_HOME ; these could mask those we are now distributing as part of git.

Remove all the systemd units possibly created by previous version of git when running `git maintenance start/stop`. Avoid overwriting units we didn't write, by comparing the first line with the start of the comment we added to our unit files previously.

Signed-off-by: Max Gautier <mg@max.gautier.name>
---
Notes:
    How should I refer to a commit which is part of the same patch series ?
    The commit id will change so the message won't be correct anymore, right
    ?
 builtin/gc.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
diff --git a/builtin/gc.c b/builtin/gc.c
index aaee91451a..99b158e481 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -2329,8 +2329,50 @@ static int systemd_set_units_state(int enable)
 	return 0;
 }
 
+/*
+ * TODO: in the future (~2026 ?) remove this cleanup code
+ */
+static void systemd_delete_user_unit(char const *unit)
+{
+	char const	file_start_stale[] =	"# This file was created and is"
+						" maintained by Git.";
+	char		file_start_user[sizeof(file_start_stale)] = {'\0'};
+
+	char *filename = xdg_config_home_for("systemd/user", unit);
+	int handle = open(filename, O_RDONLY);
+
+	/*
+	 * Check this is actually our file and we're not removing a legitimate
+	 * user override.
+	 */
+	if (handle == -1 && !is_missing_file_error(errno))
+		warning(_("failed to delete '%s'"), filename);
+	else {
+		read(handle, file_start_user, sizeof(file_start_stale) - 1);
+		close(handle);
+		if (strcmp(file_start_stale, file_start_user) == 0) {
+			if (unlink(filename) == 0)
+				warning(_("deleted stale unit file '%s'"), filename);
+			else if (!is_missing_file_error(errno))
+				warning(_("failed to delete '%s'"), filename);
+		}
+	}
+
+	free(filename);
+}
+
 static int systemd_timer_update_schedule(int run_maintenance, int fd UNUSED)
 {
+	/*
+	 * A previous version of Git wrote the units in the user configuration
+	 * directory. Clean these up, if they exist.
+	 * TODO: in the future (~2026 ?) remove this cleanup code
+	 */
+	systemd_delete_user_unit("git-maintenance@hourly.timer");
+	systemd_delete_user_unit("git-maintenance@daily.timer");
+	systemd_delete_user_unit("git-maintenance@weekly.timer");
+	systemd_delete_user_unit("git-maintenance@.timer");
+	systemd_delete_user_unit("git-maintenance@.service");
 	return systemd_set_units_state(run_maintenance);
 }
 
-- 
2.44.0
Previous: Max GautierNext: Kristoffer Haugsbakk
Message 2 of 30 in “maintenance: use packaged systemd units”
  1. 0/6 maintenance: use packaged systemd unitsMax Gautier, Mar 22, 2024
  2. 4/6 maintenance: cleanup $XDG_CONFIG_HOME/systemd/userMax Gautier, Mar 22, 2024
  3. Kristoffer HaugsbakkMar 22, 2024
  4. Junio C HamanoMar 22, 2024
  5. Max GautierMar 23, 2024
  6. Phillip WoodMar 24, 2024
  7. Max GautierMar 25, 2024
  8. Phillip WoodMar 25, 2024
  9. Max GautierMar 27, 2024
  10. 2/6 maintenance: use packaged systemd unitsMax Gautier, Mar 22, 2024
  11. Eric SunshineMar 23, 2024
  12. Max GautierMar 23, 2024
  13. 3/6 maintenance: simplify systemctl callsMax Gautier, Mar 22, 2024
  14. Eric SunshineMar 22, 2024
  15. Max GautierMar 23, 2024
  16. 1/6 maintenance: use systemd timers builtin randomizationMax Gautier, Mar 22, 2024
  17. 5/6 maintenance: update systemd scheduler docsMax Gautier, Mar 22, 2024
  18. 6/6 maintenance: update tests for systemd schedulerMax Gautier, Mar 22, 2024
  19. Eric SunshineMar 22, 2024
  20. Max GautierMar 23, 2024
  21. Phillip WoodMar 24, 2024
  22. Eric SunshineMar 24, 2024
  23. phillip.wood123@gmail.comMar 25, 2024
  24. Max GautierMar 25, 2024
  25. phillip.wood123@gmail.comMar 25, 2024
  26. Max GautierMar 25, 2024
  27. Phillip WoodMar 25, 2024
  28. Max GautierMar 25, 2024
  29. Phillip WoodMar 25, 2024
  30. Max GautierMar 27, 2024

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.