annotate toys/other/reboot.c @ 1322:b91284c2e569 draft

Make "losetup /dev/loop0 filename" work. Sigh. Implement the complex cases and you screw up the simple cases you already tested...
author Rob Landley <rob@landley.net>
date Thu, 29 May 2014 06:29:12 -0500
parents e1d3a9ac9e9f
children 5fac2769a159
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1092
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
1 /* reboot.c - Restart, halt or powerdown the system.
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
2 *
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
3 * Copyright 2013 Elie De Brauwer <eliedebrauwer@gmail.com>
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
4
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
5 USE_REBOOT(NEWTOY(reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
6 USE_REBOOT(OLDTOY(halt, reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
7 USE_REBOOT(OLDTOY(poweroff, reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
8
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
9 config REBOOT
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
10 bool "reboot"
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
11 default y
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
12 help
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
13 usage: reboot/halt/poweroff [-n]
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
14
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
15 Restart, halt or powerdown the system.
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
16
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
17 -n Don't sync before stopping the system.
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
18 */
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
19
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
20 #define FOR_reboot
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
21 #include "toys.h"
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
22 #include <sys/reboot.h>
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
23
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
24 void reboot_main(void)
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
25 {
1093
e1d3a9ac9e9f Minor cleanup of reboot
Rob Landley <rob@landley.net>
parents: 1092
diff changeset
26 int types[] = {RB_AUTOBOOT, RB_HALT_SYSTEM, RB_POWER_OFF};
1092
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
27
1093
e1d3a9ac9e9f Minor cleanup of reboot
Rob Landley <rob@landley.net>
parents: 1092
diff changeset
28 if (!(toys.optflags & FLAG_n)) sync();
e1d3a9ac9e9f Minor cleanup of reboot
Rob Landley <rob@landley.net>
parents: 1092
diff changeset
29
e1d3a9ac9e9f Minor cleanup of reboot
Rob Landley <rob@landley.net>
parents: 1092
diff changeset
30 toys.exitval = reboot(types[stridx("hp", *toys.which->name)+1]);
1092
1a5c7092afbf New toy: reboot/halt/poweroff
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
31 }