gfc>dZddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddl m Zdd l mZdd l mZdd l mZdd l mZdd l mZddl mZddl mZddl mZddl mZddl mZddl mZddl mZddlmZddlmZddlmZddlm Z ddlm!Z!gdZ"ej#Z$ej%Z%ej&dkZ'dZ(dZ)ej*e j+ej,e j-ej.e j/ej0e j1ej2e j3ej4e j-ej5e j6iZ7ej8e j9ej:e j;ej<e j=ej>e j?ej@e jAejBe jCejDe jEejFe jGejHe jIejJe jKejLe jMejNe jOejPe(ejQe)iZReSddddd d!d"d#d$d%d&d'( ZTed)gd*ZUed+gd,ZVed-gd.ZWed/d0d1gZXeXZYed2gd3ZZed4d5d6[eZj\zZ]d7Z^d8Z_d9Z`d:Zad;Zbd<Zcd=ZdejeZee jfZfdJd?ZgejhZhejiZidKdAZjdBZkdCZldDZmdEZndFZodGZpGdHdIeqZrdS)Lz'Sun OS Solaris platform implementation.N) namedtuple)AF_INET)_common)_psposix) _psutil_posix) _psutil_sunos) AccessDenied)AF_INET6)debug)get_procfs_path) isfile_strict)memoize_when_activated) NoSuchProcess)sockfam_to_enum)socktype_to_enum) usage_percent) ZombieProcess)b)FileNotFoundError)PermissionError)ProcessLookupError)PY3) CONN_IDLE CONN_BOUND PROCFS_PATHlIDLEBOUND ) ppidrssvms create_timenice num_threadsstatusttynruideuidgidegid scputimes)usersystemidleiowait pcputimes)r6r7 children_userchildren_systemsvmem)total availablepercentusedfreepmemr*r+ pmmap_grouped)pathr* anonymouslocked pmmap_extz addr perms  ctjdtz}tjdtzx}}||z }t||d}t |||||S)zReport virtual memory metrics. SC_PHYS_PAGESSC_AVPHYS_PAGESrround_)ossysconf PAGE_SIZErr=)r>rBavailrAr@s q/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/psutil/_pssunos.pyvirtual_memoryrT{se J ' ') 3E:/009<rBlinetfrAr@s rS swap_memoryrss IC .*C*V,+-.4d< * 1 1 1A]]__NFF 4sz233|q:Q\IJJJ LLNN  & &qrr *E ;9:::ED""zz||AaCy1 SVVc\""" CFFSL!!! 4zcpu_times..s111!s1vv111rU)r[ per_cpu_timesr5ziprets rS cpu_timesrs.    C 11sCy111 22rUc@tj}d|DS)z5Return system per-CPU times as a list of named tuplesc g|] }t| Srv)r5rxs rSr{z!per_cpu_times..s ' ' 'aIqM ' ' 'rU)r[r|r~s rSr|r|s$    C ' '3 ' ' ''rUcN tjdS#t$rYdSwxYw)z0Return the number of logical CPUs in the system.SC_NPROCESSORS_ONLNN)rOrP ValueErrorrvrUrScpu_count_logicalrs:z/000 tts  $$c(tjS)z1Return the number of physical CPUs in the system.)r[cpu_count_physrvrUrScpu_count_physicalrs    rUcdtj\}}}}d}tj||||S)z*Return various CPU stats as a named tuple.r)r[ cpu_statsr scpustats) ctx_switches interruptssyscallstrapssoft_interruptss rSrrs;040@0@-L*hO  \:% ' ''rUFc Fg}tj}|D]}|\}}}}|dkrd}|sC t|js)n,#t$r}t d|d|Yd}~Nd}~wwxYwdx} } t j||||| | } || |S)zReturn system disk partitions.nonez skipping z: N) r[disk_partitions disk_usager>OSErrorr r sdiskpartappend) allretlist partitions partitiondevice mountpointfstypeoptserrmaxfilemaxpathntuples rSrrsG%''J +4( FD V  F  !*--3   :::ss;<<< ! '"6:vt#*G55v NsA A+ A&&A+c tj}|dkr|dd||vr2t d|ddd|Dtj|\}}t j|}t}|D]}|\}} } } } } }| |vr| |vr| ttfvr | rtj | } | rtj | } t| } t| } t| } |dkrtj|| | | | | |}ntj|| | | | | }||t%|S)zReturn socket connections. If pid == -1 return system-wide connections (as opposed to connections opened by one process only). Only INET sockets are returned (UNIX are not). runixrzinvalid z kind argument; choose between z, c,g|]}t|Srv)reprrxs rSr{z#net_connections..s,C,C,CT!WW,C,C,CrU)r conn_tmapcopypoprjoinr[net_connectionssetrr addr TCP_STATUSESrrsconnpconnaddlist)kind_pidcmapfamiliestypesrawlistritemfdfamtype_laddrraddrr/pidnts rSrrs   ! ! # #D rzz  4j DD$)),C,Cd,C,C,C"D"D"DFGG G'-OHe"4((G %%C481Cufc h        7H% % % - e, - e,f%c"" '' 2::r3ueVSIIBBr3ueVDDB  99rUctj}|D]O\}}|\}}}}ttdrt j|}t j||||||<P|S)z)Get NIC stats (isup, duplex, speed, mtu). NicDuplex)r[ net_if_statsitemshasattrrr snicstats)rnamerisupduplexspeedmtus rSrr!s~    Cyy{{@@ e#( feS 7K ( ( /&v..F%dFE3??D JrUc(tjS)z:The system boot time expressed in seconds since the epoch.)r[ boot_timervrUrSrr1s >  rUcg}tj}d}|D]A}|\}}}}}} |s||vrd}tj||||| } || B|S)z:Return currently connected users as a list of namedtuples.)z:0.0z:0 localhost)r[usersrsuserr) rrrrr6ttyhostnametstamp user_processrrs rSrr6sGjllGI  9=6c8V\3   y "H ]4h < <r NrUcpdtjttDS)z7Returns a list of PIDs currently running on the system.cTg|]%}|t|&Srv)isdigitrirxs rSr{zpids..Ps+ L L Lq LCFF L L LrU)rOlistdirrr rvrUrSpidsrNs. L LBJq):):';';<< L L LLrUc*tj|S)z&Check for the existence of a unix pid.)r pid_exists)rs rSrrSs  s # ##rUcFtjfd}|S)zCall callable into a try/except clause and translate ENOENT, EACCES and EPERM in NoSuchProcess or AccessDenied exceptions. c |g|Ri|S#ttf$rOt|jst |j|jt |j|j|jt$rt|j|jt$r8|jdkr+dtvrt|j|jwxYwNr) rrrrr_namer_ppidrr rr)selfargskwargsfuns rSwrapperz wrap_exceptions..wrapper\s 3t-d---f-- -!#56 F F Fdh'' F#DHdj999#DHdj$*EEE 5 5 5tx44 4   x1}};;&tx<<<   s CC) functoolswraps)rrs` rSwrap_exceptionsrXs:_S( NrUceZdZdZgdZdZdZdZdZe e dZ e e dZ e e d Z e d Ze d Ze d Ze d Ze dZe dZe dZe dZe dZe dZe dZe dZe dZe dZe dZe dZeZe dZe dZ e dZ!dZ"e d(dZ#e$d d!Z%e$d d"Z&e d#Z'e d$Z(e d%Z)e d)d'Z*d&S)*Processz1Wrapper class around underlying C implementation.)rrr _procfs_path_cachecV||_d|_d|_t|_dSN)rrrr r)rrs rS__init__zProcess.__init__ys+  +--rUcLtj|jd|jdS)z+Raise NSP if the process disappeared on us./N)rOstatrrrs rS _assert_alivezProcess._assert_alives, 4,,,dhh788888rUc|j||j||j|dSr)_proc_name_and_argscache_activate_proc_basic_info _proc_credrs rS oneshot_enterzProcess.oneshot_entersL  //555 ,,T222 &&t,,,,,rUc|j||j||j|dSr)rcache_deactivaterrrs rS oneshot_exitzProcess.oneshot_exitsL  11$777 ..t444 ((.....rUc@tj|j|jSr)r[proc_name_and_argsrrrs rSrzProcess._proc_name_and_argss&tx1BCCCrUc.|jdkrCtj|jd|jdst |jt j|j|j}t|ttksJ|S)Nrrz/psinfo) rrOrEexistsrr r[proc_basic_infolen proc_info_map)rrs rSrzProcess._proc_basic_infos 8q==1B1B1BDHHHMNN tx(( ("48T->??3xx3}------ rUc@tj|j|jSr)r[ proc_credrrrs rSrzProcess._proc_creds~dh(9:::rUc6|dSr)rrs rSrz Process.names''))!,,rUc tj|jd|jdS#t$rYnwxYw|dS)Nrz /path/a.outr)rOreadlinkrrrcmdliners rSexez Process.exesi ;&*&7&7&7BDD D    D  rs #& 33c\|ddS)NrrI)rrhrs rSrzProcess.cmdlines'''))!,223777rUc@tj|j|jSr)r[ proc_environrrrs rSr_zProcess.environ 4+<===rUcL|tdS)Nr,rr rs rSr,zProcess.create_time$$&&}]'CDDrUcL|tdS)Nr.rrs rSr.zProcess.num_threadsrrUcL|tdS)Nr-rrs rSnice_getzProcess.nice_gets $$&&}V'<==rUc||jdvrt|j|jtj|j|S)N)rr )rr r cext_posix setpriority)rvalues rSnice_setzProcess.nice_sets: 8v   tx44 4%dh666rUcd|td|_|jS)Nr))rr rrs rSr)z Process.ppids'**,,]6-BC zrUc  |\}}}}}}n\#t$rO|td}|td}d}YnwxYwt j|||S)Nr1r2rr rr rpuids)rreal effectivesaved_s rSuidsz Process.uidss .2oo.?.? +D)UAq!!   ((**=+?@D--// f0EFIEEE }T9e444AA76A7c  |\}}}}}}n\#t$rO|td}|td}d}YnwxYwt j|||S)Nr3r4r")rr'r$r%r&s rSgidsz Process.gidss .2oo.?.? +Aq!T9ee   ((**=+?@D--// f0EFIEEE }T9e444r)c tj|j|j}n7#t$r*}|jt jkr tsd}nYd}~nd}~wwxYwtj |S)N)r-r-r-) r[proc_cpu_timesrrrerrno EOVERFLOW IS_64_BITrr:)rtimesrs rSrzProcess.cpu_timess| '$2CDDEE   yEO++I+-  %((s" A AAc@tj|j|jSr)r[ proc_cpu_numrrrs rScpu_numzProcess.cpu_numrrUc<|j}d}t|td}|tjkr8dD]5} t jd||j|fzcS#t$rd}Y2wxYw|r| dSdS)NFr0)rrrz %s/%d/path/%dT) rrrr r[PRNODEVrOrrrr)r procfs_path hit_enoentrrzs rSterminalzProcess.terminals'    ! ! # #M'$: ;== $,  #  ;';!*DDFFFFF(!%JH  !     ! !sA22 BBc|j} tj|d|jdS#t$r"tj|d|jYdSwxYw)Nrz /path/cwd)rrOrrrr)rr9s rScwdz Process.cwdso '  ;;;;IJJ J     G{{{DHH5 6 6 644 s((AAc|}|tddz}|tddz}t||S)Nr*ir+)rr rC)rrr*r+s rS memory_infozProcess.memory_info#sI##%%-&'$.-&'$.C~~rUc|td}t|dS)Nr/?)rr  PROC_STATUSESget)rcodes rSr/zProcess.status,s3$$&&}X'>?  s+++rUc|j}g}tjd||jfz}d}|D]}t |} t j|j||\}}tj|||}| |\#t$rC} | j tj kr tsYd} ~ | j tjkrd}Yd} ~ d} ~ wwxYw|r||S)Nz %s/%d/lwpFT)rrOrrrir[query_process_threadrpthreadrEnvironmentErrorr/r0r1ENOENTr) rr9rtidsr:tidutimestimerrs rSthreadszProcess.threads2s' z+dh(??@@   Cc((C #8Hc; 0 0 u$_S%77 2#$   9// /HHHH9 ,,!%JHHHH $  !     s#B CC3CCCc g}d}|j}d||jfz}tjd||jfzD]}tj||}tj|rl tj|}t|r5| tj |t|#t$rd}YwxYw|r||S)NFz %s/%d/pathz%s/%d/fdT)rrrOrrErislinkrrrr popenfilerirr)rrr:r9pathdirrrEfiles rS open_fileszProcess.open_filesSs ' +tx!88*Z;*AABB I IB7<<,,Dw~~d## II;t,,D %T**Iw'8s2ww'G'GHHH )!%JH I  !    s8C C C c#|Kd|z}tj|dtjtj}|\}}trd||fD\}}|jdkrtd|vrt|j|j d|vrt|j|j t|d|| d d d }t|D]\}}|}|d r| d d d } ||d z } | dkr t"j} n| dkr t"j} nd} dt"j| | dt*jfVd S)z.qs9999"# hhsz':;;999rUrzpermission deniedzno such processz command error rZrNzsockname: AF_UNIXrI SOCK_STREAM SOCK_DGRAMrr)r]r^r`rarrelowerr rrrrfrh enumeratelstrip startswithrgsocketrXrYAF_UNIXr CONN_NONE) rrcmdrmrYrnroirprEtypes rS_get_unix_socketszProcess._get_unix_socketshsC  SZ_$.O 5 5 5  999(.'7999NFF <1  "fllnn44"48TZ888 FLLNN22#DHdj999ffEFF F T""122& '' N NGAt;;==D233 Nzz#q))!,QU|))++=((!-DD\))!,DDD6>4r7;LMMMM N NrUinetct||j}|s#tj|jd|j|dvr7|d||jD|S)N)rr)rrc*g|]}tj|Srv)rr)ryconns rSr{z'Process.connections..s+::: t,:::rU)rrrOrrextendrd)rrrs rS connectionszProcess.connectionssd222  = Gt000$((; < < < ? " " JJ::..tx88::: ; ; ; rUmmapzpath rss anon lockedzaddr perms path rss anon lockedc Ld}|j}g} tj|j|}n6#t$r)}|jt jkrtsgcYd}~Sd}~wwxYwd}|D]}|\}} } } } } }||| }| dsb tj |d|jd| } n?#t$r2}|jt j kr|d|jd| } d}nYd}~nd}~wwxYw| || | | | |f|r| |S)Nct|ddddt|dddS)NrL-)hexrg)startends rStoaddrz#Process.memory_maps..toaddrsS!%jjn2237777!#hhqrrl005557 7rUF[rz/path/T)rr[proc_memory_mapsrrr/r0r1r]rOrrIrr)rrsr9rrrr:rraddrsizepermrr*anonrGs rS memory_mapszProcess.memory_mapss 7 7 7'  +DHkBBGG   yEO++I+    B BD<@ 9D(D$T66$))D??3'' ;+6;;$$GIIDD   yEL003>++txxxN%) #   NND$c4@ A A A A  !    s8) AAAAA!B33 C/=(C**C/cdttj|jd|jdS)Nrz/fd)rrOrrrrs rSnum_fdszProcess.num_fdss.2:D,=,=,=txxxHIIJJJrUcXtjtj|j|jSr)rpctxswr[proc_num_ctx_switchesrrrs rSnum_ctx_switcheszProcess.num_ctx_switchess(~  '$2C D DF FrUNcBtj|j||jSr)rwait_pidrr)rtimeouts rSwaitz Process.waits 7DJ???rU)rer)+__name__ __module__ __qualname____doc__ __slots__rrrrrrrrrrrrr_r,r.rrr)r(r+rr5r;r=r?memory_full_infor/rNrTrdrjrnt_mmap_grouped nt_mmap_extryr{rrrvrUrSrrts;;CCCI... 999 --- /// DD_D_;;_;--_-  _ 88_8>>_>EE_EEE_E>>_> 77_7_55_555_5))_)">>_>!!_!   _ _ #,,_, _@_(NNN@_"!j)?@@O*V%FGGK,,_,\KK_KFF_F@@@_@@@rUr)F)r)srr/rrOr^r]rc collectionsrrrrrrrr r[r r r r rrrrrrr_compatrrrrr__extra__all__ getpagesizerQAF_LINKmaxsizer1rrSSLEEPSTATUS_SLEEPINGSRUNSTATUS_RUNNINGSZOMB STATUS_ZOMBIESSTOPSTATUS_STOPPEDSIDL STATUS_IDLESONPROCSWAITSTATUS_WAITINGrBTCPS_ESTABLISHEDCONN_ESTABLISHED TCPS_SYN_SENT CONN_SYN_SENT TCPS_SYN_RCVD CONN_SYN_RECVTCPS_FIN_WAIT_1CONN_FIN_WAIT1TCPS_FIN_WAIT_2CONN_FIN_WAIT2TCPS_TIME_WAITCONN_TIME_WAIT TCPS_CLOSED CONN_CLOSETCPS_CLOSE_WAITCONN_CLOSE_WAIT TCPS_LAST_ACK CONN_LAST_ACK TCPS_LISTEN CONN_LISTEN TCPS_CLOSING CONN_CLOSINGPSUTIL_CONN_NONEr` TCPS_IDLE TCPS_BOUNDrdictr r5r:r=rCpfullmemrDr_fieldsrHrTrsrr|rrrdisk_io_countersrrnet_io_counters net_if_addrsrrrrrrrobjectrrvrUrSrsN .-   """"""))))))######!!!!!!$$$$$$""""""++++++""""""$$$$$$%%%%%%""""""""""""&&&&&&$$$$$$''''''<;; #J " $ $   K%     K(Iw%J%J&Iw"L'(J&  73--'0'0/g('1-g)w+7,NIOZ "           * J{$H$H$H I I J{MMM O O   7MMMNNz&5%.))  ?AAACC  J-*?!@!@@ B B 444<<