diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c index 785805d4dc..14a96eb094 100644 --- a/psutil/_psutil_sunos.c +++ b/psutil/_psutil_sunos.c @@ -114,6 +114,240 @@ psutil_proc_basic_info(PyObject *self, PyObject *args) { ); } +static int +open_address_space(pid_t pid, const char *procfs_path) { + int fd; + char proc_path[PATH_MAX]; + + sprintf(proc_path, "%s/%i/as", procfs_path, pid); + fd = open(proc_path, O_RDONLY); + if (fd < 0) + PyErr_SetFromErrno(PyExc_OSError); + + return fd; +} + +static int +read_offt(int fd, off_t offset, char *buf, size_t buf_size) { + size_t to_read = buf_size; + size_t stored = 0; + + while (to_read) { + int r = pread(fd, buf + stored, to_read, offset + stored); + if (r < 0) { + PyErr_SetFromErrno(PyExc_OSError); + return -errno; + } + + to_read -= r; + stored += r; + } + + return stored; +} + +#define STRING_SEARCH_BUF_SIZE 512 + +static char * +read_cstring_offt(int fd, off_t offset) { + int r; + int i; + off_t end; + size_t len; + char buf[STRING_SEARCH_BUF_SIZE]; + char *result = NULL; + + if (lseek(fd, offset, SEEK_SET) == (off_t)-1) { + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + + // Search end of string + end = offset; + for (;; end += STRING_SEARCH_BUF_SIZE) { + r = read(fd, buf, sizeof(buf)); + + if (r == -1) { + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + else if (r == 0) { + break; + } + else { + for (i=0; itcp6ConnCreationProcess; #else - processed_pid = 0; + processed_pid = 0; #endif if (pid != -1 && processed_pid != pid) continue; @@ -1163,7 +1417,7 @@ psutil_net_connections(PyObject *self, PyObject *args) { else if (mibhdr->level == MIB2_UDP || mibhdr->level == MIB2_UDP_ENTRY) { ude = (mib2_udpEntry_t *)databuf.buf; num_ent = mibhdr->len / sizeof(mib2_udpEntry_t); - assert(num_ent * sizeof(mib2_udpEntry_t) == mibhdr->len); + assert(num_ent * sizeof(mib2_udpEntry_t) == mibhdr->len); for (i = 0; i < num_ent; i++, ude++) { #ifdef NEW_MIB_COMPLIANT processed_pid = ude->udpCreationProcess;