aboutsummaryrefslogtreecommitdiff
path: root/libbb/find_pid_by_name.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-06-26 22:44:09 +0000
committerEric Andersen <andersen@codepoet.org>2001-06-26 22:44:09 +0000
commit91a6318d555eb96f48fb8c134d5499d2f61670a0 (patch)
tree05c79e83a0a31bfb96a3b06904dae4410a20ea65 /libbb/find_pid_by_name.c
parent5ef5614c31d26a87d9d92e97bed7df7993296682 (diff)
downloadbusybox-w32-91a6318d555eb96f48fb8c134d5499d2f61670a0.tar.gz
busybox-w32-91a6318d555eb96f48fb8c134d5499d2f61670a0.tar.bz2
busybox-w32-91a6318d555eb96f48fb8c134d5499d2f61670a0.zip
Make it so we don't segfault when /proc isn't mounted -- guess pid 1...
-Erik
Diffstat (limited to 'libbb/find_pid_by_name.c')
-rw-r--r--libbb/find_pid_by_name.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c
index ea1cba65b..f335e9c1f 100644
--- a/libbb/find_pid_by_name.c
+++ b/libbb/find_pid_by_name.c
@@ -137,6 +137,10 @@ extern pid_t* find_pid_by_name( char* pidName)
137 char buffer[READ_BUF_SIZE]; 137 char buffer[READ_BUF_SIZE];
138 char name[READ_BUF_SIZE]; 138 char name[READ_BUF_SIZE];
139 139
140 /* Must skip ".." since that is outside /proc */
141 if (strcmp(next->d_name, "..") == 0)
142 continue;
143
140 /* If it isn't a number, we don't want it */ 144 /* If it isn't a number, we don't want it */
141 if (!isdigit(*next->d_name)) 145 if (!isdigit(*next->d_name))
142 continue; 146 continue;
@@ -161,6 +165,11 @@ extern pid_t* find_pid_by_name( char* pidName)
161 165
162 if (pidList) 166 if (pidList)
163 pidList[i]=0; 167 pidList[i]=0;
168 else {
169 /* If we found nothing, guess PID 1 and call it good */
170 pidList=xrealloc( pidList, sizeof(pid_t));
171 pidList[0]=1;
172 }
164 return pidList; 173 return pidList;
165} 174}
166#endif /* BB_FEATURE_USE_DEVPS_PATCH */ 175#endif /* BB_FEATURE_USE_DEVPS_PATCH */