static status_t s_route(alsa_handle_t *handle, uint32_t devices, int mode) { LOGD("route called for devices %08x in mode %d...", devices, mode); if (handle->handle && handle->curDev == devices && handle->curMode == mode) return NO_ERROR; return s_open(handle, devices, mode); }
ByteArrayInputStream::ByteArrayInputStream(char* dd,int oo,int ss) { // p_open=s_open; p_close=s_close; p_read=s_read; p_reset=s_reset; p_dup=s_dup; p_skip=s_skip; handle=s_open(((char*)dd)+oo,ss); }
extern int s_validate(char *name, tcconf_section_t *cs) { muxed_stream_t *ms = s_open(name, cs, NULL); tcvp_packet_t *pk; int i; if(!ms) return -1; for(i = 0; i < ms->n_streams; i++) ms->used_streams[i] = 1; while((pk = ms->next_packet(ms, -1))) tcfree(pk); tcfree(ms); return 0; }
void CFtpDialog::ListDirectory() { if (fSocket < 0) { beep(); return; } for (int i = fListView->CountItems() - 1; i >= 0; i--) delete fListView->RemoveItem(i); int data = 0; try { struct sockaddr_in saData; struct sockaddr_in saCmd; data = socket(AF_INET, SOCK_STREAM, 0); if (data < 0) THROW(("Failed to get socket: %s", strerror(errno))); memset(&saData, 0, sizeof(saData)); saData.sin_family = AF_INET; socklen_t size = sizeof(saData); bool passive = IsOn("pssv"); if (passive) { // switch to passive mode s_printf(fSocketFD, "pasv\r\n"); } else { FailSockErr(bind(data, (struct sockaddr *)&saData, sizeof(saData))); FailSockErr(listen(data, 5)); // [zooey]: calling getsockname() on a socket that has been bound to // IN_ADDR_ANY (the wildcard-address) will *not* return any IP-address, // as this will only be setup by the system during connect or accept. // [refer to W.R. Stevens - Unix Network Programming, Vol 1, p. 92] // BeOS R5 however, *does* fill in the IP-address at this stage (that's // why this code worked for R5 but didn't work for BONE). // In order to fix this problem, we simply use the IP-address of the // command-socket for the PORT-command: // // fetch port from data-socket: FailSockErr(getsockname(data, (struct sockaddr *)&saData, &size)); unsigned char *pap = (unsigned char *)&saData.sin_port; // fetch ip-address from cmd-socket: FailSockErr(getsockname(fSocketFD->sSocket, (struct sockaddr *)&saCmd, &size)); unsigned char *sap = (unsigned char *)&saCmd.sin_addr.s_addr; // combine both into the PORT-command: s_printf(fSocketFD, "port %d,%d,%d,%d,%d,%d\r\n", sap[0], sap[1], sap[2], sap[3], pap[0], pap[1]); } int state = 1; SOCK* dsf = NULL; while (state) { GetReply(); switch (state) { case 1: if (passive) { unsigned int sap[4]; unsigned int pap[2]; if (*fReply != '2') THROW(("Pasv command failed: %s", fReply)); char* pos = strchr(fReply,'('); if (!pos) THROW(("Answer to Pasv has unknown format: %s", fReply)); int cnt = sscanf(pos+1, "%u,%u,%u,%u,%u,%u", &sap[0], &sap[1], &sap[2], &sap[3], &pap[0], &pap[1]); if (cnt != 6) THROW(("Could not parse answer to Pasv (%d of 6): %s", cnt, fReply)); char ipAddr[20]; sprintf(ipAddr, "%d.%d.%d.%d", sap[0], sap[1], sap[2], sap[3]); saData.sin_port = htons(pap[0]*256+pap[1]); saData.sin_addr.s_addr = inet_addr(ipAddr); FailOSErr(connect(data, (struct sockaddr *)&saData, sizeof(saData))); dsf = s_open(data, "r+"); } else { if (*fReply != '2') THROW(("Port command failed: %s", fReply)); } s_printf(fSocketFD, "list\r\n"); state = 2; break; case 2: if (*fReply == '1') { int ds = 0; if (!passive) { FailSockErr(ds = accept(data, (struct sockaddr *)&saData, &size)); dsf = s_open(ds, "r+"); } try { CFtpListItem *item; char s[256]; bool showAll = IsOn("dotf"); int entryCount = 0; while (s_gets(s, 256, dsf)) { entryCount++; item = new CFtpListItem(this, s); if (item->IsValid() && (showAll || !item->IsDotFile())) { fListView->AddItem(item); } else delete item; } if (entryCount == 0) THROW(("Could not get listing.")); fListView->Invalidate(); UpdateIfNeeded(); s_close(dsf); if (!passive) closesocket(ds); } catch (HErr& e) { EnableUpdates(); s_close(dsf); closesocket(ds); throw; } state = 3; } else THROW(("Failed to get listing: %s", fReply)); break; case 3: if (*fReply != '2') THROW(("Something went wrong fetching the directory listing")); state = 0; break; } } closesocket(data); } catch (HErr& e) { if (data) closesocket(data); e.DoError(); } } // CFtpDialog::ListDirectory
void CFtpDialog::Connect() { try { if (fSocket >= 0) { if (fSocketFD) s_close(fSocketFD); closesocket(fSocket); } fSocket = socket(AF_INET, SOCK_STREAM, 0); if (fSocket < 0) THROW(("Failed to get socket: %s", strerror(errno))); fSocketFD = s_open(fSocket, "r+"); FailNil(fSocketFD); SetDefaultButton(static_cast<BButton*>(FindView("ok "))); struct hostent *host; if ((host = gethostbyname(GetText("srvr"))) == NULL) { fServerName->MarkAsInvalid(true); THROW(("Failed to get server address: %s", strerror(errno))); } struct sockaddr_in sa; sa.sin_family = AF_INET; sa.sin_port = htons(21); sa.sin_addr.s_addr = *(unsigned int *)host->h_addr; if (connect(fSocket, (struct sockaddr *)&sa, sizeof(sa)) < 0) { if (!(errno == ECONNREFUSED || errno == ETIMEDOUT || errno == ENETUNREACH)) fServerName->MarkAsInvalid(true); THROW(("Failed to connect to the host: %s", strerror(errno))); } int state = 1; while (state) { GetReply(); switch (state) { case 1: if (*fReply != '2') THROW(("Connect failed: %s", fReply)); s_printf(fSocketFD, "user %s\r\n", GetText("user")); state = 2; break; case 2: if (*fReply == '3') { s_printf(fSocketFD, "pass %s\r\n", GetText("pass")); state = 3; break; } else if (*fReply != '2' && *fReply != '5') THROW(("Failed to login: %s", fReply)); // fall thru case 3: if (*fReply == '5') THROW(("Incorrect username/password.\n%s", fReply)); if (state == 3 && *fReply != '2') THROW(("Failed to login: %s", fReply)); state = 0; break; } } gPrefs->SetPrefString(prf_S_LastFtpUser, GetText("user")); gPrefs->SetPrefString(prf_S_LastFtpServer, GetText("srvr")); sfPassword = GetText("pass"); GetPWD(); } catch (HErr& e) { e.DoError(); s_close(fSocketFD); fSocketFD = NULL; closesocket(fSocket); fSocket = -1; SetDefaultButton(static_cast<BButton*>(FindView("cnct"))); } if (fSocketFD) ListDirectory(); } // CFtpDialog::Connect
int mbtransfer (char *ziel) //************************************************************************* // // TRANSFER-Prozedur // (wird fuer jedes transferierte File einzeln aufgerufen) // //************************************************************************* { char name[20]; strcpy(name, "mbtransfer"); lastfunc(name); char *line = b->line; int findex; FILE *oldf, *newf; char usermail = 0; int retwert = NO; int nocp; //no-copy flag char oldsubject[101]; unsigned long int oldfpos; char oldmsgty; char oldmailfname[10]; time_t oldmsgtime; char old_ziel[DIRLEN+1]; int old_usermail; char oldboardname[10]; char oldmailpath[FNAMELEN+1]; char zielcall[CALLEN+1]; char newcall[CALLEN+1]; int gleichesboard = NO; unsigned long nummer; #ifdef USERLT short int old_lt; #endif #ifdef DEBUG_FWD trace(report, "mbtransfer", "ziel: %s", ziel); #endif strupr(ziel); nexttoken(ziel, zielcall, CALLEN); strcpy(oldmailpath, b->mailpath); if (sema_test("sendlock") || m.disable) { putf(ms(m_sendnotpossible)); return NO; } if (mbcallok(zielcall)) { // Use newcall if (get_newcall(zielcall, newcall)) { strcpy(zielcall, newcall); putf(ms(m_usingnewcall), newcall); } } char *bbuf = (char *) t_malloc(sizeof(tvar_t) - sizeof(task_t), "tran"); char *oldfname; oldfname = (char *) t_malloc(sizeof(char) * (FNAMELEN+1), "tra2"); if (! bbuf || ! oldfname) return NO; memcpy(bbuf, (char *) b + sizeof(task_t), sizeof(tvar_t) - sizeof(task_t)); strlwr(b->mailpath); strcpy(oldfname, b->mailpath); strcpy(oldmailfname, b->mailfname); oldmsgtime = filename2time(b->mailfname); if ((oldf = s_fopen(oldfname, "srt")) != NULL) { fgets(b->line, BUFLEN - 1, oldf); // Befehlszeile einlesen mbsend_parse(line, 0); if (b->mailtype == 'A' || (b->mailtype == 'B' && b->eraseinfo == 'T')) { retwert = NIL; s_fclose(oldf); goto error_exit; } oldmsgty = b->conttype; // save mailflags ...(conttype) fgets(b->line, BUFLEN - 1, oldf); // Forwardzeile vernichten fgets(b->line, BUFLEN - 1, oldf); // Read-Zeile fgets(oldsubject, BETREFFLEN, oldf); // Betreff cut_blank(oldsubject); // Newline entfernen if (mbcallok(zielcall)) *b->at = 0; // Verteiler loeschen -> Neubestimmen strcpy(old_ziel, b->ziel); #ifdef USERLT old_lt = b->lifetime; b->lifetime = 0; #endif old_usermail = b->usermail; mbsend_parse(ziel, 2); if (! stricmp(b->ziel, b->mailpath+strlen(b->mailpath)-strlen(b->ziel)-8)) { retwert = NIL; s_fclose(oldf); goto error_exit; } b->conttype = oldmsgty; // set mailflags again.. (conttype) if (b->mailtype == 'B' && ! old_usermail) strcpy(b->ziel, old_ziel); weiterleiten(1, b->zielboard); waitfor(e_ticsfull); findex = finddir(b->zielboard, b->sysop); if (findex && !(strlen(b->zielboard)==1 && !b->sysop)) { if (xmkdir(b->boardpath)) { trace(serious, name, "mkdir %s error", b->boardpath); s_fclose(oldf); goto error_exit; } nocp = ! strcmp(b->herkunft, b->logincall) || b->sysop; //kein "CP " wenn Sysop! if (nocp || b->mailtype == 'B') strcpy(b->betreff, oldsubject); else sprintf(b->betreff, "CP %s: %.67s", b->logincall, oldsubject); //Bei Nicht-Bulletin BID neu generieren bzw. wenn BID fehlt if (b->mailtype != 'B'|| ! *b->bid) strcpy(b->bid, newbid()); make_mask(b->mailpath, b->boardfullname); strcpy(b->mask, b->mailpath); // Ursprungsboardnamen aus b->mailpath holen und mit ziel vergleichen strcpy(oldboardname, b->boardname); oldmailpath[strlen(oldmailpath)-8] = 0; if (finddir(oldmailpath,0) > 0) { if (! strcmp(ziel, b->boardname)) gleichesboard = YES; } else gleichesboard = NO; strcpy(b->boardname,oldboardname); // b->boardname wieder herstellen // bei Usermail oder gleichem Board zum Sortieren // Filezeit/-namen neu setzen if (mbcallok(zielcall) || gleichesboard) { strcpy(b->mailfname, time2filename(0)); } else strcpy(b->mailfname, oldmailfname); if (! strstr(b->mailpath, "*.*")) trace(fatal, name, "mask %s", b->mailpath); strcpy(strstr(b->mailpath, "*.*"), b->mailfname); strlwr(b->mailpath); if ((newf = s_fopen(b->mailpath, "sw+t")) != NULL) { s_fsetopt(newf, 1); #ifdef USERLT set_boardlife_max(old_lt); b->lifetime = old_lt; #endif writeheader(newf, 1); if (b->mailtype != 'B') { if (fgets(b->line, BUFLEN - 1, oldf)) { do { // fputs(line,f); skip old R-lines waitfor(e_ticsfull); fgets(b->line, BUFLEN - 1, oldf); } while (! feof(oldf) && *line == 'R' && line[1] == ':'); } fprintf(newf, "%s\n", makeheader(1)); fprintf(newf, "X-Transfer: %s by %s @ %s\n", datestr(ad_time(), 12), b->logincall, m.boxadress); fprintf(newf, "X-Original-Date: %s\n", datestr(oldmsgtime, 10)); do { if(( ! strncasecmp(line, "from", 4) || ! strncmp(line, "de: ", 4) || ! strncmp(line, "de ", 3) || ! strncmp(line, "fm ", 3)) && ! nocp) fprintf(newf, "X-Originally %s", line); else if (( ! strncasecmp(line, "to: ", 4) || ! strncasecmp(line, "to ", 3)) && ! nocp) fprintf(newf, "X-Originally %s", line); else if (! strncmp(line, "X-MID: ", 7)) fprintf(newf, "X-Old-MID: %s", line + 7); else if (! strncmp(line, "X-BID: ", 7)) fprintf(newf, "X-Old-BID: %s", line + 7); else fputs(line, newf); waitfor(e_ticsfull); fgets(b->line, BUFLEN - 1, oldf); } while (! feof(oldf) && *line != LF); fputc(LF, newf); } //Files binaer behandeln oldfpos = ftell(oldf); s_fclose(oldf); s_fclose(newf); writemailflags(); if ((oldf = s_fopen(oldfname, "srb")) != NULL) { if ((newf = s_fopen(b->mailpath, "sab")) != NULL) //append to file { fseek(oldf, oldfpos, SEEK_SET); do { //oe3dzw: Transferroutine transparent int len; len = fread(line, 1, 255, oldf); if (len) fwrite(line, 1, len, newf); waitfor(e_ticsfull); } while (! feof(oldf)); if (b->binstart) //bei binaeren Mails offset neu berechnen { b->binstart += ftell(newf) - ftell(oldf); if (b->binstart < 0) trace(serious, name, "offset %ld in %s", b->binstart, b->mailpath); } s_fclose(newf); if (b->binstart) writelines(); //Neuen Binstart speichern if (b->bytes) { if (old_usermail || gleichesboard) nummer = appenddirlist(1); else nummer = appenddirlist(0); //change old CHECKLINE if (b->usermail) { add_fwdfile("", get_fdelay(b->herkunft), 0); sprintf(b->line, "%s %lu", b->herkunft, nummer); mbtalk("\001", b->zielboard, b->line); trigger_ufwd(b->zielboard); } else { handle fh; char found; if (old_usermail) add_fwdfile("", get_fdelay(b->herkunft), 0); else add_fwdfile("", get_fdelay(b->herkunft), 1); if (findex > 0) tree[findex - 1].newestmail = oldmsgtime; if ((fh = s_open(CHECKNAME, "sr+b")) != EOF) { seek_fname(fh, b->mailfname, &found, 1); long pos = ltell(fh); if (found) { _read(fh, b->line, BLEN); sprintf(b->line + 15, "%-8s", b->boardname); b->line[23] = '~'; #ifdef USERLT char nlt[4]; sprintf(nlt, "%3.3d", b->boardlife_max); memcpy(b->line + 51, nlt, 3); #endif lseek(fh, -(LBLEN), SEEK_CUR); _write(fh, b->line, BLEN); } s_close(fh); if (found && (fh = s_open(CHECKNUMNAME, "sr+b")) != EOF) { lseek(fh, 2*(pos >> 6), SEEK_SET); //2* da 32bit! _write(fh, &nummer, 4); // 4Byte=32 bit s_close(fh); } } else trace(serious, name, "check"); } inc_mailgot(b->boardname); writemailflags(); retwert = OK;
void CFtpStream::Automaton(int action) { int ctrl = 0, data = 0, r; char msg[1024]; SOCK *csSock = NULL; try { if (! fURL.IsValid()) THROW(("The data to connect is not complete")); ctrl = socket(AF_INET, SOCK_STREAM, 0); if (ctrl < 0) THROW(("Failed to get socket: %s", strerror(errno))); data = socket(AF_INET, SOCK_STREAM, 0); if (data < 0) THROW(("Failed to get socket: %s", strerror(errno))); csSock = s_open(ctrl, "r+"); struct hostent *host; if ((host = gethostbyname(fURL.Server())) == NULL) THROW(("Failed to get server address: %s", strerror(errno))); struct sockaddr_in sa; sa.sin_family = AF_INET; sa.sin_port = htons(21); sa.sin_addr.s_addr = *(unsigned int *)host->h_addr; FailOSErr(connect(ctrl, (struct sockaddr *)&sa, sizeof(sa))); mail_pop_account pa; string username, password; username = strlen(fURL.Username()) ? fURL.Username() : "anonymous"; if (strlen(fURL.Password())) password = fURL.Password(); else if (get_pop_account(&pa) == B_OK) password = pa.reply_to; else password = "******"; struct sockaddr_in saData; memset(&saData, 0, sizeof(saData)); saData.sin_family = AF_INET; int state = 1; while (state) { GetReply(csSock, r, msg); switch (state) { case 1: if ((r / 100) != 2) THROW(("Connect failed: %s", msg)); s_printf(csSock, "user %s\r\n", username.c_str()); state = 2; break; case 2: if ((r / 100) == 3) { s_printf(csSock, "pass %s\r\n", password.c_str()); state = 3; break; } else if ((r / 100) != 2 && (r / 100) != 5) THROW(("Failed to login: %s", msg)); // fall thru case 3: if ((r / 100) == 5) { bool ok; CLogin *l = DialogCreator<CLogin>::CreateDialog(NULL); FailNil(l); l->Connect(fURL.Server(), username, password, &ok); if (ok) { s_printf(csSock, "noop\r\n"); state = 1; continue; } else THROW((0)); } else if (state == 3 && (r / 100) != 2) THROW(("Failed to login: %s", msg)); else if (strlen(fURL.Path())) { s_printf(csSock, "cwd %s\r\n", fURL.Path()); state = 4; break; } // fall thru case 4: { if (state == 4 && (r / 100) != 2) THROW(("Failed to change directory: %s", msg)); if (fPassive) { // switch to passive mode s_printf(csSock, "pasv\r\n"); } else { FailSockErr(bind(data, (struct sockaddr *)&saData, sizeof(saData))); FailSockErr(listen(data, 5)); // [zooey]: calling getsockname() on a socket that has been bound to // IN_ADDR_ANY (the wildcard-address) will *not* return any IP-address, // as this will only be setup by the system during connect or accept. // [refer to W.R. Stevens - Unix Network Programming, Vol 1, p. 92] // BeOS R5 however, *does* fill in the IP-address at this stage (that's // why this code worked for R5 but didn't work for BONE). // In order to fix this problem, we simply use the IP-address of the // command-socket for the PORT-command: socklen_t size = sizeof(saData); // fetch port from data-socket: FailSockErr(getsockname(data, (struct sockaddr *)&saData, &size)); unsigned char *pap = (unsigned char *)&saData.sin_port; // fetch ip-address from cmd-socket: FailSockErr(getsockname(csSock->sSocket, (struct sockaddr *)&sa, &size)); unsigned char *sap = (unsigned char *)&sa.sin_addr.s_addr; s_printf(csSock, "port %d,%d,%d,%d,%d,%d\r\n", sap[0], sap[1], sap[2], sap[3], pap[0], pap[1]); } state = 5; break; } case 5: if (fPassive) { unsigned int sap[4]; unsigned int pap[2]; if ((r / 100) != 2) THROW(("Pasv command failed: %s", msg)); char* pos = strchr(msg,'('); if (!pos) THROW(("Answer to Pasv has unknown format: %s", msg)); int cnt = sscanf(pos+1, "%u,%u,%u,%u,%u,%u", &sap[0], &sap[1], &sap[2], &sap[3], &pap[0], &pap[1]); if (cnt != 6) THROW(("Could not parse answer to Pasv (%d of 6): %s", cnt, msg)); char ipAddr[20]; sprintf(ipAddr, "%d.%d.%d.%d", sap[0], sap[1], sap[2], sap[3]); saData.sin_port = htons(pap[0]*256+pap[1]); saData.sin_addr.s_addr = inet_addr(ipAddr); FailOSErr(connect(data, (struct sockaddr *)&saData, sizeof(saData))); } else { if ((r / 100) != 2) THROW(("Port command failed: %s", msg)); } if (action == 1) { s_printf(csSock, "retr %s\r\n", fURL.File()); state = 6; } else { s_printf(csSock, "stor %s\r\n", fURL.File()); state = 7; } break; case 6: if ((r / 100) == 1) { int ds; socklen_t size = sizeof(sa); if (fPassive) ds = data; else FailSockErr(ds = accept(data, (struct sockaddr *)&sa, &size)); try { do { FailSockErr(r = recv(ds, msg, 1024, 0)); if (r) fData.Write(msg, r); } while (r); closesocket(ds); } catch (HErr& e) { closesocket(ds); throw; } state = 8; } else THROW(("Failed to retrieve file: %s", msg)); break; case 7: if ((r / 100) == 1) { int ds; socklen_t size = sizeof(sa); if (fPassive) ds = data; else FailSockErr(ds = accept(data, (struct sockaddr *)&sa, &size)); try { FailSockErr(send(ds, fData.Buffer(), fData.BufferLength(), 0)); closesocket(ds); } catch (HErr& e) { closesocket(ds); throw; } state = 8; } else THROW(("Failed to store file: %s", msg)); break; case 8: if ((r / 100) != 2) THROW(("Failed to %s file: %s", action == 1 ? "retrieve" : "store", msg)); s_printf(csSock, "quit\r\n"); state = 0; break; } } s_close(csSock); if (!fPassive) closesocket(data); closesocket(ctrl); } catch (HErr& e) { if (csSock) s_close(csSock); if (ctrl) closesocket(ctrl); if (data) closesocket(data); throw; } } /* CFtpStream::Automaton */
static int play(struct conf *conf) { struct afile a; int i; int j; assert(conf != NULL && conf->songs != NULL && conf->buffer != NULL); if (conf->flags & RFLAG) { arc4random_buf(conf->songs->shuffle, conf->songs->cur * sizeof(uint16_t)); shuffle(conf->songs->songs, conf->songs->shuffle, conf->songs->cur); } for (i = 0; i < conf->songs->cur; i++) { #ifdef OSS if ((conf->out = a_open(conf->dev)) == NULL) err(EX_SOFTWARE, "a_open"); #endif s_open(&a, conf->songs->songs[i]); if (conf->flags & VFLAG) puts(conf->songs->songs[i]); if (a.t == ANULL) { if (conf->flags & VFLAG) warn("s_open"); if (errno == ENOMEM || errno == ENFILE || errno == EMFILE) err(EX_OSERR, "s_open %s", conf->songs->songs[i]); /* remove the song from the list */ free(conf->songs->songs[i]); for (j = i; j < conf->songs->cur; j++) conf->songs->songs[j] = conf->songs->songs[j + 1]; conf->songs->cur--; /* replay the current index */ i--; continue; } switch (s_play(conf, &a)) { case CEXIT: s_close(&a); return CEXIT; case CREPLAY: i--; break; case CPREV: if (i == 0 && (conf->flags & RFLAG)) { /* replay */ i--; break; } i -= 2; if (i < -1 && (conf->flags & LFLAG)) i += conf->songs->cur; break; case CNEXT: break; } s_close(&a); #ifdef OSS a_close(conf->out); #endif } return CNULL; }
glibtop_map_entry * glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid) { int fd, i, nmaps, pr_err, heap; #if GLIBTOP_SOLARIS_RELEASE >= 50600 prxmap_t *maps; struct ps_prochandle *Pr = NULL; #else prmap_t *maps; #endif /* A few defines, to make it shorter down there */ #ifdef HAVE_PROCFS_H # define OFFSET pr_offset #else # define OFFSET pr_off #endif glibtop_map_entry *entry; struct stat inode; char buffer[BUFSIZ]; memset (buf, 0, sizeof (glibtop_proc_map)); #ifdef HAVE_PROCFS_H sprintf(buffer, "/proc/%d/xmap", (int)pid); #else sprintf(buffer, "/proc/%d", (int)pid); #endif if((fd = s_open(buffer, O_RDONLY)) < 0) { if (errno != EPERM && errno != EACCES) glibtop_warn_io_r(server, "open (%s)", buffer); return NULL; } #ifdef HAVE_PROCFS_H if(fstat(fd, &inode) < 0) { if(errno != EOVERFLOW) glibtop_warn_io_r(server, "fstat (%s)", buffer); /* else call daemon for 64-bit support */ s_close(fd); return NULL; } maps = g_alloca(inode.st_size); nmaps = inode.st_size / sizeof(prxmap_t); if(s_pread(fd, maps, inode.st_size, 0) != inode.st_size) { glibtop_warn_io_r(server, "pread (%s)", buffer); s_close(fd); return NULL; } #else if(ioctl(fd, PIOCNMAP, &nmaps) < 0) { glibtop_warn_io_r(server, "ioctl(%s, PIOCNMAP)", buffer); s_close(fd); return NULL; } maps = g_alloca((nmaps + 1) * sizeof(prmap_t)); if(ioctl(fd, PIOCMAP, maps) < 0) { glibtop_warn_io_r(server, "ioctl(%s, PIOCMAP)", buffer); s_close(fd); return NULL; } #endif buf->number = nmaps; buf->size = sizeof(glibtop_map_entry); buf->total = nmaps * sizeof(glibtop_map_entry); entry = g_malloc0(buf->total); #if GLIBTOP_SOLARIS_RELEASE >= 50600 if(server->machine->objname && server->machine->pgrab && server->machine->pfree) Pr = (server->machine->pgrab)(pid, 1, &pr_err); #endif for(heap = 0,i = 0; i < nmaps; ++i) { int len; entry[i].start = maps[i].pr_vaddr; entry[i].end = maps[i].pr_vaddr + maps[i].pr_size; #if GLIBTOP_SOLARIS_RELEASE >= 50600 if(maps[i].pr_dev != PRNODEV) { entry[i].device = maps[i].pr_dev; entry[i].inode = maps[i].pr_ino; entry[i].flags |= _glibtop_sysdeps_map_device; } #endif entry[i].offset = maps[i].OFFSET; if(maps[i].pr_mflags & MA_READ) entry[i].perm |= GLIBTOP_MAP_PERM_READ; if(maps[i].pr_mflags & MA_WRITE){ entry[i].perm |= GLIBTOP_MAP_PERM_WRITE; entry[i].size = maps[i].pr_size; } if(maps[i].pr_mflags & MA_EXEC) entry[i].perm |= GLIBTOP_MAP_PERM_EXECUTE; if(maps[i].pr_mflags & MA_SHARED) entry[i].perm |= GLIBTOP_MAP_PERM_SHARED; else entry[i].perm |= GLIBTOP_MAP_PERM_PRIVATE; entry[i].flags = _glibtop_sysdeps_map_entry; #if GLIBTOP_SOLARIS_RELEASE >= 50600 if(maps[i].pr_mflags & MA_ANON) { if(!heap) { ++heap; strcpy(entry[i].filename, "[ heap ]"); } else if(i == nmaps - 1) strcpy(entry[i].filename, "[ stack ]"); else strcpy(entry[i].filename, "[ anon ]"); entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); } else if(Pr) { server->machine->objname(Pr, maps[i].pr_vaddr, buffer, BUFSIZ); if((len = resolvepath(buffer, entry[i].filename, GLIBTOP_MAP_FILENAME_LEN)) > 0) { entry[i].filename[len] = 0; entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); } } #endif } #if GLIBTOP_SOLARIS_RELEASE >= 50600 if(Pr) server->machine->pfree(Pr); #endif buf->flags = _glibtop_sysdeps_proc_map; s_close(fd); return entry; }