RE: [PATCH v3 3/4] lslocks: new command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Davidlohr Bueso wrote:


> +static char *get_cmdname(pid_t pid)
> +{
> +	FILE *fp;
> +	char path[PATH_MAX];
> +
> +	sprintf(path, "/proc/%d/comm", pid);
> +	if (!(fp = fopen(path, "r")))
> +		return NULL;
> +
> +	/* just need the first line */
> +	if (!fgets(path, sizeof(path), fp))
> +		goto out;
> +out:

this looks strange to me:
if fgets fails, then we want to ...

> +	fclose(fp);

... but certainly not this:

> +	path[strlen(path) - 1] = '\0';
> +	return xstrdup(path);
> +}

Have a nice day,
Berny
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux