\c@sddlmZmZmZmZmZmZmZddlm Z ddl Zddl m Z ddl m Z ddlZddlZddlZddlZddlZddljZddlmZejjZdgZdefd YZdS( i(tstoragetunitstmonitorstpluginstprofilestexportsthardware(tTunedExceptionNi(t controller(tdaemon(t GlobalConfigt ApplicationcBseZd d dZdZdZdZdZej dZ dZ dZ ej dZ ed Zed Zd ZRS( c Csd|_tj}tj|}|dkr9tn||_|jjtj rgt j dn t j dt 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_exporterRtPickleProvidertFactoryR tconfigtget_booltconststCFG_DYNAMIC_TUNINGtlogtinfoRt Repositorytget_sizetCFG_DEF_UDEV_BUFFER_SIZERt Inventoryt DeviceMatchertDeviceMatcherUdevRtinstanceRt variablest VariablestinttgettCFG_DEFAULT_INSTANCE_PRIORITYt!CFG_DEF_DEFAULT_INSTANCE_PRIORITYRtManagertMergertLocatortLOAD_DIRECTORIEStLoaderR tDaemont_daemonRt 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__s8      !   !! cs&fd}tj|dS(Ncs|krndS(N((t_signal_numbert_frame(thandlert signal_number(s</usr/lib/python2.7/site-packages/tuned/daemon/application.pythandler_wrapper;s (tsignal(R0RDRCRE((RCRDs</usr/lib/python2.7/site-packages/tuned/daemon/application.pyt_handle_signal:scCsO|jtj|jj|jtj|jj|jtj|jjdS(N(RGRFtSIGHUPR-treloadtSIGINTt terminatetSIGTERM(R0((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyR.@scCs]|jdk rtdntjj||||_tj|jtj|jdS(Ns&DBus interface is already initialized.( RRRRtdbust DBusExportertregister_exportertregister_objectR-(R0tbus_namet object_nametinterface_name((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pytattach_to_dbusEs cCstj|tj|gggtj\}}}t|dkrbtj|tdntj|d}tj|t|dkrtdnytj d|d}Wn tj k rtdnX|t krtdnd S( 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.t?s?Cannot daemonize, invalid response from child process received.s0Cannot daemonize, child process reports failure.N( tostclosetselectRtDAEMONIZE_PARENT_TIMEOUTtlenRtreadtstructtunpackterrortTrue(R0t parent_in_fdt child_out_fdt read_readytdroptresponsetval((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyt_daemonize_parentMs '   cCs||_|jytjj|j}tjj|sMtj|ntjtj|jtj tj Btj Bdd}|j dtj WdQXWn9ttfk r}tjd|jt|fnXdS(Nitws%dscannot write the PID to %s: %s(R/t_delete_pid_fileRVtpathtdirnametexiststmakedirstfdopentopentO_CREATtO_TRUNCtO_WRONLYtwritetgetpidtOSErrortIOErrorRtcriticaltstr(R0tpid_filetdir_nametfR^((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pytwrite_pid_filefs  8!cCsftjj|jrbytj|jWqbtk r^}tjd|jt|fqbXndS(Ns&cannot remove existing PID file %s, %s( RVRiRkR/tunlinkRtRtwarningRw(R0R^((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyRhss cCs~tj|tjdtjtjdy,tj}|dkr\tjdnWnetk r}t j dt |t j dt}tj||tj|tdnXtdd}tj|jtjjtj|jtjjtj|jtjj|j|t jdt j dt}tj||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: %sRUs'Cannot daemonize, second fork() failed.s /dev/nullsw+ssuccessfully daemonizedN(RVRWtchdirtsetsidtumasktforktsystexitRtRRvRwR\tpacktFalseRrRRntdup2tfilenotstdintstdouttstderrR{tdebugR_(R0RxR`RatpidR^Retfd((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyt_daemonize_childzs.         cCstj}ytj}WnAtk r_}tj|dtj|dtdnXy=|dkr|j|tjdn|j ||Wn&|dkrqtjdnXdS(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( RVtpipeRRtRWRRfRRR(R0Rxtparent_child_fdst child_pidR^((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyt daemonizes     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.pyRscCs|r|jjtjtn|jjtjtjsJtjdn|j j }|jjtjtjrt j n|j dk r|jn|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/RRh(R0R tresult((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyRs  N(t__name__t __module__RR@RGR.RTRfRtPID_FILER{RhRRtpropertyR RR(((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyR s'      "(ttunedRRRRRRRttuned.exceptionsRt tuned.logstRR RFRVRRXR\t tuned.constsRttuned.utils.global_configR tlogsR"Rt__all__tobjectR (((s</usr/lib/python2.7/site-packages/tuned/daemon/application.pyts4