[PATCH 8/11] simpleinit: Use EXIT_*

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Marek Polacek <mmpolacek@xxxxxxxxx>
---
 login-utils/simpleinit.c |   44
++++++++++++++++++++++++--------------------
 1 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/login-utils/simpleinit.c b/login-utils/simpleinit.c
index 9277a3c..3863700 100644
--- a/login-utils/simpleinit.c
+++ b/login-utils/simpleinit.c
@@ -241,7 +241,7 @@ int main(int argc, char *argv[])
 		printf("tty= %s\n", inittab[i].tty);
 		printf("termcap= %s\n", inittab[i].termcap);
 	}
-	exit(0);
+	exit(EXIT_SUCCESS);
 #endif
 	signal (SIGHUP, sighup_handler);  /* Better semantics with signal(2) */

@@ -257,7 +257,7 @@ int main(int argc, char *argv[])
 		  case 0:   /*  Child   */
 		    execl (final_prog, final_prog, "start", NULL);
 		    err ( _("error running finalprog\n") );
-		    _exit (1);
+		    _exit(EXIT_FAILURE);
 		    break;
 		  case -1:  /*  Error   */
 		    err ( _("error forking finalprog\n") );
@@ -371,7 +371,9 @@ static int do_rc_tty (const char *path)
     pid_t pid;
     sigset_t ss;

-    if (caught_sigint) return 0;
+    if (caught_sigint)
+        return EXIT_SUCCESS;
+
     process_path (path, preload_file, 0);
     /*  Launch off a subprocess to start a new session (required for
frobbing
 	the TTY) and capture control-C  */
@@ -388,7 +390,7 @@ static int do_rc_tty (const char *path)
 	sigsuspend (&ss);  /*  Should never return, should just be killed  */
 	break;             /*  No-one else is controlled by this TTY now   */
       case -1:  /*  Error  */
-	return (1);
+	return EXIT_FAILURE;
 	/*break;*/
       default:  /*  Parent  */
 	break;
@@ -398,12 +400,12 @@ static int do_rc_tty (const char *path)
     while (1)
     {
 	if ( ( pid = mywait (&status) ) == rc_child )
-	    return (WTERMSIG (status) == SIGINT) ? 0 : 1;
+	    return (WTERMSIG (status) == SIGINT) ? EXIT_SUCCESS : EXIT_FAILURE;
 	if (pid < 0) break;
     }
     kill (rc_child, SIGKILL);
     while (waitpid (rc_child, NULL, 0) != rc_child)  /*  Nothing  */;
-    return 0;
+    return EXIT_SUCCESS;
 }   /*  End Function do_rc_tty  */

 static int process_path (const char *path, int (*func) (const char *path),
@@ -416,7 +418,7 @@ static int process_path (const char *path, int
(*func) (const char *path),
     if (lstat (path, &statbuf) != 0)
     {
 	err (_("lstat of path failed\n") );
-	return 1;
+	return EXIT_FAILURE;
     }
     if ( S_ISLNK (statbuf.st_mode) )
     {
@@ -424,7 +426,7 @@ static int process_path (const char *path, int
(*func) (const char *path),
 	{
 	    if ( (errno == ENOENT) && ignore_dangling_symlink ) return 0;
 	    err (_("stat of path failed\n") );
-	    return 1;
+	    return EXIT_FAILURE;
 	}
     }
     if ( !( statbuf.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH) ) ) return 0;
@@ -432,7 +434,7 @@ static int process_path (const char *path, int
(*func) (const char *path),
     if ( ( dp = opendir (path) ) == NULL )
     {
 	err (_("open of directory failed\n") );
-	return 1;
+	return EXIT_FAILURE;
     }
     while ( ( de = readdir (dp) ) != NULL )
     {
@@ -445,7 +447,7 @@ static int process_path (const char *path, int
(*func) (const char *path),
 	if ( ( retval = process_path (newpath, func, 1) ) ) return retval;
     }
     closedir (dp);
-    return 0;
+    return EXIT_SUCCESS;
 }   /*  End Function process_path  */

 static int preload_file (const char *path)
@@ -453,10 +455,10 @@ static int preload_file (const char *path)
     int fd;
     char ch;

-    if ( ( fd = open (path, O_RDONLY, 0) ) < 0) return 0;
+    if ( ( fd = open (path, O_RDONLY, 0) ) < 0) return EXIT_SUCCESS;
     while (read (fd, &ch, 1) == 1) lseek (fd, 1024, SEEK_CUR);
     close (fd);
-    return 0;
+    return EXIT_SUCCESS;
 }   /*  End Function preload_file  */

 static int run_file (const char *path)
@@ -465,7 +467,7 @@ static int run_file (const char *path)

     if ( ( ptr = strrchr ( (char *) path, '/' ) ) == NULL ) ptr = path;
     else ++ptr;
-    return (run_command (path, ptr, 0) == SIG_FAILED) ? 1 : 0;
+    return (run_command (path, ptr, 0) == SIG_FAILED) ? EXIT_FAILURE :
EXIT_SUCCESS;
 }   /*  End Function run_file  */

 static void spawn (int i)
@@ -539,7 +541,7 @@ static void spawn (int i)
 		execve(inittab[i].toks[0], inittab[i].toks, env);
 		err(_("exec failed\n"));
 		sleep(5);
-		_exit(1);
+		_exit(EXIT_FAILURE);
 	}
 }

@@ -699,7 +701,8 @@ static void sigint_handler (int sig)

     caught_sigint = 1;
     kill (rc_child, SIGKILL);
-    if (no_reboot) _exit (1) /*kill (0, SIGKILL)*/;
+    if (no_reboot)
+	_exit(EXIT_FAILURE) /*kill (0, SIGKILL)*/;
     sync ();
     sync ();
     pid = fork ();
@@ -962,9 +965,10 @@ static void process_command (const struct
command_struct *command)
       case COMMAND_DUMP_LIST:
 	if (fork () == 0) /* Do it in a child process so pid=1 doesn't block */
 	{
-	    FILE *fp;
+	    FILE *fp = fopen(command->name, "w");
+	    if (!fp)
+	        _exit(EXIT_FAILURE);

-	    if ( ( fp = fopen (command->name, "w") ) == NULL ) _exit (1);
 	    show_scripts (fp, available_list.first, "AVAILABLE");
 	    show_scripts (fp, starting_list.first, "STARTING");
 	    fputs ("UNAVAILABLE SERVICES:\n", fp);
@@ -973,7 +977,7 @@ static void process_command (const struct
command_struct *command)
 		fprintf (fp, "%s (%s)\n", service->name,
 			 service->failed ? "FAILED" : "not configured");
 	    fclose (fp);
-	    _exit (0);
+	    _exit(EXIT_SUCCESS);
 	}
 	break;
       case COMMAND_PROVIDE:
@@ -1088,10 +1092,10 @@ static int run_command (const char *file, const
char *name, pid_t pid)
 	    break;
 	}
     }
-    if (needer == NULL) return 0;
+    if (needer == NULL) return EXIT_SUCCESS;
     needer->next = service->needers;
     service->needers = needer;
-    return 0;
+    return EXIT_SUCCESS;
 }   /*  End Function run_command  */

 static struct service_struct *find_service_in_list (const char *name,
-- 
1.7.3.2


--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux