blob: c4c3ab0500be3623ff00dc9f4d5b6cab8b92d34e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#include <lha_internal.h>
#include <clplumbing/cl_reboot.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SYS_REBOOT_H
# include <sys/reboot.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#include <clplumbing/cl_log.h>
#include <clplumbing/timers.h>
enum rebootopt {
REBOOT_DEFAULT = 0,
REBOOT_NOCOREDUMP = 1,
REBOOT_COREDUMP = 2,
};
static enum rebootopt coredump = REBOOT_DEFAULT;
void
cl_enable_coredump_before_reboot(gboolean yesno)
{
coredump = (yesno ? REBOOT_COREDUMP : REBOOT_NOCOREDUMP);
}
void cl_reboot(int msdelaybeforereboot, const char * reason)
{
int rebootflag = 0;
int systemrc = 0;
#ifdef RB_AUTOBOOT
rebootflag = RB_AUTOBOOT;
#endif
#ifdef RB_NOSYNC
rebootflag = RB_NOSYNC;
#endif
#ifdef RB_DUMP
if (coredump == REBOOT_COREDUMP) {
rebootflag = RB_DUMP;
}
#endif
cl_log(LOG_EMERG, "Rebooting system. Reason: %s", reason);
sync();
mssleep(msdelaybeforereboot);
#if REBOOT_ARGS == 1
reboot(rebootflag);
#elif REBOOT_ARGS == 2
reboot(rebootflag, NULL);
#else
#error "reboot() call needs to take one or two args"
#endif
/* Shouldn't ever get here, but just in case... */
systemrc=system(REBOOT " " REBOOT_OPTIONS);
cl_log(LOG_EMERG, "ALL REBOOT OPTIONS FAILED: %s returned %d"
, REBOOT " " REBOOT_OPTIONS, systemrc);
exit(1);
}
|