From 375e98b950a5264c52fc13fbe05625ab9c295e99 Mon Sep 17 00:00:00 2001 From: Daniele Debernardi Date: Thu, 20 Jun 2019 22:03:38 +0200 Subject: [PATCH] main/reboot-mode: new aport (!442) New tool to reboot the device to a specific mode. --- main/reboot-mode/APKBUILD | 25 ++++++++++++++++ main/reboot-mode/reboot-mode.c | 53 ++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 main/reboot-mode/APKBUILD create mode 100644 main/reboot-mode/reboot-mode.c diff --git a/main/reboot-mode/APKBUILD b/main/reboot-mode/APKBUILD new file mode 100644 index 000000000..dc52a3a5b --- /dev/null +++ b/main/reboot-mode/APKBUILD @@ -0,0 +1,25 @@ +# Contributor: Daniele Debernardi +# Maintainer: Daniele Debernardi +pkgname=reboot-mode +pkgver=0.1 +pkgrel=0 +pkgdesc="Reboot the device to a specific mode" +url="https://postmarketos.org" +arch="all" +license="GPL-3.0-or-later" +makedepends="musl-dev linux-headers" +source="reboot-mode.c" +options="!check" +builddir="$srcdir/" + +build() { + gcc reboot-mode.c -o reboot-mode.o -c + gcc reboot-mode.o -o reboot-mode +} + +package() { + install -Dm755 "reboot-mode" \ + "${pkgdir}/usr/sbin/reboot-mode" +} + +sha512sums="569b6b1cf595e208b8c5731ea8d4334cd5458cbc2a63d5756014f55f04dd89a4b67ec0d0d01d7a1cd935ae13d44e62e3ea6765f626736bc3dc2029b890c20070 reboot-mode.c" diff --git a/main/reboot-mode/reboot-mode.c b/main/reboot-mode/reboot-mode.c new file mode 100644 index 000000000..d94dca474 --- /dev/null +++ b/main/reboot-mode/reboot-mode.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +/* + * Reboot the device to a specific mode + * + * Copyright (C) 2019 Daniele Debernardi + */ +#include +#include +#include +#include +#include +#include + +void usage(char* appname) +{ + printf("Usage: %s [-h] MODE\n\n", appname); + printf("Reboot the device to the MODE specified (e.g. recovery, bootloader)\n\n"); + printf("WARNING: the reboot is instantaneous\n\n"); + printf("optional arguments:\n"); + printf(" -h Show this help message and exit\n"); +} + +int main(int argc, char** argv) +{ + if (argc != 2) + { + usage(argv[0]); + exit(1); + } + + int opt; + while ((opt = getopt(argc, argv, "h")) != -1) + { + switch (opt) + { + case 'h': + default: + usage(argv[0]); + exit(1); + } + } + + sync(); + + int ret; + ret = syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, argv[1]); + + if (ret) { + printf("Error: %s", strerror(ret)); + } + + return ret; +}