@@ -161,7 +161,11 @@ static int bus_job_get_service_result(BusWaitForJobs *d, char **ret) {
161161 ret );
162162}
163163
164- static void log_job_error_with_service_result (const char * service , const char * result , const char * const * extra_args ) {
164+ static void log_job_error_with_service_result (
165+ const char * service ,
166+ const char * result ,
167+ bool quiet ,
168+ const char * const * extra_args ) {
165169
166170 static const struct {
167171 const char * result , * explanation ;
@@ -195,24 +199,27 @@ static void log_job_error_with_service_result(const char* service, const char *r
195199 if (!isempty (result ))
196200 FOREACH_ELEMENT (i , explanations )
197201 if (streq (result , i -> result )) {
198- log_error ("Job for %s failed because %s.\n"
199- "See \"%s status %s\" and \"%s -xeu %s\" for details.\n" ,
200- service , i -> explanation ,
201- systemctl , service_shell_quoted ?: "<service>" ,
202- journalctl , service_shell_quoted ?: "<service>" );
202+ log_full (quiet ? LOG_DEBUG : LOG_ERR ,
203+ "Job for %s failed because %s.\n"
204+ "See \"%s status %s\" and \"%s -xeu %s\" for details.\n" ,
205+ service , i -> explanation ,
206+ systemctl , service_shell_quoted ?: "<service>" ,
207+ journalctl , service_shell_quoted ?: "<service>" );
203208 goto extra ;
204209 }
205210
206- log_error ("Job for %s failed.\n"
207- "See \"%s status %s\" and \"%s -xeu %s\" for details.\n" ,
208- service ,
209- systemctl , service_shell_quoted ?: "<service>" ,
210- journalctl , service_shell_quoted ?: "<service>" );
211+ log_full (quiet ? LOG_DEBUG : LOG_ERR ,
212+ "Job for %s failed.\n"
213+ "See \"%s status %s\" and \"%s -xeu %s\" for details.\n" ,
214+ service ,
215+ systemctl , service_shell_quoted ?: "<service>" ,
216+ journalctl , service_shell_quoted ?: "<service>" );
211217
212218extra :
213219 /* For some results maybe additional explanation is required */
214220 if (streq_ptr (result , "start-limit-hit" ))
215- log_info ("To force a start use \"%1$s reset-failed %2$s\"\n"
221+ log_full (quiet ? LOG_DEBUG : LOG_INFO ,
222+ "To force a start use \"%1$s reset-failed %2$s\"\n"
216223 "followed by \"%1$s start %2$s\" again." ,
217224 systemctl ,
218225 service_shell_quoted ?: "<service>" );
@@ -226,51 +233,51 @@ static int check_wait_response(BusWaitForJobs *d, WaitJobsFlags flags, const cha
226233 assert (d -> result );
227234
228235 if (streq (d -> result , "done" )) {
229- if (FLAGS_SET (flags , BUS_WAIT_JOBS_LOG_SUCCESS ))
230- log_info ( "Job for %s finished." , d -> name );
236+ log_full (FLAGS_SET (flags , BUS_WAIT_JOBS_LOG_SUCCESS ) ? LOG_INFO : LOG_DEBUG ,
237+ "Job for %s finished." , d -> name );
231238
232239 return 0 ;
233240 } else if (streq (d -> result , "skipped" )) {
234- if (FLAGS_SET (flags , BUS_WAIT_JOBS_LOG_SUCCESS ))
235- log_info ( "Job for %s was skipped." , d -> name );
241+ log_full (FLAGS_SET (flags , BUS_WAIT_JOBS_LOG_SUCCESS ) ? LOG_INFO : LOG_DEBUG ,
242+ "Job for %s was skipped." , d -> name );
236243
237244 return 0 ;
238245 }
239246
240- if ( FLAGS_SET (flags , BUS_WAIT_JOBS_LOG_ERROR )) {
241- if ( streq ( d -> result , "canceled" ))
242- log_error ( "Job for %s canceled." , d -> name );
243- else if ( streq ( d -> result , "timeout" ))
244- log_error ( "Job for %s timed out." , d -> name );
245- else if ( streq ( d -> result , "dependency" ))
246- log_error ( "A dependency job for %s failed. See 'journalctl -xe' for details." , d -> name );
247- else if ( streq ( d -> result , "invalid" ))
248- log_error ( "%s is not active, cannot reload." , d -> name );
249- else if ( streq ( d -> result , "assert" ))
250- log_error ( "Assertion failed on job for %s." , d -> name );
251- else if ( streq ( d -> result , "unsupported" ))
252- log_error ( "Operation on or unit type of %s not supported on this system." , d -> name );
253- else if ( streq ( d -> result , "collected" ))
254- log_error ( "Queued job for %s was garbage collected." , d -> name );
255- else if ( streq ( d -> result , "once" ))
256- log_error ( "Unit %s was started already once and can't be started again." , d -> name );
257- else if ( streq ( d -> result , "frozen" ))
258- log_error ( "Cannot perform operation on frozen unit %s." , d -> name );
259- else if ( streq ( d -> result , "concurrency" ))
260- log_error ( "Concurrency limit of a slice unit %s is contained in has been reached." , d -> name );
261- else if ( endswith ( d -> name , ".service" )) {
262- /* Job result is unknown. For services, let's also try Result property. */
263- _cleanup_free_ char * result = NULL ;
264-
265- r = bus_job_get_service_result ( d , & result );
266- if ( r < 0 )
267- log_debug_errno ( r , "Failed to get Result property of unit %s, ignoring: %m" ,
268- d -> name );
269-
270- log_job_error_with_service_result ( d -> name , result , extra_args );
271- } else /* Otherwise we just show a generic message. */
272- log_error ( "Job failed. See \"journalctl -xe\" for details." );
273- }
247+ int priority = FLAGS_SET (flags , BUS_WAIT_JOBS_LOG_ERROR ) ? LOG_ERR : LOG_DEBUG ;
248+
249+ if ( streq ( d -> result , "canceled" ))
250+ log_full ( priority , "Job for %s canceled." , d -> name );
251+ else if ( streq ( d -> result , "timeout" ))
252+ log_full ( priority , "Job for %s timed out." , d -> name );
253+ else if ( streq ( d -> result , "dependency" ))
254+ log_full ( priority , "A dependency job for %s failed. See 'journalctl -xe' for details." , d -> name );
255+ else if ( streq ( d -> result , "invalid" ))
256+ log_full ( priority , "%s is not active, cannot reload." , d -> name );
257+ else if ( streq ( d -> result , "assert" ))
258+ log_full ( priority , "Assertion failed on job for %s." , d -> name );
259+ else if ( streq ( d -> result , "unsupported" ))
260+ log_full ( priority , "Operation on or unit type of %s not supported on this system." , d -> name );
261+ else if ( streq ( d -> result , "collected" ))
262+ log_full ( priority , "Queued job for %s was garbage collected." , d -> name );
263+ else if ( streq ( d -> result , "once" ))
264+ log_full ( priority , "Unit %s was started already once and can't be started again." , d -> name );
265+ else if ( streq ( d -> result , "frozen" ))
266+ log_full ( priority , "Cannot perform operation on frozen unit %s." , d -> name );
267+ else if ( streq ( d -> result , "concurrency" ))
268+ log_full ( priority , "Concurrency limit of a slice unit %s is contained in has been reached." , d -> name );
269+ else if ( endswith ( d -> name , ".service" )) {
270+ /* Job result is unknown. For services, let's also try Result property. */
271+ _cleanup_free_ char * result = NULL ;
272+
273+ r = bus_job_get_service_result ( d , & result );
274+ if ( r < 0 )
275+ log_debug_errno ( r , "Failed to get Result property of unit %s, ignoring: %m" ,
276+ d -> name );
277+
278+ log_job_error_with_service_result ( d -> name , result , priority , extra_args );
279+ } else /* Otherwise we just show a generic message. */
280+ log_full ( priority , "Job failed. See \"journalctl -xe\" for details." );
274281
275282 if (STR_IN_SET (d -> result , "canceled" , "collected" ))
276283 return - ECANCELED ;
0 commit comments