MCPcopy Create free account
hub / github.com/git/git / systemd_timer_write_service_template

Function systemd_timer_write_service_template

builtin/gc.c:3078–3130  ·  view source on GitHub ↗

* No matter the schedule, we use the same service and can make use of the * templating system. When installing git-maintenance@ .timer, * systemd will notice that git-maintenance@.service exists as a template * and will use this file and insert the into the template at * the position of "%i". */

Source from the content-addressed store, hash-verified

3076 * the position of "%i".
3077 */
3078static int systemd_timer_write_service_template(const char *exec_path)
3079{
3080 int res = -1;
3081 char *filename;
3082 FILE *file;
3083 const char *unit;
3084 char *local_service_name = xstrfmt(SYSTEMD_UNIT_FORMAT, "", "service");
3085
3086 filename = xdg_config_home_systemd(local_service_name);
3087 if (safe_create_leading_directories(the_repository, filename)) {
3088 error(_("failed to create directories for '%s'"), filename);
3089 goto error;
3090 }
3091 file = fopen_or_warn(filename, "w");
3092 if (!file)
3093 goto error;
3094
3095 unit = "# This file was created and is maintained by Git.\n"
3096 "# Any edits made in this file might be replaced in the future\n"
3097 "# by a Git command.\n"
3098 "\n"
3099 "[Unit]\n"
3100 "Description=Optimize Git repositories data\n"
3101 "\n"
3102 "[Service]\n"
3103 "Type=oneshot\n"
3104 "ExecStart=\"%s/git\" --exec-path=\"%s\" %s for-each-repo --keep-going --config=maintenance.repo maintenance run --schedule=%%i\n"
3105 "LockPersonality=yes\n"
3106 "MemoryDenyWriteExecute=yes\n"
3107 "NoNewPrivileges=yes\n"
3108 "RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_VSOCK\n"
3109 "RestrictNamespaces=yes\n"
3110 "RestrictRealtime=yes\n"
3111 "RestrictSUIDSGID=yes\n"
3112 "SystemCallArchitectures=native\n"
3113 "SystemCallFilter=@system-service\n";
3114 if (fprintf(file, unit, exec_path, exec_path, get_extra_config_parameters()) < 0) {
3115 error(_("failed to write to '%s'"), filename);
3116 fclose(file);
3117 goto error;
3118 }
3119 if (fclose(file) == EOF) {
3120 error_errno(_("failed to flush '%s'"), filename);
3121 goto error;
3122 }
3123
3124 res = 0;
3125
3126error:
3127 free(local_service_name);
3128 free(filename);
3129 return res;
3130}
3131
3132static int systemd_timer_enable_unit(int enable,
3133 enum schedule_priority schedule,

Callers 1

Calls 7

xstrfmtFunction · 0.85
xdg_config_home_systemdFunction · 0.85
errorFunction · 0.85
fopen_or_warnFunction · 0.85
error_errnoFunction · 0.85

Tested by

no test coverage detected