Commit 375e98b9 authored by Daniele Debernardi's avatar Daniele Debernardi Committed by Oliver Smith

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

New tool to reboot the device to a specific mode.
parent af263907
Pipeline #67788727 failed with stages
in 1 minute and 29 seconds
# 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"
// 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment