| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* Control socket for client/server test execution |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * Copyright (C) 2017 Red Hat, Inc. |
|---|
| 4 | 5 | * |
|---|
| 5 | 6 | * 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. |
|---|
| 11 | 7 | */ |
|---|
| 12 | 8 | |
|---|
| 13 | 9 | /* The client and server may need to coordinate to avoid race conditions like |
|---|
| .. | .. |
|---|
| 209 | 205 | char *line; |
|---|
| 210 | 206 | |
|---|
| 211 | 207 | 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) { |
|---|
| 213 | 220 | fprintf(stderr, "expected \"%s\" on control socket, got \"%s\"\n", |
|---|
| 214 | 221 | str, line); |
|---|
| 215 | 222 | exit(EXIT_FAILURE); |
|---|
| 216 | 223 | } |
|---|
| 217 | 224 | |
|---|
| 218 | | - free(line); |
|---|
| 225 | + return false; |
|---|
| 219 | 226 | } |
|---|