|
Lines 8-13
Link Here
|
| 8 |
#include <time.h> |
8 |
#include <time.h> |
| 9 |
#include <fcntl.h> |
9 |
#include <fcntl.h> |
| 10 |
#include <mntent.h> |
10 |
#include <mntent.h> |
|
|
11 |
#include <termios.h> |
| 11 |
|
12 |
|
| 12 |
#include <sys/reboot.h> |
13 |
#include <sys/reboot.h> |
| 13 |
#include <sys/mount.h> |
14 |
#include <sys/mount.h> |
|
Lines 130-141
Link Here
|
| 130 |
break; |
131 |
break; |
| 131 |
} |
132 |
} |
| 132 |
|
133 |
|
|
|
134 |
int |
| 135 |
linux_kbhit(void) |
| 136 |
{ |
| 137 |
struct termios oldstuff; |
| 138 |
struct termios newstuff; |
| 139 |
struct timeval tv = {0,1}; /* set one microsecond timeout */ |
| 140 |
fd_set rdfds; |
| 141 |
int fd = fileno(stdin); /* is usually zero */ |
| 142 |
int retval; |
| 143 |
|
| 144 |
FD_ZERO(&rdfds); |
| 145 |
FD_SET(fd, &rdfds); |
| 146 |
|
| 147 |
tcgetattr(fd, &oldstuff); |
| 148 |
newstuff = oldstuff; /* save old attributes */ |
| 149 |
|
| 150 |
newstuff.c_lflag &= ~(ICANON | ECHO | IGNBRK); |
| 151 |
|
| 152 |
tcsetattr(fd, TCSANOW, &newstuff); /* set new attributes */ |
| 153 |
|
| 154 |
if (select(fd + 1, &rdfds, NULL, NULL, &tv) == -1) { |
| 155 |
perror("select"); |
| 156 |
exit(1); |
| 157 |
} |
| 158 |
if (FD_ISSET(fd, &rdfds)) { |
| 159 |
retval = 1; |
| 160 |
} |
| 161 |
else { |
| 162 |
retval = 0; |
| 163 |
} |
| 164 |
|
| 165 |
tcsetattr(fd, TCSANOW, &oldstuff); /* restore old attributes */ |
| 166 |
|
| 167 |
return retval; |
| 168 |
} |
| 169 |
|
| 133 |
static void |
170 |
static void |
| 134 |
countdown(void) |
171 |
countdown(void) |
| 135 |
{ |
172 |
{ |
| 136 |
int i; |
173 |
int i; |
| 137 |
|
174 |
|
| 138 |
fprintf(stderr, "%s", "\nYou may safely reboot your system\n"); |
175 |
fprintf(stderr, "%s", "\nYou may safely reboot your system\n"); |
|
|
176 |
fprintf(stderr, "%s", "Press any key to reboot\n"); |
| 139 |
fflush(stderr); |
177 |
fflush(stderr); |
| 140 |
|
178 |
|
| 141 |
/* Set countdown when METHOD = cdrom */ |
179 |
/* Set countdown when METHOD = cdrom */ |
|
Lines 143-148
Link Here
|
| 143 |
{ |
181 |
{ |
| 144 |
for (i = REBOOT_TIMEOUT; i > 0; --i) |
182 |
for (i = REBOOT_TIMEOUT; i > 0; --i) |
| 145 |
{ |
183 |
{ |
|
|
184 |
if (linux_kbhit()) |
| 185 |
break; |
| 186 |
|
| 146 |
fprintf(stderr, |
187 |
fprintf(stderr, |
| 147 |
"\rAutomatic reboot after %d seconds... ", i); |
188 |
"\rAutomatic reboot after %d seconds... ", i); |
| 148 |
fflush(stderr); |
189 |
fflush(stderr); |
|
Lines 153-158
Link Here
|
| 153 |
fflush(stderr); |
194 |
fflush(stderr); |
| 154 |
} |
195 |
} |
| 155 |
|
196 |
|
|
|
197 |
|
| 198 |
|
| 156 |
static void |
199 |
static void |
| 157 |
killall(void) |
200 |
killall(void) |
| 158 |
{ |
201 |
{ |