@@ -46,13 +46,15 @@ int utmp_get_runlevel(int *runlevel, int *previous) {
4646 * very new and does not apply to the current script being
4747 * executed. */
4848
49- if ((e = getenv ("RUNLEVEL" )) && e [0 ] > 0 ) {
49+ e = getenv ("RUNLEVEL" );
50+ if (e && e [0 ] > 0 ) {
5051 * runlevel = e [0 ];
5152
5253 if (previous ) {
5354 /* $PREVLEVEL seems to be an Upstart thing */
5455
55- if ((e = getenv ("PREVLEVEL" )) && e [0 ] > 0 )
56+ e = getenv ("PREVLEVEL" );
57+ if (e && e [0 ] > 0 )
5658 * previous = e [0 ];
5759 else
5860 * previous = 0 ;
@@ -66,7 +68,8 @@ int utmp_get_runlevel(int *runlevel, int *previous) {
6668
6769 setutxent ();
6870
69- if (!(found = getutxid (& lookup )))
71+ found = getutxid (& lookup );
72+ if (!found )
7073 r = - errno ;
7174 else {
7275 int a , b ;
@@ -232,7 +235,8 @@ int utmp_put_dead_process(const char *id, pid_t pid, int code, int status) {
232235 lookup .ut_type = INIT_PROCESS ; /* looks for DEAD_PROCESS, LOGIN_PROCESS, USER_PROCESS, too */
233236 strncpy (lookup .ut_id , sanitize_id (id ), sizeof (lookup .ut_id ));
234237
235- if (!(found = getutxid (& lookup )))
238+ found = getutxid (& lookup );
239+ if (!found )
236240 return 0 ;
237241
238242 if (found -> ut_pid != pid )
@@ -264,7 +268,8 @@ int utmp_put_runlevel(int runlevel, int previous) {
264268 if (previous <= 0 ) {
265269 /* Find the old runlevel automatically */
266270
267- if ((r = utmp_get_runlevel (& previous , NULL )) < 0 ) {
271+ r = utmp_get_runlevel (& previous , NULL );
272+ if (r < 0 ) {
268273 if (r != - ESRCH )
269274 return r ;
270275
@@ -343,16 +348,15 @@ static int write_to_terminal(const char *tty, const char *message) {
343348}
344349
345350int utmp_wall (const char * message , bool (* match_tty )(const char * tty )) {
346- struct utmpx * u ;
351+ _cleanup_free_ char * text = NULL , * hn = NULL , * un = NULL , * tty = NULL ;
347352 char date [FORMAT_TIMESTAMP_MAX ];
348- char * text = NULL , * hn = NULL , * un = NULL , * tty = NULL ;
353+ struct utmpx * u ;
349354 int r ;
350355
351- if (!(hn = gethostname_malloc ()) ||
352- !(un = getlogname_malloc ())) {
353- r = - ENOMEM ;
354- goto finish ;
355- }
356+ hn = gethostname_malloc ();
357+ un = getlogname_malloc ();
358+ if (!hn || !un )
359+ return - ENOMEM ;
356360
357361 getttyname_harder (STDIN_FILENO , & tty );
358362
@@ -363,19 +367,17 @@ int utmp_wall(const char *message, bool (*match_tty)(const char *tty)) {
363367 un , hn ,
364368 tty ? " on " : "" , strempty (tty ),
365369 format_timestamp (date , sizeof (date ), now (CLOCK_REALTIME )),
366- message ) < 0 ) {
367- r = - ENOMEM ;
368- goto finish ;
369- }
370+ message ) < 0 )
371+ return - ENOMEM ;
370372
371373 setutxent ();
372374
373375 r = 0 ;
374376
375377 while ((u = getutxent ())) {
376- int q ;
378+ _cleanup_free_ char * buf = NULL ;
377379 const char * path ;
378- char * buf = NULL ;
380+ int q ;
379381
380382 if (u -> ut_type != USER_PROCESS || u -> ut_user [0 ] == 0 )
381383 continue ;
@@ -384,27 +386,18 @@ int utmp_wall(const char *message, bool (*match_tty)(const char *tty)) {
384386 if (path_startswith (u -> ut_line , "/dev/" ))
385387 path = u -> ut_line ;
386388 else {
387- if (asprintf (& buf , "/dev/%.*s" ,
388- (int ) sizeof (u -> ut_line ), u -> ut_line ) < 0 ) {
389- r = - ENOMEM ;
390- goto finish ;
391- }
389+ if (asprintf (& buf , "/dev/%.*s" , (int ) sizeof (u -> ut_line ), u -> ut_line ) < 0 )
390+ return - ENOMEM ;
392391
393392 path = buf ;
394393 }
395394
396- if (!match_tty || match_tty (path ))
397- if ((q = write_to_terminal (path , text )) < 0 )
395+ if (!match_tty || match_tty (path )) {
396+ q = write_to_terminal (path , text );
397+ if (q < 0 )
398398 r = q ;
399-
400- free (buf );
399+ }
401400 }
402401
403- finish :
404- free (hn );
405- free (un );
406- free (tty );
407- free (text );
408-
409402 return r ;
410403}
0 commit comments