pmap: Don't reopen stdin for reading file
pmap uses freopen to read /proc/self/maps. There doesn't seem to be a good reason to do this and if pmap has its stdin previously closed then it fails. Signed-off-by: Craig Small <csmall@dropbear.xyz>
This commit is contained in:
parent
581ed4bcab
commit
1f085f5a9f
1
NEWS
1
NEWS
@ -1,6 +1,7 @@
|
|||||||
procps-ng-NEXT
|
procps-ng-NEXT
|
||||||
* library
|
* library
|
||||||
Re-add elogind support merge #151
|
Re-add elogind support merge #151
|
||||||
|
* pmap: Dont reuse stdin filehandle issue #231
|
||||||
* ps: threads again display when -L is used with -q issue #234
|
* ps: threads again display when -L is used with -q issue #234
|
||||||
* ps: proper aix format string behavior was restored
|
* ps: proper aix format string behavior was restored
|
||||||
* sysctl: print dotted keys again
|
* sysctl: print dotted keys again
|
||||||
|
9
pmap.c
9
pmap.c
@ -158,21 +158,25 @@ static void discover_shm_minor(void)
|
|||||||
void *addr;
|
void *addr;
|
||||||
int shmid;
|
int shmid;
|
||||||
char mapbuf_b[256];
|
char mapbuf_b[256];
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
if (!freopen("/proc/self/maps", "r", stdin))
|
if ( (fp = fopen("/proc/self/maps", "r")) == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* create */
|
/* create */
|
||||||
shmid = shmget(IPC_PRIVATE, 42, IPC_CREAT | 0666);
|
shmid = shmget(IPC_PRIVATE, 42, IPC_CREAT | 0666);
|
||||||
if (shmid == -1)
|
if (shmid == -1)
|
||||||
|
{
|
||||||
/* failed; oh well */
|
/* failed; oh well */
|
||||||
|
fclose(fp);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
/* attach */
|
/* attach */
|
||||||
addr = shmat(shmid, NULL, SHM_RDONLY);
|
addr = shmat(shmid, NULL, SHM_RDONLY);
|
||||||
if (addr == (void *)-1)
|
if (addr == (void *)-1)
|
||||||
goto out_destroy;
|
goto out_destroy;
|
||||||
|
|
||||||
while (fgets(mapbuf_b, sizeof mapbuf_b, stdin)) {
|
while (fgets(mapbuf_b, sizeof mapbuf_b, fp)) {
|
||||||
char perms[32];
|
char perms[32];
|
||||||
/* to clean up unprintables */
|
/* to clean up unprintables */
|
||||||
char *tmp;
|
char *tmp;
|
||||||
@ -207,6 +211,7 @@ static void discover_shm_minor(void)
|
|||||||
perror(_("shared memory detach"));
|
perror(_("shared memory detach"));
|
||||||
|
|
||||||
out_destroy:
|
out_destroy:
|
||||||
|
fclose(fp);
|
||||||
if (shmctl(shmid, IPC_RMID, NULL) && errno != EINVAL)
|
if (shmctl(shmid, IPC_RMID, NULL) && errno != EINVAL)
|
||||||
perror(_("shared memory remove"));
|
perror(_("shared memory remove"));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user