Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
sunos: don't use fopen()
Browse files Browse the repository at this point in the history
FILE uses an unsigned char to store the file descriptor so it cannot handle
situations where there are more than 256 open file descriptors.
  • Loading branch information
bnoordhuis committed Mar 31, 2012
1 parent 1ab8f5a commit 4632163
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/unix/sunos.c
Expand Up @@ -37,6 +37,7 @@
#include <sys/time.h>
#include <unistd.h>
#include <kstat.h>
#include <fcntl.h>

#if HAVE_PORTS_FS
# include <sys/port.h>
Expand Down Expand Up @@ -239,28 +240,24 @@ uv_err_t uv_get_process_title(char* buffer, size_t size) {


uv_err_t uv_resident_set_memory(size_t* rss) {
pid_t pid = getpid();
psinfo_t psinfo;
char pidpath[1024];
FILE *f;
uv_err_t err;
int fd;

sprintf(pidpath, "/proc/%d/psinfo", (int)pid);

f = fopen(pidpath, "r");
if (!f) return uv__new_sys_error(errno);

if (fread(&psinfo, sizeof(psinfo_t), 1, f) != 1) {
fclose (f);
fd = open("/proc/self/psinfo", O_RDONLY);
if (fd == -1)
return uv__new_sys_error(errno);
}

/* XXX correct? */
err = uv_ok_;

*rss = (size_t) psinfo.pr_rssize * 1024;
if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo))
*rss = (size_t)psinfo.pr_rssize * 1024;
else
err = uv__new_sys_error(EINVAL);

fclose (f);
close(fd);

return uv_ok_;
return err;
}


Expand Down

0 comments on commit 4632163

Please sign in to comment.