ó ±2öYc@séddlmZmZmZmZmZmZmZddlm Z ddl Zddl Z ddl Z ddl Z ddlZddlZddlZddljZddlmZejjƒZdgZdefd„ƒYZdS(iÿÿÿÿ(tstoragetunitstmonitorstpluginstprofilestexportsthardware(tTunedExceptionN(t GlobalConfigt ApplicationcBs’eZd d d„Zd„Zd„Zd„Zd„Zej d„Z d„Z d„Z ej d„Z ed „ƒZed „ƒZd „ZRS( c Csád|_tjƒ}tj|ƒ}|dkr9tƒn||_|jjtj ƒrgt j dƒn t j dƒt j ƒ}|jjdtjƒ}tjd|ƒ}tjƒ}tjƒ} tjjƒ} tjjƒ|_tj ||||| | |j|jƒ} t|jjtjtjƒƒ} tj| || ƒ} tjƒ}tjƒ}tj tj!ƒ}tj"||||j|jƒ}t#j$| |||j|ƒ|_%t&j'|j%|jƒ|_(|j)ƒd|_*dS(Ns8dynamic tuning is enabled (can be overridden in plugins)s#dynamic tuning is globally disabledtudev_buffer_sizet buffer_size(+tNonet_dbus_exporterRtPickleProvidertFactoryRtconfigtget_booltconststCFG_DYNAMIC_TUNINGtlogtinfoRt Repositorytget_sizetCFG_DEF_UDEV_BUFFER_SIZERt Inventoryt DeviceMatchertDeviceMatcherUdevRtinstanceRt variablest VariablestinttgettCFG_DEFAULT_INSTANCE_PRIORITYt!CFG_DEF_DEFAULT_INSTANCE_PRIORITYRtManagertMergertLocatortLOAD_DIRECTORIEStLoadertdaemontDaemont_daemont controllert Controllert _controllert _init_signalst _pid_file(tselft profile_nameRtstorage_providertstorage_factorytmonitors_repositoryR thardware_inventorytdevice_matchertdevice_matcher_udevtplugin_instance_factorytplugins_repositorytdef_instance_priorityt unit_managertprofile_factorytprofile_mergertprofile_locatortprofile_loader((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyt__init__s4      !  !! cs&‡‡fd†}tjˆ|ƒdS(Ncsˆ|krˆƒndS(N((t_signal_numbert_frame(thandlert signal_number(s</usr/lib/python2.7/site-packages/tuned/daemon/application.pythandler_wrapper8s (tsignal(R0RDRCRE((RCRDs</usr/lib/python2.7/site-packages/tuned/daemon/application.pyt_handle_signal7scCsO|jtj|jjƒ|jtj|jjƒ|jtj|jjƒdS(N(RGRFtSIGHUPR-treloadtSIGINTt terminatetSIGTERM(R0((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyR.=scCs]|jdk rtdƒ‚ntjj|||ƒ|_tj|jƒtj|jƒdS(Ns&DBus interface is already initialized.( R R RRtdbust DBusExportertregister_exportertregister_objectR-(R0tbus_namet object_nametinterface_name((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pytattach_to_dbusBs cCsÅtj|ƒtj|gggtjƒ\}}}t|ƒdkrbtj|ƒtdƒ‚ntj|dƒ}tj|ƒt|ƒdkr¢tdƒ‚n|dtkrÁtdƒ‚ndS( s| Wait till the child signalizes that the initialization is complete by writing some uninteresting data into the pipe. is=Cannot daemonize, timeout when waiting for the child process.iis:Cannot daemonize, no response from child process received.s%cs0Cannot daemonize, child process reports failure.N( tostclosetselectRtDAEMONIZE_PARENT_TIMEOUTtlenRtreadtTrue(R0t parent_in_fdt child_out_fdt read_readytdroptresponse((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyt_daemonize_parentJs '  cCsÞ||_|jƒy‹tjj|jƒ}tjj|ƒsMtj|ƒntj|jtjtj Btj Bdƒ}tj |dtj ƒƒtj |ƒWn9ttfk rÙ}tjd|jt|ƒfƒnXdS(Ni¤s%dscannot write the PID to %s: %s(R/t_delete_pid_fileRUtpathtdirnametexiststmakedirstopentO_CREATtO_TRUNCtO_WRONLYtwritetgetpidRVtOSErrortIOErrorRtcriticaltstr(R0tpid_filetdir_nametfdterror((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pytwrite_pid_file_s  )cCsftjj|jƒrbytj|jƒWqbtk r^}tjd|jt|ƒfƒqbXndS(Ns&cannot remove existing PID file %s, %s( RURcReR/tunlinkRmRtwarningRp(R0Rt((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyRbms c Csƒtj|ƒtjdƒtjƒtjdƒy,tjƒ}|dkr\tjdƒnWnWtk r¶}t j dt |ƒƒtj |dt ƒtj|ƒtdƒ‚nXtddƒ}tddƒ}tdddƒ}tj|jƒtjjƒƒtj|jƒtjjƒƒtj|jƒtjjƒƒ|j|ƒt jd ƒtj |dtƒtj|ƒd S( sy Finishes daemonizing process, writes a PID file and signalizes to the parent that the initialization is complete. t/is"cannot daemonize, fork() error: %ss%cs'Cannot daemonize, second fork() failed.s /dev/nulltrsa+ssuccessfully daemonizedN(RURVtchdirtsetsidtumasktforktsystexitRmRRoRpRktFalseRtfiletdup2tfilenotstdintstdouttstderrRutdebugR[( R0RqR\R]tpidRttsitsotse((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyt_daemonize_childts.         cCsÊtjƒ}ytjƒ}WnAtk r_}tj|dƒtj|dƒtdƒ‚nXy=|dkrŒ|j|Œtjdƒn|j ||ŒWn&|dkrµ‚qÆtjdƒnXdS(sÚ Daemonizes the application. In case of failure, TunedException is raised in the parent process. If the operation is successfull, the main process is terminated and only child process returns from this method. iis Cannot daemonize, fork() failed.N( RUtpipeR}RmRVRRaR~RRŒ(R0Rqtparent_child_fdst child_pidRt((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyt daemonize–s     cCs|jS(N(R*(R0((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyR(±scCs|jS(N(R-(R0((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyR+µscCs¡|r|jjtjtƒn|jjtjtjƒsJtjdƒn|j j ƒ}|jjtjtjƒrt j ƒn|j dk r|jƒn|S(NsrUsing one shot no deamon mode, most of the functionality will be not available, it can be changed in global config(RtsetRt CFG_DAEMONR[RtCFG_DEF_DAEMONRtwarnR-trunRtstopR/R Rb(R0R(tresult((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyR•¹s  N(t__name__t __module__R R@RGR.RTRaRtPID_FILERuRbRŒRtpropertyR(R+R•(((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyR s%      "(ttunedRRRRRRRttuned.exceptionsRt tuned.logsR+R(RFRUR~RWt tuned.constsRttuned.utils.global_configRtlogsR Rt__all__tobjectR (((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyts4