|
| 1 | +/* Setup and start system qmicli proxy |
| 2 | + * |
| 3 | + * Portions Copyright (c) 2012-2022 Joachim Wiberg <[email protected]> |
| 4 | + * Portions Copyright (c) 2022 Andy Savage <[email protected]> |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +#include <sys/types.h> |
| 26 | +#ifndef _LIBITE_LITE |
| 27 | +# include <lite/lite.h> |
| 28 | +#else |
| 29 | +# include <libite/lite.h> |
| 30 | +#endif |
| 31 | + |
| 32 | +#include "finit/finit.h" |
| 33 | +#include "finit/helpers.h" |
| 34 | +#include "finit/plugin.h" |
| 35 | +#include "finit/service.h" |
| 36 | +#include "finit/conf.h" |
| 37 | + |
| 38 | +#define QMI_PROXY_DAEMON "/usr/libexec/qmi-proxy" |
| 39 | +#define QMI_PROXY_ARGS "--no-exit" |
| 40 | +#define QMI_PROXY_DESC "Proxy for QMI devices" |
| 41 | + |
| 42 | +#ifndef QMI_PROXY_DAEMONUSER |
| 43 | +#define QMI_PROXY_DAEMONUSER "root" |
| 44 | +#endif |
| 45 | + |
| 46 | +#ifndef QMI_PROXY_DAEMONGROUP |
| 47 | +#define QMI_PROXY_DAEMONGROUP "root" |
| 48 | +#endif |
| 49 | + |
| 50 | +#ifndef QMI_PROXY_DAEMONPIDFILE |
| 51 | +#define QMI_PROXY_DAEMONPIDFILE "/var/run/qmi-proxy.pid" |
| 52 | +#endif |
| 53 | + |
| 54 | +static void setup(void *arg) |
| 55 | +{ |
| 56 | + char line[256]; |
| 57 | + mode_t prev; |
| 58 | + char *cmd; |
| 59 | + |
| 60 | + if (rescue) { |
| 61 | + _d("Skipping %s plugin in rescue mode.", __FILE__); |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + cmd = which(QMI_PROXY_DAEMON); |
| 66 | + if (!cmd) { |
| 67 | + _d("Skipping plugin, %s is not installed.", QMI_PROXY_DAEMON); |
| 68 | + return; |
| 69 | + } |
| 70 | + |
| 71 | + prev =umask(0); |
| 72 | + |
| 73 | + /* Clean up from any previous pre-bootstrap run */ |
| 74 | + remove(QMI_PROXY_DAEMONPIDFILE); |
| 75 | + |
| 76 | + /* Register service with Finit */ |
| 77 | + snprintf(line, sizeof(line), "[S12345789] cgroup.system pid:!%s @%s:%s %s %s -- %s", |
| 78 | + QMI_PROXY_DAEMONPIDFILE, QMI_PROXY_DAEMONUSER, QMI_PROXY_DAEMONUSER, cmd, QMI_PROXY_ARGS, QMI_PROXY_DESC); |
| 79 | + if (service_register(SVC_TYPE_SERVICE, line, global_rlimit, NULL)) |
| 80 | + _pe("Failed registering %s", QMI_PROXY_DAEMON); |
| 81 | + free(cmd); |
| 82 | + |
| 83 | + umask(prev); |
| 84 | +} |
| 85 | + |
| 86 | +static plugin_t plugin = { |
| 87 | + .name = __FILE__, |
| 88 | + .hook[HOOK_BASEFS_UP] = { |
| 89 | + .cb = setup |
| 90 | + }, |
| 91 | + .depends = { "bootmisc", "mdevd" }, |
| 92 | +}; |
| 93 | + |
| 94 | +PLUGIN_INIT(plugin_init) |
| 95 | +{ |
| 96 | + plugin_register(&plugin); |
| 97 | +} |
| 98 | + |
| 99 | +PLUGIN_EXIT(plugin_exit) |
| 100 | +{ |
| 101 | + plugin_unregister(&plugin); |
| 102 | +} |
| 103 | + |
| 104 | +/** |
| 105 | + * Local Variables: |
| 106 | + * indent-tabs-mode: t |
| 107 | + * c-file-style: "linux" |
| 108 | + * End: |
| 109 | + */ |
0 commit comments