Fix the halt/reboot/poweroff segfault when used from within an initrd...
-Erik
This commit is contained in:
parent
131241f71c
commit
31e6829bd8
18
utility.c
18
utility.c
@ -1360,14 +1360,12 @@ extern pid_t* findPidByName( char* pidName)
|
|||||||
FILE *status;
|
FILE *status;
|
||||||
char filename[256];
|
char filename[256];
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
char* p;
|
|
||||||
|
|
||||||
/* If it isn't a number, we don't want it */
|
/* If it isn't a number, we don't want it */
|
||||||
if (!isdigit(*next->d_name))
|
if (!isdigit(*next->d_name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Now open the status file */
|
sprintf(filename, "/proc/%s/cmdline", next->d_name);
|
||||||
sprintf(filename, "/proc/%s/status", next->d_name);
|
|
||||||
status = fopen(filename, "r");
|
status = fopen(filename, "r");
|
||||||
if (!status) {
|
if (!status) {
|
||||||
continue;
|
continue;
|
||||||
@ -1375,22 +1373,12 @@ extern pid_t* findPidByName( char* pidName)
|
|||||||
fgets(buffer, 256, status);
|
fgets(buffer, 256, status);
|
||||||
fclose(status);
|
fclose(status);
|
||||||
|
|
||||||
/* Make sure we only match on the process name */
|
if (strstr(get_last_path_component(buffer), pidName) != NULL) {
|
||||||
p=buffer+5; /* Skip the name */
|
|
||||||
while ((p)++) {
|
|
||||||
if (*p==0 || *p=='\n') {
|
|
||||||
*p='\0';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p=buffer+6; /* Skip the "Name:\t" */
|
|
||||||
|
|
||||||
if ((strstr(p, pidName) != NULL)
|
|
||||||
&& (strlen(pidName) == strlen(p))) {
|
|
||||||
pidList=xrealloc( pidList, sizeof(pid_t) * (i+2));
|
pidList=xrealloc( pidList, sizeof(pid_t) * (i+2));
|
||||||
pidList[i++]=strtol(next->d_name, NULL, 0);
|
pidList[i++]=strtol(next->d_name, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pidList)
|
if (pidList)
|
||||||
pidList[i]=0;
|
pidList[i]=0;
|
||||||
return pidList;
|
return pidList;
|
||||||
|
Loading…
Reference in New Issue
Block a user