xref: /OK3568_Linux_fs/yocto/poky/meta/recipes-devtools/qemu/qemu-helper/qemu-oe-bridge-helper.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
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>
11 #include <stdlib.h>
12 
try_program(char const * path,char ** args)13 void try_program(char const* path, char** args) {
14     if (access(path, X_OK) == 0) {
15         execv(path, args);
16     }
17 }
18 
main(int argc,char ** argv)19 int main(int argc, char** argv) {
20     char* var;
21 
22     var = getenv("QEMU_BRIDGE_HELPER");
23     if (var && var[0] != '\0') {
24         execvp(var, argv);
25         return 1;
26     }
27 
28     try_program("/usr/libexec/qemu-bridge-helper", argv);
29     try_program("/usr/lib/qemu/qemu-bridge-helper", argv);
30 
31     fprintf(stderr, "No bridge helper found\n");
32     return 1;
33 }
34 
35