@@ -2335,46 +2335,6 @@ static char *xdg_config_home_systemd(const char *filename)
23352335 return xdg_config_home_for ("systemd/user" , filename );
23362336}
23372337
2338- static int systemd_timer_enable_unit (int enable ,
2339- enum schedule_priority schedule )
2340- {
2341- const char * cmd = "systemctl" ;
2342- struct child_process child = CHILD_PROCESS_INIT ;
2343- const char * frequency = get_frequency (schedule );
2344-
2345- /*
2346- * Disabling the systemd unit while it is already disabled makes
2347- * systemctl print an error.
2348- * Let's ignore it since it means we already are in the expected state:
2349- * the unit is disabled.
2350- *
2351- * On the other hand, enabling a systemd unit which is already enabled
2352- * produces no error.
2353- */
2354- if (!enable )
2355- child .no_stderr = 1 ;
2356-
2357- get_schedule_cmd (& cmd , NULL );
2358- strvec_split (& child .args , cmd );
2359- strvec_pushl (& child .args , "--user" , enable ? "enable" : "disable" ,
2360- "--now" , NULL );
2361- strvec_pushf (& child .args , "git-maintenance@%s.timer" , frequency );
2362-
2363- if (start_command (& child ))
2364- return error (_ ("failed to start systemctl" ));
2365- if (finish_command (& child ))
2366- /*
2367- * Disabling an already disabled systemd unit makes
2368- * systemctl fail.
2369- * Let's ignore this failure.
2370- *
2371- * Enabling an enabled systemd unit doesn't fail.
2372- */
2373- if (enable )
2374- return error (_ ("failed to run systemctl" ));
2375- return 0 ;
2376- }
2377-
23782338static int systemd_timer_delete_unit_templates (void )
23792339{
23802340 int ret = 0 ;
@@ -2391,14 +2351,6 @@ static int systemd_timer_delete_unit_templates(void)
23912351 return ret ;
23922352}
23932353
2394- static int systemd_timer_delete_units (void )
2395- {
2396- return systemd_timer_enable_unit (0 , SCHEDULE_HOURLY ) ||
2397- systemd_timer_enable_unit (0 , SCHEDULE_DAILY ) ||
2398- systemd_timer_enable_unit (0 , SCHEDULE_WEEKLY ) ||
2399- systemd_timer_delete_unit_templates ();
2400- }
2401-
24022354static int systemd_timer_write_unit_templates (const char * exec_path )
24032355{
24042356 char * filename ;
@@ -2480,6 +2432,54 @@ static int systemd_timer_write_unit_templates(const char *exec_path)
24802432 return -1 ;
24812433}
24822434
2435+ static int systemd_timer_enable_unit (int enable ,
2436+ enum schedule_priority schedule )
2437+ {
2438+ const char * cmd = "systemctl" ;
2439+ struct child_process child = CHILD_PROCESS_INIT ;
2440+ const char * frequency = get_frequency (schedule );
2441+
2442+ /*
2443+ * Disabling the systemd unit while it is already disabled makes
2444+ * systemctl print an error.
2445+ * Let's ignore it since it means we already are in the expected state:
2446+ * the unit is disabled.
2447+ *
2448+ * On the other hand, enabling a systemd unit which is already enabled
2449+ * produces no error.
2450+ */
2451+ if (!enable )
2452+ child .no_stderr = 1 ;
2453+
2454+ get_schedule_cmd (& cmd , NULL );
2455+ strvec_split (& child .args , cmd );
2456+ strvec_pushl (& child .args , "--user" , enable ? "enable" : "disable" ,
2457+ "--now" , NULL );
2458+ strvec_pushf (& child .args , "git-maintenance@%s.timer" , frequency );
2459+
2460+ if (start_command (& child ))
2461+ return error (_ ("failed to start systemctl" ));
2462+ if (finish_command (& child ))
2463+ /*
2464+ * Disabling an already disabled systemd unit makes
2465+ * systemctl fail.
2466+ * Let's ignore this failure.
2467+ *
2468+ * Enabling an enabled systemd unit doesn't fail.
2469+ */
2470+ if (enable )
2471+ return error (_ ("failed to run systemctl" ));
2472+ return 0 ;
2473+ }
2474+
2475+ static int systemd_timer_delete_units (void )
2476+ {
2477+ return systemd_timer_enable_unit (0 , SCHEDULE_HOURLY ) ||
2478+ systemd_timer_enable_unit (0 , SCHEDULE_DAILY ) ||
2479+ systemd_timer_enable_unit (0 , SCHEDULE_WEEKLY ) ||
2480+ systemd_timer_delete_unit_templates ();
2481+ }
2482+
24832483static int systemd_timer_setup_units (void )
24842484{
24852485 const char * exec_path = git_exec_path ();
0 commit comments