diff options
author | beppu <beppu@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 1999-12-09 22:10:18 +0000 |
---|---|---|
committer | beppu <beppu@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 1999-12-09 22:10:18 +0000 |
commit | 2bbcec81a7457a36d3f83747d67f0a2e8ab90fcb (patch) | |
tree | c494de94d27e7d8dc8fdd43b1ca8fe6710e15eda /utility.c | |
parent | 66f7666802a4e4209f9201f47302401579d99615 (diff) | |
download | busybox-w32-2bbcec81a7457a36d3f83747d67f0a2e8ab90fcb.tar.gz busybox-w32-2bbcec81a7457a36d3f83747d67f0a2e8ab90fcb.tar.bz2 busybox-w32-2bbcec81a7457a36d3f83747d67f0a2e8ab90fcb.zip |
findInitPid() has been implemented and it seems to work.
reboot has been changed to take advantage of findInitPid();
git-svn-id: svn://busybox.net/trunk/busybox@184 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to '')
-rw-r--r-- | utility.c | 43 |
1 files changed, 34 insertions, 9 deletions
@@ -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 | */ | ||
1081 | extern pid_t | ||
1082 | findInitPid() | ||
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 | |||