aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Beppu <beppu@lbox.org>1999-12-09 22:10:18 +0000
committerJohn Beppu <beppu@lbox.org>1999-12-09 22:10:18 +0000
commitf95ca97d1bb94307ee0b8ed95d329dc9d6ccec85 (patch)
treec494de94d27e7d8dc8fdd43b1ca8fe6710e15eda
parent395b216a2eb70ea2796556c06be01261de993687 (diff)
downloadbusybox-w32-f95ca97d1bb94307ee0b8ed95d329dc9d6ccec85.tar.gz
busybox-w32-f95ca97d1bb94307ee0b8ed95d329dc9d6ccec85.tar.bz2
busybox-w32-f95ca97d1bb94307ee0b8ed95d329dc9d6ccec85.zip
findInitPid() has been implemented and it seems to work.
reboot has been changed to take advantage of findInitPid();
-rw-r--r--init/reboot.c3
-rw-r--r--internal.h1
-rw-r--r--reboot.c3
-rw-r--r--utility.c43
4 files changed, 39 insertions, 11 deletions
diff --git a/init/reboot.c b/init/reboot.c
index 53a3520e1..17ec9f82f 100644
--- a/init/reboot.c
+++ b/init/reboot.c
@@ -26,5 +26,6 @@
26extern int 26extern int
27reboot_main(int argc, char ** argv) 27reboot_main(int argc, char ** argv)
28{ 28{
29 exit( kill(1, SIGUSR2)); 29 /* don't assume init's pid == 1 */
30 exit( kill(findInitPid(), SIGUSR2));
30} 31}
diff --git a/internal.h b/internal.h
index 830d30eb4..de13bb202 100644
--- a/internal.h
+++ b/internal.h
@@ -157,6 +157,7 @@ extern void write_mtab(char* blockDevice, char* directory,
157extern void erase_mtab(const char * name); 157extern void erase_mtab(const char * name);
158extern int check_wildcard_match(const char* text, const char* pattern); 158extern int check_wildcard_match(const char* text, const char* pattern);
159extern long getNum (const char *cp); 159extern long getNum (const char *cp);
160extern pid_t findInitPid();
160 161
161 162
162#if defined BB_MTAB 163#if defined BB_MTAB
diff --git a/reboot.c b/reboot.c
index 53a3520e1..17ec9f82f 100644
--- a/reboot.c
+++ b/reboot.c
@@ -26,5 +26,6 @@
26extern int 26extern int
27reboot_main(int argc, char ** argv) 27reboot_main(int argc, char ** argv)
28{ 28{
29 exit( kill(1, SIGUSR2)); 29 /* don't assume init's pid == 1 */
30 exit( kill(findInitPid(), SIGUSR2));
30} 31}
diff --git a/utility.c b/utility.c
index de7a0fbfc..42ee00c50 100644
--- a/utility.c
+++ b/utility.c
@@ -1068,14 +1068,39 @@ extern long getNum (const char *cp)
1068} 1068}
1069#endif 1069#endif
1070 1070
1071#if 1
1072/* findInitPid()
1073 *
1074 * This finds the pid of init (which is not always 1).
1075 * Currently, it's implemented by rummaging through the proc filesystem.
1076 *
1077 * [return]
1078 * 0 failure
1079 * pid when init's pid is found.
1080 */
1081extern pid_t
1082findInitPid()
1083{
1084 pid_t init_pid;
1085 char filename[256];
1086 char buffer[256];
1087
1088 /* no need to opendir ;) */
1089 for (init_pid = 1; init_pid < 65536; init_pid++) {
1090 FILE *status;
1091
1092 sprintf(filename, "/proc/%d/status", init_pid);
1093 status = fopen(filename, "r");
1094 if (!status) { continue; }
1095 fgets(buffer, 256, status);
1096 fclose(status);
1097
1098 if ( (strcmp(&buffer[6], "init\n") == 0)) {
1099 return init_pid;
1100 }
1101 }
1102 return 0;
1103}
1104#endif
1071 1105
1072/* END CODE */ 1106/* END CODE */
1073
1074
1075
1076
1077
1078
1079
1080
1081