blob: 9434e1d2699c21fba396fdbf0758ee0b04619f69 [file] [log] [blame]
Patrick Williams2390b1b2022-11-03 13:47:49 -05001/*
2 * Copyright 2022 Garmin Ltd. or its subsidiaries
3 *
4 * SPDX-License-Identifier: GPL-2.0
5 *
6 * Attempts to find and exec the host qemu-bridge-helper program
7 */
8
9#include <stdio.h>
10#include <unistd.h>
Andrew Geissler517393d2023-01-13 08:55:19 -060011#include <stdlib.h>
Patrick Williams2390b1b2022-11-03 13:47:49 -050012
13void try_program(char const* path, char** args) {
14 if (access(path, X_OK) == 0) {
15 execv(path, args);
16 }
17}
18
19int main(int argc, char** argv) {
20 char* var;
21
Patrick Williams2390b1b2022-11-03 13:47:49 -050022 var = getenv("QEMU_BRIDGE_HELPER");
23 if (var && var[0] != '\0') {
Andrew Geissler517393d2023-01-13 08:55:19 -060024 execvp(var, argv);
Patrick Williams2390b1b2022-11-03 13:47:49 -050025 return 1;
26 }
27
Andrew Geissler517393d2023-01-13 08:55:19 -060028 try_program("/usr/libexec/qemu-bridge-helper", argv);
29 try_program("/usr/lib/qemu/qemu-bridge-helper", argv);
Patrick Williams2390b1b2022-11-03 13:47:49 -050030
31 fprintf(stderr, "No bridge helper found\n");
32 return 1;
33}
34