Merge branch 'master' into 'master'
Fix readlink anomalies Noticed minor readlink issues in pidof.c and pwdx.c. I have fixed them in two separate commits, please see the commit messages for their specific descriptions. See merge request !5
This commit is contained in:
commit
3178eb54fc
10
pidof.c
10
pidof.c
@ -103,20 +103,18 @@ static char *pid_link (pid_t pid, const char *base_name)
|
|||||||
{
|
{
|
||||||
char link [PROCPATHLEN];
|
char link [PROCPATHLEN];
|
||||||
char *result;
|
char *result;
|
||||||
int path_alloc_size;
|
ssize_t path_alloc_size;
|
||||||
int len;
|
ssize_t len;
|
||||||
|
|
||||||
snprintf(link, sizeof(link), "/proc/%d/%s", pid, base_name);
|
snprintf(link, sizeof(link), "/proc/%d/%s", pid, base_name);
|
||||||
|
|
||||||
len = path_alloc_size = 0;
|
len = path_alloc_size = 0;
|
||||||
result = NULL;
|
result = NULL;
|
||||||
do {
|
do {
|
||||||
if (len == path_alloc_size) {
|
|
||||||
grow_size(path_alloc_size);
|
grow_size(path_alloc_size);
|
||||||
result = (char *) xrealloc (result, path_alloc_size);
|
result = xrealloc(result, path_alloc_size);
|
||||||
}
|
|
||||||
|
|
||||||
if ((len = readlink(link, result, path_alloc_size - 1)) < 0) {
|
if ((len = readlink(link, result, path_alloc_size)) < 0) {
|
||||||
len = 0;
|
len = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
6
pwdx.c
6
pwdx.c
@ -65,7 +65,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
int retval = 0, i;
|
int retval = 0, i;
|
||||||
int alloclen = 128;
|
ssize_t alloclen = 128;
|
||||||
char *pathbuf;
|
char *pathbuf;
|
||||||
|
|
||||||
static const struct option longopts[] = {
|
static const struct option longopts[] = {
|
||||||
@ -99,7 +99,7 @@ int main(int argc, char *argv[])
|
|||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
usage(stderr);
|
usage(stderr);
|
||||||
|
|
||||||
pathbuf = malloc(alloclen);
|
pathbuf = xmalloc(alloclen);
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
char *s;
|
char *s;
|
||||||
@ -128,7 +128,7 @@ int main(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
while ((len = readlink(buf, pathbuf, alloclen)) == alloclen) {
|
while ((len = readlink(buf, pathbuf, alloclen)) == alloclen) {
|
||||||
alloclen *= 2;
|
alloclen *= 2;
|
||||||
pathbuf = realloc(pathbuf, alloclen);
|
pathbuf = xrealloc(pathbuf, alloclen);
|
||||||
}
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user