main/reboot-mode: new aport (!442)

New tool to reboot the device to a specific mode.
This commit is contained in:
Daniele Debernardi 2019-06-20 22:03:38 +02:00 committed by Oliver Smith
parent af263907ca
commit 375e98b950
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
2 changed files with 78 additions and 0 deletions

25
main/reboot-mode/APKBUILD Normal file
View file

@ -0,0 +1,25 @@
# Contributor: Daniele Debernardi <drebrez@gmail.com>
# Maintainer: Daniele Debernardi <drebrez@gmail.com>
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"

View file

@ -0,0 +1,53 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
* Reboot the device to a specific mode
*
* Copyright (C) 2019 Daniele Debernardi <drebrez@gmail.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/reboot.h>
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;
}