int reboot_now(void) { /* We need to sleep for just a little to allow the CGI's to finish */ sleep(1); /* Don't kill ourself */ signal(SIGTERM,SIG_IGN); signal(SIGHUP,SIG_IGN); setpgrp(); sync(); /* Send signals to every process _except_ pid 1 */ kill(-1, SIGTERM); sleep(1); sync(); kill(-1, SIGKILL); sleep(1); sync(); #if !defined(__UC_LIBC__) && (LINUX_VERSION_CODE <= KERNEL_VERSION(2,2,11)) { extern int bdflush(int func, long data); /* bdflush, kupdate not needed for kernels >2.2.11 */ bdflush(1, 0); sync(); } #endif init_reboot(RB_AUTOBOOT); return(-1); /* Shrug */ }
extern int update_main(int argc, char **argv) { int pid; int opt; while ((opt = getopt(argc, argv, "Ss:f:")) > 0) { switch (opt) { case 'S': use_sync = 1; break; case 's': sync_duration = atoi(optarg); break; case 'f': flush_duration = atoi(optarg); break; default: bb_show_usage(); } } if (daemon(0, 1) < 0) bb_perror_msg_and_die("daemon"); #ifdef OPEN_MAX for (pid = 0; pid < OPEN_MAX; pid++) close(pid); #else /* glibc 2.1.92 requires using sysconf(_SC_OPEN_MAX) */ for (pid = 0; pid < sysconf(_SC_OPEN_MAX); pid++) close(pid); #endif /* This is no longer necessary since 1.3.5x, but it will harmlessly * exit if that is the case. */ /* set the program name that will show up in a 'ps' listing */ argv[0] = "bdflush (update)"; argv[1] = NULL; argv[2] = NULL; for (;;) { if (use_sync) { sleep(sync_duration); sync(); } else { sleep(flush_duration); if (bdflush(1, 0) < 0) { openlog("update", LOG_CONS, LOG_DAEMON); syslog(LOG_INFO, "This kernel does not need update(8). Exiting."); closelog(); return EXIT_SUCCESS; } } } return EXIT_SUCCESS; }
int reboot_now(void) { /** * Write the current date/time to the RTC */ #ifdef CONFIG_USER_HWCLOCK_HWCLOCK system("hwclock --systohc --utc"); #elif defined(CONFIG_USER_RTC_M41T11) || defined (CONFIG_USER_RTC_DS1302) system("rtc -w"); #else /* We need to sleep for just a little to allow the CGI's to finish * The RTC commands above already take a little while, so * only sleep if we don't have any RTC command to run */ sleep(1); #endif /* Don't kill ourself */ signal(SIGTERM,SIG_IGN); signal(SIGHUP,SIG_IGN); setpgrp(); sync(); #ifdef CONFIG_USER_INIT_INIT /* Stop init from respawning daemons */ kill(1, SIGTSTP); #endif /* Send signals to every process _except_ pid 1 */ kill(-1, SIGTERM); sleep(1); sync(); kill(-1, SIGKILL); sleep(1); #if defined(CONFIG_USER_MOUNT_UMOUNT) || defined (CONFIG_USER_BUSYBOX_UMOUNT) system("/bin/umount -a -r"); #endif sync(); #if !defined(__UC_LIBC__) && (LINUX_VERSION_CODE <= KERNEL_VERSION(2,2,11)) { extern int bdflush(int func, long data); /* bdflush, kupdate not needed for kernels >2.2.11 */ bdflush(1, 0); sync(); } #endif init_reboot(RB_AUTOBOOT); return(-1); /* Shrug */ }
static int shutdown_now(int rb_which) { /** * Save us some entropy over this event */ logd("entropy", NULL); /** * Write the current date/time to the RTC */ #ifdef CONFIG_USER_HWCLOCK_HWCLOCK system("hwclock --systohc --utc"); #elif defined(CONFIG_USER_RTC_M41T11) || defined (CONFIG_USER_RTC_DS1302) system("rtc -w"); #else /* We need to sleep for just a little to allow the CGI's to finish * The RTC commands above already take a little while, so * only sleep if we don't have any RTC command to run */ sleep(1); #endif /* Don't kill ourself */ signal(SIGTERM,SIG_IGN); signal(SIGHUP,SIG_IGN); setpgrp(); sync(); #ifdef CONFIG_USER_INIT_INIT /* Stop init from respawning daemons */ kill(1, SIGTSTP); #endif /* Send signals to every process _except_ pid 1 */ kill(-1, SIGTERM); sleep(1); sync(); kill(-1, SIGKILL); sleep(1); #if defined(CONFIG_USER_MOUNT_UMOUNT) || defined (CONFIG_USER_BUSYBOX_UMOUNT) system("/bin/umount -a -r"); #endif sync(); #if !defined(__UC_LIBC__) && (LINUX_VERSION_CODE <= KERNEL_VERSION(2,2,11)) { extern int bdflush(int func, long data); /* bdflush, kupdate not needed for kernels >2.2.11 */ bdflush(1, 0); sync(); } #endif #ifdef CONFIG_LEDMAN /* We want to turn off all LEDs, except the POWER LED, * so it is clear that we are shut down. Enable the ALT functionality * for the POWER LED and then turn all std LEDs off. */ ledman_cmd(LEDMAN_CMD_ALT_ON, LEDMAN_POWER); ledman_cmd(LEDMAN_CMD_ON | LEDMAN_CMD_ALTBIT, LEDMAN_POWER); ledman_cmd(LEDMAN_CMD_OFF, LEDMAN_ALL); #endif #ifdef CONFIG_SNAPDOG /* Turn off user servicing of the watchdog */ write(open("/dev/watchdog", O_WRONLY), "V", 1); #endif init_reboot(rb_which); return -1; /* Shrug */ }
extern int reboot_main(int argc, char **argv) { int delay = 0; /* delay in seconds before rebooting */ int rc; while ((rc = getopt(argc, argv, "d:")) > 0) { switch (rc) { case 'd': delay = atoi(optarg); break; default: show_usage(); break; } } if(delay > 0) sleep(delay); #ifdef CONFIG_USER_INIT_INIT /* Don't kill ourself */ signal(SIGTERM,SIG_IGN); signal(SIGHUP,SIG_IGN); setpgrp(); /* Allow Ctrl-Alt-Del to reboot system. */ init_reboot(RB_ENABLE_CAD); message("\n\rThe system is going down NOW !!\n"); sync(); /* Send signals to every process _except_ pid 1 */ message("\rSending SIGTERM to all processes.\n"); kill(-1, SIGTERM); sleep(1); sync(); message("\rSending SIGKILL to all processes.\n"); kill(-1, SIGKILL); sleep(1); sync(); if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,2,11)) { /* bdflush, kupdate not needed for kernels >2.2.11 */ bdflush(1, 0); sync(); } init_reboot(RB_AUTOBOOT); exit(0); /* Shrug */ #else #ifdef BB_FEATURE_LINUXRC { /* don't assume init's pid == 1 */ long *pid = find_pid_by_name("init"); if (!pid || *pid<=0) pid = find_pid_by_name("linuxrc"); if (!pid || *pid<=0) error_msg_and_die("no process killed"); fflush(stdout); return(kill(*pid, SIGTERM)); } #else // yachen *(unsigned int volatile *)(0xfff8101c) = 0x82; return(kill(1, SIGTERM)); #endif #endif }