hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/tools/testing/vsock/control.c
....@@ -1,13 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* Control socket for client/server test execution
23 *
34 * Copyright (C) 2017 Red Hat, Inc.
45 *
56 * Author: Stefan Hajnoczi <stefanha@redhat.com>
6
- *
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License
9
- * as published by the Free Software Foundation; version 2
10
- * of the License.
117 */
128
139 /* The client and server may need to coordinate to avoid race conditions like
....@@ -209,11 +205,22 @@
209205 char *line;
210206
211207 line = control_readln();
212
- if (strcmp(str, line) != 0) {
208
+
209
+ control_cmpln(line, str, true);
210
+
211
+ free(line);
212
+}
213
+
214
+bool control_cmpln(char *line, const char *str, bool fail)
215
+{
216
+ if (strcmp(str, line) == 0)
217
+ return true;
218
+
219
+ if (fail) {
213220 fprintf(stderr, "expected \"%s\" on control socket, got \"%s\"\n",
214221 str, line);
215222 exit(EXIT_FAILURE);
216223 }
217224
218
- free(line);
225
+ return false;
219226 }