From b96f112106ea43dda5b5747bc315a2b76ba9da8f Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sat, 26 Feb 2011 18:54:48 +0100 Subject: [PATCH] Make $exec et al. use the new callback system I removed the code for automatic killing of stuck children, because (by admission of the person who wrote it) it wasn't working. I also removed the $pre_exec variable, because one can use lua to generate the config on the startup, if one wants to. --- doc/variables.xml | 11 -- extras/nano/conky.nanorc | 2 +- extras/vim/syntax/conkyrc.vim | 2 +- src/conky.cc | 16 +-- src/core.cc | 2 - src/exec.cc | 210 ++++++++++------------------------ src/exec.h | 7 +- 7 files changed, 64 insertions(+), 186 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index b55da7b9..06d30e67 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -3062,17 +3062,6 @@ when Conky starts. - - - - - - - - Executes a shell command one time before conky - displays anything and puts output as text. - - diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index ce14f3d5..6150c4fc 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -11,7 +11,7 @@ color green "\<(alignment|append_file|background|border_inner_margin|border_oute color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|middle_middle|undecorated|yes)\>" ## Variables -color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|distribution|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|ical|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|ioscheduler|irc|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|mysql|nameserver|new_mails|nodename|nodename_short|no_update|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|read_udp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|stock|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_ping|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" +color brightblue "\<(acpiacadapter|acpifan|acpitemp|addr|addrs|alignc|alignr|apcupsd|apcupsd_cable|apcupsd_charge|apcupsd_lastxfer|apcupsd_linev|apcupsd_load|apcupsd_loadbar|apcupsd_loadgauge|apcupsd_loadgraph|apcupsd_model|apcupsd_name|apcupsd_status|apcupsd_temp|apcupsd_timeleft|apcupsd_upsmode|apm_adapter|apm_battery_life|apm_battery_time|audacious_bar|audacious_bitrate|audacious_channels|audacious_filename|audacious_frequency|audacious_length|audacious_length_seconds|audacious_main_volume|audacious_playlist_length|audacious_playlist_position|audacious_position|audacious_position_seconds|audacious_status|audacious_title|battery|battery_bar|battery_percent|battery_short|battery_time|blink|bmpx_album|bmpx_artist|bmpx_bitrate|bmpx_title|bmpx_track|bmpx_uri|buffers|cached|cmdline_to_pid|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_build_arch|conky_build_date|conky_version|cpu|cpubar|cpugauge|cpugraph|curl|desktop|desktop_name|desktop_number|disk_protect|diskio|diskio_read|diskio_write|diskiograph|diskiograph_read|diskiograph_write|distribution|downspeed|downspeedf|downspeedgraph|draft_mails|else|endif|entropy_avail|entropy_bar|entropy_perc|entropy_poolsize|eval|eve|exec|execbar|execgauge|execgraph|execi|execibar|execigauge|execigraph|execp|execpi|flagged_mails|font|format_time|forwarded_mails|freq|freq_g|fs_bar|fs_bar_free|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_used_perc|goto|gw_iface|gw_ip|hddtemp|head|hr|hwmon|i2c|i8k_ac_status|i8k_bios|i8k_buttons_status|i8k_cpu_temp|i8k_left_fan_rpm|i8k_left_fan_status|i8k_right_fan_rpm|i8k_right_fan_status|i8k_serial|i8k_version|ibm_brightness|ibm_fan|ibm_temps|ibm_volume|ical|iconv_start|iconv_stop|if_empty|if_existing|if_gw|if_match|if_mixer_mute|if_mounted|if_mpd_playing|if_running|if_smapi_bat_installed|if_up|if_updatenr|if_xmms2_connected|image|imap_messages|imap_unseen|ioscheduler|irc|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|memwithbuffers|membar|memwithbuffersbar|memeasyfree|memfree|memgauge|memgraph|memmax|memperc|mixer|mixerbar|mixerl|mixerlbar|mixerr|mixerrbar|moc_album|moc_artist|moc_bitrate|moc_curtime|moc_file|moc_rate|moc_song|moc_state|moc_timeleft|moc_title|moc_totaltime|monitor|monitor_number|mpd_album|mpd_artist|mpd_bar|mpd_bitrate|mpd_elapsed|mpd_file|mpd_length|mpd_name|mpd_percent|mpd_random|mpd_repeat|mpd_smart|mpd_status|mpd_title|mpd_track|mpd_vol|mysql|nameserver|new_mails|nodename|nodename_short|no_update|nvidia|obsd_product|obsd_sensors_fan|obsd_sensors_temp|obsd_sensors_volt|obsd_vendor|offset|outlinecolor|pb_battery|pid_chroot|pid_cmdline|pid_cwd|pid_environ|pid_environ_list|pid_exe|pid_nice|pid_openfiles|pid_parent|pid_priority|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|pid_threads|pid_thread_list|pid_time_kernelmode|pid_time_usermode|pid_time|pid_uid|pid_euid|pid_suid|pid_fsuid|pid_gid|pid_egid|pid_sgid|pid_fsgid|pid_read|pid_vmpeak|pid_vmsize|pid_vmlck|pid_vmhwm|pid_vmrss|pid_vmdata|pid_vmstk|pid_vmexe|pid_vmlib|pid_vmpte|pid_write|platform|pop3_unseen|pop3_used|processes|read_tcp|read_udp|replied_mails|rss|running_processes|running_threads|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|stock|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_ping|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|texecpi|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|gid_name|uid_name|unflagged_mails|unforwarded_mails|unreplied_mails|unseen_mails|updates|upspeed|upspeedf|upspeedgraph|uptime|uptime_short|user_names|user_number|user_terms|user_times|user_time|utime|voffset|voltage_mv|voltage_v|weather|wireless_ap|wireless_bitrate|wireless_essid|wireless_link_bar|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_mode|words|xmms2_album|xmms2_artist|xmms2_bar|xmms2_bitrate|xmms2_comment|xmms2_date|xmms2_duration|xmms2_elapsed|xmms2_genre|xmms2_id|xmms2_percent|xmms2_playlist|xmms2_size|xmms2_smart|xmms2_status|xmms2_timesplayed|xmms2_title|xmms2_tracknr|xmms2_url)\>" color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?" color cyan "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index 22d78261..7ea58d1c 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -50,7 +50,7 @@ syn region ConkyrcVar start=/\$\w\@=/ end=/\W\@=\|$/ contained contains=ConkyrcV syn match ConkyrcVarStuff /{\@<=/ms=s contained nextgroup=ConkyrcVarName -syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write distribution downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume ical iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen ioscheduler irc kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol mysql nameserver new_mails nodename nodename_short no_update nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used pre_exec processes read_tcp read_udp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr stock swap swapbar swapfree swapmax swapperc sysname tab tail tcp_ping tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url +syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipwhite acpiacadapter acpifan acpitemp addr addrs alignc alignr apcupsd apcupsd_cable apcupsd_charge apcupsd_lastxfer apcupsd_linev apcupsd_load apcupsd_loadbar apcupsd_loadgauge apcupsd_loadgraph apcupsd_model apcupsd_name apcupsd_status apcupsd_temp apcupsd_timeleft apcupsd_upsmode apm_adapter apm_battery_life apm_battery_time audacious_bar audacious_bitrate audacious_channels audacious_filename audacious_frequency audacious_length audacious_length_seconds audacious_main_volume audacious_playlist_length audacious_playlist_position audacious_position audacious_position_seconds audacious_status audacious_title battery battery_bar battery_percent battery_short battery_time blink bmpx_album bmpx_artist bmpx_bitrate bmpx_title bmpx_track bmpx_uri buffers cached cmdline_to_pid color color0 color1 color2 color3 color4 color5 color6 color7 color8 color9 combine conky_build_arch conky_build_date conky_version cpu cpubar cpugauge cpugraph curl desktop desktop_name desktop_number disk_protect diskio diskio_read diskio_write diskiograph diskiograph_read diskiograph_write distribution downspeed downspeedf downspeedgraph draft_mails else endif entropy_avail entropy_bar entropy_perc entropy_poolsize eval eve exec execbar execgauge execgraph execi execibar execigauge execigraph execp execpi flagged_mails font format_time forwarded_mails freq freq_g fs_bar fs_bar_free fs_free fs_free_perc fs_size fs_type fs_used fs_used_perc goto gw_iface gw_ip hddtemp head hr hwmon i2c i8k_ac_status i8k_bios i8k_buttons_status i8k_cpu_temp i8k_left_fan_rpm i8k_left_fan_status i8k_right_fan_rpm i8k_right_fan_status i8k_serial i8k_version ibm_brightness ibm_fan ibm_temps ibm_volume ical iconv_start iconv_stop if_empty if_existing if_gw if_match if_mixer_mute if_mounted if_mpd_playing if_running if_smapi_bat_installed if_up if_updatenr if_xmms2_connected image imap_messages imap_unseen ioscheduler irc kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem memwithbuffers membar memwithbuffersbar memeasyfree memfree memgauge memgraph memmax memperc mixer mixerbar mixerl mixerlbar mixerr mixerrbar moc_album moc_artist moc_bitrate moc_curtime moc_file moc_rate moc_song moc_state moc_timeleft moc_title moc_totaltime monitor monitor_number mpd_album mpd_artist mpd_bar mpd_bitrate mpd_elapsed mpd_file mpd_length mpd_name mpd_percent mpd_random mpd_repeat mpd_smart mpd_status mpd_title mpd_track mpd_vol mysql nameserver new_mails nodename nodename_short no_update nvidia obsd_product obsd_sensors_fan obsd_sensors_temp obsd_sensors_volt obsd_vendor offset outlinecolor pb_battery pid_chroot pid_cmdline pid_cwd pid_environ pid_environ_list pid_exe pid_nice pid_openfiles pid_parent pid_priority pid_state pid_state_short pid_stderr pid_stdin pid_stdout pid_threads pid_thread_list pid_time_kernelmode pid_time_usermode pid_time pid_uid pid_euid pid_suid pid_fsuid pid_gid pid_egid pid_sgid pid_fsgid pid_read pid_vmpeak pid_vmsize pid_vmlck pid_vmhwm pid_vmrss pid_vmdata pid_vmstk pid_vmexe pid_vmlib pid_vmpte pid_write platform pop3_unseen pop3_used processes read_tcp read_udp replied_mails rss running_processes running_threads scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr stock swap swapbar swapfree swapmax swapperc sysname tab tail tcp_ping tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci texecpi threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime gid_name uid_name unflagged_mails unforwarded_mails unreplied_mails unseen_mails updates upspeed upspeedf upspeedgraph uptime uptime_short user_names user_number user_terms user_times user_time utime voffset voltage_mv voltage_v weather wireless_ap wireless_bitrate wireless_essid wireless_link_bar wireless_link_qual wireless_link_qual_max wireless_link_qual_perc wireless_mode words xmms2_album xmms2_artist xmms2_bar xmms2_bitrate xmms2_comment xmms2_date xmms2_duration xmms2_elapsed xmms2_genre xmms2_id xmms2_percent xmms2_playlist xmms2_size xmms2_smart xmms2_status xmms2_timesplayed xmms2_title xmms2_tracknr xmms2_url hi def link ConkyrcComment Comment hi def link ConkyrcSetting Keyword diff --git a/src/conky.cc b/src/conky.cc index 2f09ce66..01992776 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -3149,21 +3149,11 @@ int main(int argc, char **argv) } -void alarm_handler(void) { - if(childpid > 0) { - kill(childpid, SIGTERM); - } -} - static void signal_handler(int sig) { /* signal handler is light as a feather, as it should be. * we will poll g_signal_pending with each loop of conky - * and do any signal processing there, NOT here (except - * SIGALRM because this is caused when conky is hanging) */ - if(sig == SIGALRM) { - alarm_handler(); - } else { - g_signal_pending = sig; - } + * and do any signal processing there, NOT here */ + + g_signal_pending = sig; } diff --git a/src/core.cc b/src/core.cc index 90ed9c59..7d8ae428 100644 --- a/src/core.cc +++ b/src/core.cc @@ -795,8 +795,6 @@ struct text_object *construct_text_object(char *s, const char *arg, long obj->thread = true; obj->callbacks.print = &print_execi; obj->callbacks.free = &free_execi; - END OBJ(pre_exec, 0) - scan_pre_exec_arg(obj, arg); END OBJ(fs_bar, &update_fs_stats) init_fs_bar(obj, arg); obj->callbacks.barval = &fs_barval; diff --git a/src/exec.cc b/src/exec.cc index e2866b87..10f47d83 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -33,29 +33,34 @@ #include "logging.h" #include "specials.h" #include "text_object.h" -#include "timed-thread.h" #include #include #include #include +#include #include +#include "update-cb.hh" + +namespace { + class exec_cb: public conky::callback { + typedef conky::callback Base; + + protected: + virtual void work(); + + public: + exec_cb(uint32_t period, bool wait, const std::string &cmd) + : Base(period, wait, Base::Tuple(cmd)) + {} + }; +} struct execi_data { - double last_update; float interval; char *cmd; - char *buffer; - double data; - timed_thread_ptr p_timed_thread; - float barnum; - execi_data() : last_update(0), interval(0), cmd(0), buffer(0), data(0), barnum(0) {} + execi_data() : interval(0), cmd(0) {} }; -/* FIXME: this will probably not work, since the variable is being reused - * between different text objects. So when a process really hangs, it's PID - * will be overwritten at the next iteration. */ -pid_t childpid = 0; - //our own implementation of popen, the difference : the value of 'childpid' will be filled with //the pid of the running 'command'. This is useful if want to kill it when it hangs while reading //or writing to it. We have to kill it because pclose will wait until the process dies by itself @@ -100,6 +105,7 @@ static FILE* pid_popen(const char *command, const char *mode, pid_t *child) { //by dupping childend, the returned fd will have close-on-exec turned off if (dup(childend) == -1) perror("dup()"); + close(childend); execl("/bin/sh", "sh", "-c", command, (char *) NULL); _exit(EXIT_FAILURE); //child should die here, (normally execl will take care of this but it can fail) @@ -107,6 +113,29 @@ static FILE* pid_popen(const char *command, const char *mode, pid_t *child) { return fdopen(parentend, mode); } +void exec_cb::work() +{ + pid_t childpid; + std::string buf; + std::shared_ptr fp; + char b[0x1000]; + + if(FILE *t = pid_popen(std::get<0>(tuple).c_str(), "r", &childpid)) + fp.reset(t, fclose); + else + return; + + while(!feof(fp.get()) && !ferror(fp.get())) { + int length = fread(b, 1, sizeof b, fp.get()); + buf.append(b, length); + } + + if(*buf.rbegin() == '\n') + buf.resize(buf.size()-1); + + std::lock_guard l(result_mutex); + result = buf; +} //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat" //string has to end with \0 and it's length should fit in a int #define BACKSPACE 8 @@ -122,19 +151,11 @@ static void remove_deleted_chars(char *string){ } } -static inline double get_barnum(char *buf) +static inline double get_barnum(const char *buf) { - char *c = buf; double barnum; - while (*c) { - if (*c == '\001') { - *c = ' '; - } - c++; - } - - if (sscanf(buf, "%lf", &barnum) == 0) { + if (sscanf(buf, "%lf", &barnum) != 1) { NORM_ERR("reading exec value failed (perhaps it's not the " "correct format?)"); return 0.0; @@ -147,84 +168,6 @@ static inline double get_barnum(char *buf) return barnum; } -static inline void read_exec(const char *data, char *buf, const int size) -{ - FILE *fp; - - memset(buf, 0, size); - - if (!data) - return; - - alarm(active_update_interval()); - fp = pid_popen(data, "r", &childpid); - if(fp) { - int length; - - length = fread(buf, 1, size, fp); - fclose(fp); - buf[std::min(length, size-1)] = '\0'; - if (length > 0 && buf[length - 1] == '\n') { - buf[length - 1] = '\0'; - } - } else { - buf[0] = '\0'; - } - alarm(0); -} - -static double read_exec_barnum(const char *data) -{ - char *buf = NULL; - double barnum; - - buf = (char*)malloc(text_buffer_size.get(*state)); - - read_exec(data, buf, text_buffer_size.get(*state)); - barnum = get_barnum(buf); - free(buf); - - return barnum; -} - -static void threaded_exec(thread_handle &handle, struct text_object *obj) -{ - char *buff, *p2; - struct execi_data *ed = (struct execi_data *)obj->data.opaque; - - while (1) { - buff = (char*)malloc(text_buffer_size.get(*state)); - read_exec(ed->cmd, buff, text_buffer_size.get(*state)); - p2 = buff; - while (*p2) { - if (*p2 == '\001') { - *p2 = ' '; - } - p2++; - } - - { - std::lock_guard lock(handle.mutex()); - free_and_zero(ed->buffer); - ed->buffer = buff; - } - if (handle.test(0)) { - return; - } - } - /* never reached */ -} - -/* check the execi fields and return true if the given interval has passed */ -static int time_to_update(struct execi_data *ed) -{ - if (!ed->interval) - return 0; - if (current_update_time - ed->last_update >= ed->interval) - return 1; - return 0; -} - void scan_exec_arg(struct text_object *obj, const char *arg) { /* XXX: do real bar parsing here */ @@ -232,14 +175,6 @@ void scan_exec_arg(struct text_object *obj, const char *arg) obj->data.s = strndup(arg ? arg : "", text_buffer_size.get(*state)); } -void scan_pre_exec_arg(struct text_object *obj, const char *arg) -{ - char buf[2048]; - - read_exec(arg, buf, sizeof(buf)); - obj_be_plain_text(obj, buf); -} - void scan_execi_arg(struct text_object *obj, const char *arg) { struct execi_data *ed; @@ -289,7 +224,7 @@ void scan_execgraph_arg(struct text_object *obj, const char *arg) } #endif /* BUILD_X11 */ -void fill_p(char *buffer, struct text_object *obj, char *p, int p_max_size) { +void fill_p(const char *buffer, struct text_object *obj, char *p, int p_max_size) { if(obj->parse == true) { evaluate(buffer, p, p_max_size); } else snprintf(p, p_max_size, "%s", buffer); @@ -298,53 +233,28 @@ void fill_p(char *buffer, struct text_object *obj, char *p, int p_max_size) { void print_exec(struct text_object *obj, char *p, int p_max_size) { - char *buf; - - buf = (char*)malloc(text_buffer_size.get(*state)); - memset(buf, 0, text_buffer_size.get(*state)); - - read_exec(obj->data.s, buf, text_buffer_size.get(*state)); - fill_p(buf, obj, p, p_max_size); - free(buf); + auto cb = conky::register_cb(1, true, obj->data.s); + fill_p(cb->get_result_copy().c_str(), obj, p, p_max_size); } void print_execi(struct text_object *obj, char *p, int p_max_size) { struct execi_data *ed = (struct execi_data *)obj->data.opaque; - bool fillbuffer = true; if (!ed) return; - if(obj->thread == true) { - if (!ed->p_timed_thread) { - /* - * note that we don't register this thread with the - * timed_thread list, because we destroy it manually - */ - ed->p_timed_thread = timed_thread::create(std::bind(threaded_exec, std::placeholders::_1, obj), - std::chrono::microseconds(long(ed->interval * 1000000)), false); - if (!ed->p_timed_thread) { - NORM_ERR("Error creating texeci timed thread"); - } - fillbuffer = false; - } else { - std::lock_guard lock(ed->p_timed_thread->mutex()); - } - } else { - if (time_to_update(ed)) { - if (!ed->buffer) - ed->buffer = (char*)malloc(text_buffer_size.get(*state)); - read_exec(ed->cmd, ed->buffer, text_buffer_size.get(*state)); - ed->last_update = current_update_time; - } - } - if(fillbuffer) fill_p(ed->buffer, obj, p, p_max_size); + uint32_t period = std::max(std::lround(ed->interval/active_update_interval()), 1l); + + auto cb = conky::register_cb(period, !obj->thread, ed->cmd); + + fill_p(cb->get_result_copy().c_str(), obj, p, p_max_size); } double execbarval(struct text_object *obj) { - return read_exec_barnum(obj->data.s); + auto cb = conky::register_cb(1, true, obj->data.s); + return get_barnum(cb->get_result_copy().c_str()); } double execi_barval(struct text_object *obj) @@ -354,11 +264,11 @@ double execi_barval(struct text_object *obj) if (!ed) return 0; - if (time_to_update(ed)) { - ed->barnum = read_exec_barnum(ed->cmd); - ed->last_update = current_update_time; - } - return ed->barnum; + uint32_t period = std::max(std::lround(ed->interval/active_update_interval()), 1l); + + auto cb = conky::register_cb(period, !obj->thread, ed->cmd); + + return get_barnum(cb->get_result_copy().c_str()); } void free_exec(struct text_object *obj) @@ -373,11 +283,7 @@ void free_execi(struct text_object *obj) if (!ed) return; - if (ed->p_timed_thread) { - ed->p_timed_thread.reset(); - } free_and_zero(ed->cmd); - free_and_zero(ed->buffer); delete ed; obj->data.opaque = NULL; } diff --git a/src/exec.h b/src/exec.h index 173b72aa..1e637f3d 100644 --- a/src/exec.h +++ b/src/exec.h @@ -31,20 +31,15 @@ #ifndef _EXEC_H #define _EXEC_H -extern pid_t childpid; +#include "text_object.h" void scan_exec_arg(struct text_object *, const char *); -void scan_pre_exec_arg(struct text_object *, const char *); void scan_execi_arg(struct text_object *, const char *); void scan_execi_bar_arg(struct text_object *, const char *); void scan_execi_gauge_arg(struct text_object *, const char *); void scan_execgraph_arg(struct text_object *, const char *); void print_exec(struct text_object *, char *, int); -void print_execp(struct text_object *, char *, int); void print_execi(struct text_object *, char *, int); -void print_execpi(struct text_object *, char *, int); -void print_texeci(struct text_object *, char *, int); -void print_texecpi(struct text_object *, char *, int); double execbarval(struct text_object *); double execi_barval(struct text_object *); void free_exec(struct text_object *);