mirror of
https://github.com/troglobit/finit.git
synced 2026-11-10 16:31:21 +00:00
Fix pid_get_name() when NULL buffer is provided.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
2cba0c73be
commit
fa89370517
1 file changed
+6
-8
@@ -245,19 +245,17 @@ char *pid_get_name(pid_t pid, char *name, size_t len)
|
|||||||
{
|
{
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char path[32];
|
char *pname, path[32];
|
||||||
static char line[64];
|
static char line[64];
|
||||||
|
|
||||||
if (!name || len == 0)
|
|
||||||
name = line;
|
|
||||||
|
|
||||||
snprintf(path, sizeof(path), "/proc/%d/status", pid);
|
snprintf(path, sizeof(path), "/proc/%d/status", pid);
|
||||||
if ((fp = fopen(path, "r")) != NULL) {
|
fp = fopen(path, "r");
|
||||||
|
if (fp) {
|
||||||
if (fgets(line, sizeof (line), fp)) {
|
if (fgets(line, sizeof (line), fp)) {
|
||||||
char *pname = line + 6; /* Skip first part of line --> "Name:\t" */
|
pname = line + 6; /* Skip first part of line --> "Name:\t" */
|
||||||
|
|
||||||
chomp(pname);
|
chomp(pname);
|
||||||
strlcpy(name, pname, len);
|
if (name)
|
||||||
|
strlcpy(name, pname, len);
|
||||||
ret = 0; /* Found it! */
|
ret = 0; /* Found it! */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user