[CRIU] [PATCH 5/8] compel: error out on unknown opt or missing arg

Kir Kolyshkin kir at openvz.org
Mon Dec 5 15:37:08 PST 2016


getopt_long() prints an error message and returns '?' in cases
 - an unknown option is given
 - a required option argument is missing

In such cases, we need to show usage and exit with an error.

Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
 compel/src/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/compel/src/main.c b/compel/src/main.c
index a2e9a56..7fa4d7c 100644
--- a/compel/src/main.c
+++ b/compel/src/main.c
@@ -201,7 +201,9 @@ int main(int argc, char *argv[])
 			       COMPEL_SO_VERSION_SUBLEVEL);
 			exit(0);
 			break;
-		default:
+		default: // '?'
+			// error message already printed by getopt_long()
+			return usage(1);
 			break;
 		}
 	}
-- 
2.7.4



More information about the CRIU mailing list