瀏覽代碼

[cmdline] Store exit status of failed command in errno

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 年之前
父節點
當前提交
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
 /**

Loading…
取消
儲存