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

Function systemd_timer_enable_unit

builtin/gc.c:3132–3187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3130}
3131
3132static int systemd_timer_enable_unit(int enable,
3133 enum schedule_priority schedule,
3134 int minute)
3135{
3136 char *cmd = NULL;
3137 struct child_process child = CHILD_PROCESS_INIT;
3138 const char *frequency = get_frequency(schedule);
3139 int ret;
3140
3141 /*
3142 * Disabling the systemd unit while it is already disabled makes
3143 * systemctl print an error.
3144 * Let's ignore it since it means we already are in the expected state:
3145 * the unit is disabled.
3146 *
3147 * On the other hand, enabling a systemd unit which is already enabled
3148 * produces no error.
3149 */
3150 if (!enable) {
3151 child.no_stderr = 1;
3152 } else if (systemd_timer_write_timer_file(schedule, minute)) {
3153 ret = -1;
3154 goto out;
3155 }
3156
3157 get_schedule_cmd("systemctl", NULL, &cmd);
3158 strvec_split(&child.args, cmd);
3159 strvec_pushl(&child.args, "--user", enable ? "enable" : "disable",
3160 "--now", NULL);
3161 strvec_pushf(&child.args, SYSTEMD_UNIT_FORMAT, frequency, "timer");
3162
3163 if (start_command(&child)) {
3164 ret = error(_("failed to start systemctl"));
3165 goto out;
3166 }
3167
3168 if (finish_command(&child)) {
3169 /*
3170 * Disabling an already disabled systemd unit makes
3171 * systemctl fail.
3172 * Let's ignore this failure.
3173 *
3174 * Enabling an enabled systemd unit doesn't fail.
3175 */
3176 if (enable) {
3177 ret = error(_("failed to run systemctl"));
3178 goto out;
3179 }
3180 }
3181
3182 ret = 0;
3183
3184out:
3185 free(cmd);
3186 return ret;
3187}
3188
3189/*

Callers 2

Calls 9

get_frequencyFunction · 0.85
get_schedule_cmdFunction · 0.85
strvec_splitFunction · 0.85
strvec_pushlFunction · 0.85
strvec_pushfFunction · 0.85
start_commandFunction · 0.85
errorFunction · 0.85
finish_commandFunction · 0.85

Tested by

no test coverage detected