Просмотр исходного кода

[cmdline] Store exit status of failed command in errno

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 лет назад
Родитель
Сommit
5b4958388d
1 измененных файлов: 22 добавлений и 6 удалений
  1. 22
    6
      src/core/exec.c

+ 22
- 6
src/core/exec.c Просмотреть файл

@@ -59,18 +59,22 @@ static int stop_state;
59 59
 int execv ( const char *command, char * const argv[] ) {
60 60
 	struct command *cmd;
61 61
 	int argc;
62
+	int rc;
62 63
 
63 64
 	/* Count number of arguments */
64 65
 	for ( argc = 0 ; argv[argc] ; argc++ ) {}
65 66
 
66 67
 	/* An empty command is deemed to do nothing, successfully */
67
-	if ( command == NULL )
68
-		return 0;
68
+	if ( command == NULL ) {
69
+		rc = 0;
70
+		goto done;
71
+	}
69 72
 
70 73
 	/* Sanity checks */
71 74
 	if ( argc == 0 ) {
72 75
 		DBG ( "%s: empty argument list\n", command );
73
-		return -EINVAL;
76
+		rc = -EINVAL;
77
+		goto done;
74 78
 	}
75 79
 
76 80
 	/* Reset getopt() library ready for use by the command.  This
@@ -82,12 +86,24 @@ int execv ( const char *command, char * const argv[] ) {
82 86
 
83 87
 	/* Hand off to command implementation */
84 88
 	for_each_table_entry ( cmd, COMMANDS ) {
85
-		if ( strcmp ( command, cmd->name ) == 0 )
86
-			return cmd->exec ( argc, ( char ** ) argv );
89
+		if ( strcmp ( command, cmd->name ) == 0 ) {
90
+			rc = cmd->exec ( argc, ( char ** ) argv );
91
+			goto done;
92
+		}
87 93
 	}
88 94
 
89 95
 	printf ( "%s: command not found\n", command );
90
-	return -ENOEXEC;
96
+	rc = -ENOEXEC;
97
+
98
+ done:
99
+	/* Store error number, if an error occurred */
100
+	if ( rc ) {
101
+		errno = rc;
102
+		if ( errno < 0 )
103
+			errno = -errno;
104
+	}
105
+
106
+	return rc;
91 107
 }
92 108
 
93 109
 /**

Загрузка…
Отмена
Сохранить