Skip to contentSkip to conversation

tools/xen-ucode: return correct exit code on failed microcode update

PATCH In review Igor Druzhinin 3 participants 3 messages Jun 17, 2020 – Jun 18, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 tools/xen-ucode: return correct exit code on failed microcode update

Otherwise it's difficult to know if operation failed inside the automation.

While at it, also switch to returning 1 and 2 instead of errno to avoid incompatibilies between errno and special exit code numbers.

---
Changes in v3:
- conventionally return 1 and 2 instead of errno as exit code

---
 tools/misc/xen-ucode.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
tools/misc/xen-ucode.c +9 -6
index 0c257f4..ad32fac 100644
@@ -25,7 +25,7 @@ int main(int argc, char *argv[])
         fprintf(stderr,
                 "xen-ucode: Xen microcode updating tool\n"
                 "Usage: %s <microcode blob>\n", argv[0]);
-        return 0;
+        exit(2);
     }
 
     filename = argv[1];
@@ -34,14 +34,14 @@ int main(int argc, char *argv[])
     {
         fprintf(stderr, "Could not open %s. (err: %s)\n",
                 filename, strerror(errno));
-        return errno;
+        exit(1);
     }
 
     if ( fstat(fd, &st) != 0 )
     {
         fprintf(stderr, "Could not get the size of %s. (err: %s)\n",
                 filename, strerror(errno));
-        return errno;
+        exit(1);
     }
 
     len = st.st_size;
@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
     if ( buf == MAP_FAILED )
     {
         fprintf(stderr, "mmap failed. (error: %s)\n", strerror(errno));
-        return errno;
+        exit(1);
     }
 
     xch = xc_interface_open(NULL, NULL, 0);
@@ -57,20 +57,23 @@ int main(int argc, char *argv[])
     {
         fprintf(stderr, "Error opening xc interface. (err: %s)\n",
                 strerror(errno));
-        return errno;
+        exit(1);
     }
 
     ret = xc_microcode_update(xch, buf, len);
     if ( ret )
+    {
         fprintf(stderr, "Failed to update microcode. (err: %s)\n",
                 strerror(errno));
+        exit(1);
+    }
 
     xc_interface_close(xch);
 
     if ( munmap(buf, len) )
     {
         printf("Could not unmap: %d(%s)\n", errno, strerror(errno));
-        return errno;
+        exit(1);
     }
     close(fd);
 
Signature · 1 line
2.7.4
Reviewed-by on v3 1/1
#1 lore raw
Quoted 8 lines

-----Original Message-----
From: Igor Druzhinin <[email protected]>
Sent: 17 June 2020 03:19
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Igor Druzhinin <[email protected]>
Subject: [PATCH for-4.14 v3] tools/xen-ucode: return correct exit code on failed microcode update

Quoted 6 lines

Otherwise it's difficult to know if operation failed inside the automation.

While at it, also switch to returning 1 and 2 instead of errno to avoid incompatibilies between errno and special exit code numbers.

Quoted 74 lines

---
Changes in v3:
- conventionally return 1 and 2 instead of errno as exit code

---
 tools/misc/xen-ucode.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
tools/misc/xen-ucode.c +9 -7
index 0c257f4..ad32fac 100644
@@ -25,7 +25,7 @@ int main(int argc, char *argv[])
         fprintf(stderr,
                 "xen-ucode: Xen microcode updating tool\n"
                 "Usage: %s <microcode blob>\n", argv[0]);
-        return 0;
+        exit(2);
     }
 
     filename = argv[1];
@@ -34,14 +34,14 @@ int main(int argc, char *argv[])
     {
         fprintf(stderr, "Could not open %s. (err: %s)\n",
                 filename, strerror(errno));
-        return errno;
+        exit(1);
     }
 
     if ( fstat(fd, &st) != 0 )
     {
         fprintf(stderr, "Could not get the size of %s. (err: %s)\n",
                 filename, strerror(errno));
-        return errno;
+        exit(1);
     }
 
     len = st.st_size;
@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
     if ( buf == MAP_FAILED )
     {
         fprintf(stderr, "mmap failed. (error: %s)\n", strerror(errno));
-        return errno;
+        exit(1);
     }
 
     xch = xc_interface_open(NULL, NULL, 0);
@@ -57,20 +57,23 @@ int main(int argc, char *argv[])
     {
         fprintf(stderr, "Error opening xc interface. (err: %s)\n",
                 strerror(errno));
-        return errno;
+        exit(1);
     }
 
     ret = xc_microcode_update(xch, buf, len);
     if ( ret )
+    {
         fprintf(stderr, "Failed to update microcode. (err: %s)\n",
                 strerror(errno));
+        exit(1);
+    }
 
     xc_interface_close(xch);
 
     if ( munmap(buf, len) )
     {
         printf("Could not unmap: %d(%s)\n", errno, strerror(errno));
-        return errno;
+        exit(1);
     }
     close(fd);
 
--

2.7.4

Reviewed-by
#2 lore raw

Paul Durrant writes ("RE: [PATCH for-4.14 v3] tools/xen-ucode: return correct exit code on failed microcode update"):

Quoted 8 lines
Quoted 8 lines

-----Original Message-----
From: Igor Druzhinin <[email protected]>
Sent: 17 June 2020 03:19
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Igor Druzhinin <[email protected]>
Subject: [PATCH for-4.14 v3] tools/xen-ucode: return correct exit code on failed microcode update

Quoted 6 lines
Quoted 6 lines

Otherwise it's difficult to know if operation failed inside the automation.

While at it, also switch to returning 1 and 2 instead of errno to avoid incompatibilies between errno and special exit code numbers.

Thanks, this looks good to me.

Quoted 2 lines

I will commit this in a moment.

Ian.