static bool TryQConsole( void ) { struct _psinfo psinfo; struct _sidinfo info; struct _dev_info_entry dev; char *ptr; const char *term; if( qnx_psinfo( PROC_PID, getpid(), &psinfo, 0, 0 ) != getpid() ) { StartupErr( "unable to obtain process information" ); } if( qnx_sid_query( PROC_PID, psinfo.sid, &info ) != psinfo.sid ) { StartupErr( "unable to obtain console name" ); } ptr = info.tty_name + strlen( info.tty_name ); for( ;; ) { --ptr; if( *ptr < '0' || *ptr > '9' ) { break; } } if( DbgConsole != 0 ) { ptr[1] = '0' + DbgConsole / 10; ptr[2] = '0' + DbgConsole % 10; ptr += 2; } ptr[1] = NULLCHAR; DbgConHandle = open( info.tty_name, O_RDWR ); if( DbgConHandle == -1 ) { StartupErr( "unable to open system console" ); } term = getenv( "TERM" ); if( term != NULL && strcmp( term, "qnxw" ) == 0 ) { /* in QNX windows */ #define PROP_STRING "\033\"pwd\"" write( DbgConHandle, PROP_STRING, sizeof( PROP_STRING ) - 1 ); } ConCtrl = console_open( DbgConHandle, O_WRONLY ); if( ConCtrl == NULL ) { close( DbgConHandle ); return( false ); } if( dev_info( DbgConHandle, &dev ) == -1 ) { StartupErr( "unable to obtain console information" ); } DbgConsole = dev.unit; console_size( ConCtrl, DbgConsole, 0, 0, &PrevLines, &PrevColumns ); console_size( ConCtrl, DbgConsole, DbgLines, DbgColumns, 0, 0 ); InitConsole = console_active( ConCtrl, -1 ); return( true ); }
int FileSysNeedsCR( int handle ) { struct _fd_entry fd_info; struct _psinfo ps_info; pid_t dos_pid; if( qnx_fd_query( 0, 0, handle, &fd_info ) != handle ) return( 0 ); dos_pid = qnx_name_locate( fd_info.nid, "qnx/dosfsys", 0, NULL ); if( dos_pid == -1 ) return( 0 ); if( qnx_psinfo( PROC_PID, dos_pid, &ps_info, 0, NULL ) != dos_pid ) return( 0 ); if( ps_info.flags & _PPF_VID ) { qnx_vc_detach( dos_pid ); dos_pid = ps_info.un.vproc.remote_pid; } return( dos_pid == fd_info.pid ); }
char *procname(void) { if ((ps.flags & _PPF_TERMING) != 0) return "<defunct>"; else if ((ps.flags & _PPF_VID) == 0) return ps.un.proc.name; else { static struct _psinfo vc; pid_t vd; if ((vd = qnx_vc_attach(ps.un.vproc.remote_nid, PROC_PID, sizeof vc, 0)) == -1 || (qnx_psinfo(vd, ps.un.vproc.remote_pid, &vc, 0, 0) != ps.un.vproc.remote_pid)) { qnx_vc_detach(vd); return "*"; } qnx_vc_detach(vd); return vc.un.proc.name; } }
char *procmem(void) { long bytes = 0; if (*(long*)ps.zero1) { bytes= (*(long*)ps.zero1+*(long*)ps.un.proc.zero2)*4096; } else { struct _seginfo si[16]; int s, i; for (s = 0; qnx_psinfo(pm, ps.pid, &ps, s, si) == ps.pid; s += 16) { if ((i = ps.un.proc.nselectors) == 0) break; while (i--) if (si[i].flags & _PMF_INUSE) /* don't add first (code) selector if flat */ if (i || (ps.flags & _PPF_FLAT) == 0) bytes += si[i].nbytes; } } sprintf(buffer, "%dK", bytes / 1024); return buffer; }
int main(int argc, char **argv) { int show_other = 0; /* processes outside my session */ int show_leader = 1; /* process group leaders */ int show_interactive = 1; /* processes associated with terminals */ int show_daemon = 0; /* processes with no associated terminal */ char *match_pid = 0; /* process id to match */ char *match_pgrp = 0; /* group id to match */ char *match_sid = 0; /* session id to match */ char *match_state = 0; /* process state to match */ char *match_tty = 0; /* terminal id to match */ char *match_uid = 0; /* user id to match */ char *format = 0; /* output format string */ char detail[132]; /* detail line buffer */ time_t boot; /* boot time (kludge for image modules) */ long nid; int euid = geteuid(); int ch; time(&utc); progname = basename(argv[0]); while ((ch = getopt(argc, argv, "aAdF:g:p:s:t:u:**efjln:S:x")) != EOF) { switch (ch) { case 'a': /* all processes associated with terminals except pgrp leaders */ show_other = 1; show_leader = 0; show_interactive = 1; show_daemon = 0; break; case 'A': /* all accessible processes */ case 'f': case 'x': show_other = 1; show_leader = 1; show_interactive = 1; show_daemon = 1; break; case 'd': /* all processes except pgrp leaders */ show_other = 1; show_leader = 0; show_interactive = 1; show_daemon = 1; break; case 'F': /* specify output format */ if (format) message("more than one format string?"); format = optarg; break; case 'g': /* processes whose group ID numbers match */ show_other = 1; match_pgrp = optarg; break; case 'p': /* processes whose process ID numbers match */ show_other = 1; match_pid = optarg; break; case 's': /* sessions whose session ID numbers match */ show_other = 1; match_sid = optarg; break; case 't': /* processes whose terminal names match */ show_other = 1; match_tty = optarg; break; case 'u': /* processes whose user names/IDs match */ show_other = 1; match_uid = optarg; break; case 'e': format = FMT_ELAPSED; break; case 'l': format = FMT_LONG; break; case 'j': format = FMT_JOBS; break; case 'n': nid = strtonid(optarg, 0); if (nid == -1 || nid == 0) { message("invalid node specified (-n %s)\n", optarg); return EXIT_FAILURE; } if ((pm = qnx_vc_attach(nid, PROC_PID, sizeof ps, 1)) == -1) { message("unable to connect to node %s. (%s)\n", nidtostr(nid, 0, 0), strerror(errno)); return EXIT_FAILURE; } break; case 'S': match_state = optarg; break; } } setpwent(); if (format == 0) format = getenv("POSIX_STRICT") ? FMT_POSIX : FMT_QNX; scan_format(format, detail); print_format(detail); for (ps.pid = PROC_PID; qnx_psinfo(pm, ps.pid, &ps, 0, 0) >= 0; ps.pid++) { /* skip proxies and virtual circuits */ if ((ps.flags & _PPF_MID) || (ps.flags & _PPF_VID)) continue; /* save start time of Proc */ if (ps.pid == PROC_PID) boot = ps.un.proc.start_time; /* skip other users' processes */ if (!show_other && ps.euid != euid) continue; /* skip process group leaders */ if (!show_leader && ps.pid == ps.pgrp) continue; /* check for specific processes */ if (match_state && !match(match_state, procstate)) continue; if (match_pid && !match(match_pid, procpid)) continue; if (match_pgrp && !match(match_pgrp, procgrp)) continue; if (match_sid && !match(match_sid, procsid)) continue; if (match_tty && !match(match_tty, proctty)) continue; if (match_uid && !match(match_uid, procuser)) continue; /* kludge start time for image modules */ if (ps.un.proc.start_time == 0) ps.un.proc.start_time = boot; print_format(detail); } return EXIT_SUCCESS; }