mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-24 15:48:28 +00:00
Make it possible to use other vars as arguments for the $pid-vars, add support for $pid_state_short, add support for $cmdline_to_pid
This commit is contained in:
parent
e582acf1a0
commit
fa459f0539
@ -1,5 +1,7 @@
|
||||
2009-11-14
|
||||
* Added support for $pid_state
|
||||
* Added support for $pid_state and $pid_state_short
|
||||
* Added support for $cmdline_to_pid
|
||||
* Make it possible to use other vars as arguments for the $pid_'s
|
||||
|
||||
2009-11-13
|
||||
* Add $conky_user_time (sf.net #2830919)
|
||||
|
@ -533,6 +533,16 @@
|
||||
<listitem>Amount of memory cached
|
||||
<para /></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command>
|
||||
<option>cmdline_to_pid</option>
|
||||
</command>
|
||||
<option>pid</option>
|
||||
</term>
|
||||
<listitem>PID of process invoked with this command line
|
||||
<para /></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command>
|
||||
@ -2570,6 +2580,19 @@
|
||||
<listitem>State of the process
|
||||
<para /></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command>
|
||||
<option>pid_state_short</option>
|
||||
</command>
|
||||
<option>pid</option>
|
||||
</term>
|
||||
<listitem>One of the chars in "RSDZTW" representing the state
|
||||
of the process where R is running, S is sleeping in an
|
||||
interruptible wait, D is waiting in uninterruptible disk sleep,
|
||||
Z is zombie, T is traced or stopped (on a signal), and W is paging
|
||||
<para /></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command>
|
||||
|
@ -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|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|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|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|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|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|membar|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|nameserver|new_mails|nodename|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_openfiles|pid_state|pid_stderr|pid_stdin|pid_stdout|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|replied_mails|rss|running_processes|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|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|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|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|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|include|ioscheduler|kernel|laptop_mode|lines|loadavg|loadgraph|lua|lua_bar|lua_gauge|lua_graph|lua_parse|machine|mails|mboxscan|mem|membar|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|nameserver|new_mails|nodename|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_openfiles|pid_state|pid_state_short|pid_stderr|pid_stdin|pid_stdout|platform|pop3_unseen|pop3_used|pre_exec|processes|read_tcp|replied_mails|rss|running_processes|scroll|seen_mails|shadecolor|smapi|smapi_bat_bar|smapi_bat_perc|smapi_bat_power|smapi_bat_temp|sony_fanspeed|stippled_hr|swap|swapbar|swapfree|swapmax|swapperc|sysname|tab|tail|tcp_portmon|template0|template1|template2|template3|template4|template5|template6|template7|template8|template9|texeci|threads|time|to_bytes|top|top_io|top_mem|top_time|totaldown|totalup|trashed_mails|tztime|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 "(\{|\}|\(|\)|\;|\]|\[|`|\\|\$|<|>|!|=|&|\|)"
|
||||
|
@ -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 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 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 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 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 include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem membar 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 nameserver new_mails nodename 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_openfiles pid_state pid_stderr pid_stdin pid_stdout platform pop3_unseen pop3_used pre_exec processes read_tcp replied_mails rss running_processes scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime 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 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 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 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 include ioscheduler kernel laptop_mode lines loadavg loadgraph lua lua_bar lua_gauge lua_graph lua_parse machine mails mboxscan mem membar 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 nameserver new_mails nodename 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_openfiles pid_state pid_state_short pid_stderr pid_stdin pid_stdout platform pop3_unseen pop3_used pre_exec processes read_tcp replied_mails rss running_processes scroll seen_mails shadecolor smapi smapi_bat_bar smapi_bat_perc smapi_bat_power smapi_bat_temp sony_fanspeed stippled_hr swap swapbar swapfree swapmax swapperc sysname tab tail tcp_portmon template0 template1 template2 template3 template4 template5 template6 template7 template8 template9 texeci threads time to_bytes top top_io top_mem top_time totaldown totalup trashed_mails tztime 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
|
||||
|
54
src/conky.c
54
src/conky.c
@ -916,6 +916,9 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
OBJ(cached) {
|
||||
human_readable(cur->cached * 1024, p, 255);
|
||||
}
|
||||
OBJ(cmdline_to_pid) {
|
||||
print_cmdline_to_pid(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(cpu) {
|
||||
if (obj->data.i > info.cpu_count) {
|
||||
NORM_ERR("obj->data.i %i info.cpu_count %i",
|
||||
@ -1601,36 +1604,87 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
new_outline(p, obj->data.l);
|
||||
}
|
||||
OBJ(pid_chroot) {
|
||||
char buf[max_user_text];
|
||||
|
||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
||||
obj->data.s = buf;
|
||||
print_pid_chroot(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(pid_cmdline) {
|
||||
char buf[max_user_text];
|
||||
|
||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
||||
obj->data.s = buf;
|
||||
print_pid_cmdline(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(pid_cwd) {
|
||||
char buf[max_user_text];
|
||||
|
||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
||||
obj->data.s = buf;
|
||||
print_pid_cwd(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(pid_environ) {
|
||||
char buf[max_user_text];
|
||||
|
||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
||||
obj->data.s = buf;
|
||||
print_pid_environ(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(pid_environ_list) {
|
||||
char buf[max_user_text];
|
||||
|
||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
||||
obj->data.s = buf;
|
||||
print_pid_environ_list(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(pid_exe) {
|
||||
char buf[max_user_text];
|
||||
|
||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
||||
obj->data.s = buf;
|
||||
print_pid_exe(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(pid_openfiles) {
|
||||
char buf[max_user_text];
|
||||
|
||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
||||
obj->data.s = buf;
|
||||
print_pid_openfiles(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(pid_state) {
|
||||
char buf[max_user_text];
|
||||
|
||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
||||
obj->data.s = buf;
|
||||
print_pid_state(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(pid_state_short) {
|
||||
char buf[max_user_text];
|
||||
|
||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
||||
obj->data.s = buf;
|
||||
print_pid_state_short(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(pid_stderr) {
|
||||
char buf[max_user_text];
|
||||
|
||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
||||
obj->data.s = buf;
|
||||
print_pid_stderr(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(pid_stdin) {
|
||||
char buf[max_user_text];
|
||||
|
||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
||||
obj->data.s = buf;
|
||||
print_pid_stdin(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(pid_stdout) {
|
||||
char buf[max_user_text];
|
||||
|
||||
generate_text_internal(buf, max_user_text, *obj->sub, cur);
|
||||
obj->data.s = buf;
|
||||
print_pid_stdout(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(processes) {
|
||||
|
69
src/core.c
69
src/core.c
@ -642,28 +642,44 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
||||
END OBJ(desktop_name, &update_x11info)
|
||||
#endif
|
||||
END OBJ(nodename, 0)
|
||||
END OBJ_ARG(cmdline_to_pid, 0, "cmdline_to_pid needs a command line as argument")
|
||||
scan_cmdline_to_pid_arg(obj, arg, free_at_crash);
|
||||
END OBJ_ARG(pid_chroot, 0, "pid_chroot needs a pid as argument")
|
||||
scan_pid_chroot_arg(obj, arg, free_at_crash);
|
||||
obj->sub = malloc(sizeof(struct text_object));
|
||||
extract_variable_text_internal(obj->sub, arg);
|
||||
END OBJ_ARG(pid_cmdline, 0, "pid_cmdline needs a pid as argument")
|
||||
scan_pid_cmdline_arg(obj, arg, free_at_crash);
|
||||
obj->sub = malloc(sizeof(struct text_object));
|
||||
extract_variable_text_internal(obj->sub, arg);
|
||||
END OBJ_ARG(pid_cwd, 0, "pid_cwd needs a pid as argument")
|
||||
scan_pid_cwd_arg(obj, arg, free_at_crash);
|
||||
obj->sub = malloc(sizeof(struct text_object));
|
||||
extract_variable_text_internal(obj->sub, arg);
|
||||
END OBJ_ARG(pid_environ, 0, "pid_environ needs arguments")
|
||||
scan_pid_environ_arg(obj, arg, free_at_crash);
|
||||
obj->sub = malloc(sizeof(struct text_object));
|
||||
extract_variable_text_internal(obj->sub, arg);
|
||||
END OBJ_ARG(pid_environ_list, 0, "pid_environ_list needs a pid as argument")
|
||||
scan_pid_environ_list_arg(obj, arg, free_at_crash);
|
||||
obj->sub = malloc(sizeof(struct text_object));
|
||||
extract_variable_text_internal(obj->sub, arg);
|
||||
END OBJ_ARG(pid_exe, 0, "pid_exe needs a pid as argument")
|
||||
scan_pid_exe_arg(obj, arg, free_at_crash);
|
||||
obj->sub = malloc(sizeof(struct text_object));
|
||||
extract_variable_text_internal(obj->sub, arg);
|
||||
END OBJ_ARG(pid_openfiles, 0, "pid_openfiles needs a pid as argument")
|
||||
scan_pid_openfiles_arg(obj, arg, free_at_crash);
|
||||
obj->sub = malloc(sizeof(struct text_object));
|
||||
extract_variable_text_internal(obj->sub, arg);
|
||||
END OBJ_ARG(pid_state, 0, "pid_state needs a pid as argument")
|
||||
scan_pid_state_arg(obj, arg, free_at_crash);
|
||||
obj->sub = malloc(sizeof(struct text_object));
|
||||
extract_variable_text_internal(obj->sub, arg);
|
||||
END OBJ_ARG(pid_state_short, 0, "pid_state_short needs a pid as argument")
|
||||
obj->sub = malloc(sizeof(struct text_object));
|
||||
extract_variable_text_internal(obj->sub, arg);
|
||||
END OBJ_ARG(pid_stderr, 0, "pid_stderr needs a pid as argument")
|
||||
scan_pid_stderr_arg(obj, arg, free_at_crash);
|
||||
obj->sub = malloc(sizeof(struct text_object));
|
||||
extract_variable_text_internal(obj->sub, arg);
|
||||
END OBJ_ARG(pid_stdin, 0, "pid_stdin needs a pid as argument")
|
||||
scan_pid_stdin_arg(obj, arg, free_at_crash);
|
||||
obj->sub = malloc(sizeof(struct text_object));
|
||||
extract_variable_text_internal(obj->sub, arg);
|
||||
END OBJ_ARG(pid_stdout, 0, "pid_stdout needs a pid as argument")
|
||||
scan_pid_stdout_arg(obj, arg, free_at_crash);
|
||||
obj->sub = malloc(sizeof(struct text_object));
|
||||
extract_variable_text_internal(obj->sub, arg);
|
||||
END OBJ(processes, &update_total_processes)
|
||||
END OBJ(running_processes, &update_running_processes)
|
||||
END OBJ(threads, &update_threads)
|
||||
@ -1254,38 +1270,25 @@ void free_text_objects(struct text_object *root, int internal)
|
||||
free_sysfs_sensor(obj);
|
||||
break;
|
||||
#endif /* __linux__ */
|
||||
case OBJ_pid_chroot:
|
||||
free(data.s);
|
||||
break;
|
||||
case OBJ_pid_cmdline:
|
||||
free(data.s);
|
||||
break;
|
||||
case OBJ_pid_cwd:
|
||||
case OBJ_cmdline_to_pid:
|
||||
free(data.s);
|
||||
break;
|
||||
case OBJ_pid_environ:
|
||||
free_pid_environ(obj);
|
||||
break;
|
||||
case OBJ_pid_chroot:
|
||||
case OBJ_pid_cmdline:
|
||||
case OBJ_pid_cwd:
|
||||
case OBJ_pid_environ_list:
|
||||
free(data.s);
|
||||
break;
|
||||
case OBJ_pid_exe:
|
||||
free(data.s);
|
||||
break;
|
||||
case OBJ_pid_openfiles:
|
||||
free(data.s);
|
||||
break;
|
||||
case OBJ_pid_state:
|
||||
free(data.s);
|
||||
break;
|
||||
case OBJ_pid_state_short:
|
||||
case OBJ_pid_stderr:
|
||||
free(data.s);
|
||||
break;
|
||||
case OBJ_pid_stdin:
|
||||
free(data.s);
|
||||
break;
|
||||
case OBJ_pid_stdout:
|
||||
free(data.s);
|
||||
if(obj->sub) {
|
||||
free_text_objects(obj->sub, 1);
|
||||
free(obj->sub);
|
||||
}
|
||||
break;
|
||||
case OBJ_read_tcp:
|
||||
free_read_tcp(obj);
|
||||
|
427
src/proc.c
427
src/proc.c
@ -35,23 +35,7 @@
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
|
||||
void scan_pid_arg(struct text_object *obj, const char *arg, void* free_at_crash, const char *file)
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
if(sscanf(arg, "%d", &pid) == 1) {
|
||||
asprintf(&obj->data.s, PROCDIR "/%d/%s", pid, file);
|
||||
} else {
|
||||
CRIT_ERR(obj, free_at_crash, "syntax error: ${pid_%s pid}", file);
|
||||
}
|
||||
}
|
||||
|
||||
void scan_pid_cmdline_arg(struct text_object *obj, const char *arg, void* free_at_crash)
|
||||
{
|
||||
scan_pid_arg(obj, arg, free_at_crash, "cmdline");
|
||||
}
|
||||
|
||||
char* readfile(char* filename, int* total_read) {
|
||||
char* readfile(char* filename, int* total_read, char showerror) {
|
||||
FILE* file;
|
||||
char* buf = NULL;
|
||||
int bytes_read;
|
||||
@ -66,203 +50,24 @@ char* readfile(char* filename, int* total_read) {
|
||||
buf[*total_read] = 0;
|
||||
}while(bytes_read != 0);
|
||||
fclose(file);
|
||||
} else {
|
||||
} else if(showerror != 0) {
|
||||
NORM_ERR(READERR, filename);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
char* buf;
|
||||
int i, bytes_read;
|
||||
|
||||
buf = readfile(obj->data.s, &bytes_read);
|
||||
if(buf != NULL) {
|
||||
for(i = 0; i < bytes_read-1; i++) {
|
||||
if(buf[i] == 0) {
|
||||
buf[i] = ' ';
|
||||
}
|
||||
}
|
||||
snprintf(p, p_max_size, "%s", buf);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void scan_pid_cwd_arg(struct text_object *obj, const char *arg, void* free_at_crash)
|
||||
{
|
||||
scan_pid_arg(obj, arg, free_at_crash, "cwd");
|
||||
}
|
||||
|
||||
void print_pid_cwd(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
char buf[p_max_size];
|
||||
int bytes_read;
|
||||
|
||||
memset(buf, 0, p_max_size);
|
||||
bytes_read = readlink(obj->data.s, buf, p_max_size);
|
||||
if(bytes_read != -1) {
|
||||
snprintf(p, p_max_size, "%s", buf);
|
||||
} else {
|
||||
NORM_ERR(READERR, obj->data.s);
|
||||
}
|
||||
}
|
||||
|
||||
void scan_pid_environ_arg(struct text_object *obj, const char *arg, void* free_at_crash)
|
||||
{
|
||||
pid_t pid;
|
||||
int i;
|
||||
struct environ_data* ed = malloc(sizeof(struct environ_data));
|
||||
|
||||
ed->var = malloc(strlen(arg));
|
||||
if(sscanf(arg, "%d %s", &pid, ed->var) == 2) {
|
||||
asprintf(&ed->file, PROCDIR "/%d/environ", pid);
|
||||
for(i = 0; ed->var[i] != 0; i++) {
|
||||
ed->var[i] = toupper(ed->var[i]);
|
||||
}
|
||||
obj->data.opaque = ed;
|
||||
} else {
|
||||
free(ed->var);
|
||||
free(ed);
|
||||
CRIT_ERR(obj, free_at_crash, "${pid_environ pid varname}");
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_environ(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
char *buf = NULL;
|
||||
char *searchstring = ((struct environ_data*) obj->data.opaque)->var;
|
||||
int bytes_read, total_read = 0;
|
||||
|
||||
buf = readfile(((struct environ_data*) obj->data.opaque)->file, &total_read);
|
||||
if(buf != NULL) {
|
||||
for(bytes_read = 0; bytes_read < total_read; bytes_read += strlen(buf + bytes_read) + 1) {
|
||||
if(strncmp(buf + bytes_read, searchstring, strlen(searchstring)) == 0 && *(buf + bytes_read + strlen(searchstring)) == '=') {
|
||||
snprintf(p, p_max_size, "%s", buf + bytes_read + strlen(searchstring) + 1);
|
||||
free(buf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
p[0] = 0;
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void free_pid_environ(struct text_object *obj) {
|
||||
free(((struct environ_data*) obj->data.opaque)->file);
|
||||
free(((struct environ_data*) obj->data.opaque)->var);
|
||||
free(obj->data.opaque);
|
||||
}
|
||||
|
||||
void scan_pid_environ_list_arg(struct text_object *obj, const char *arg, void* free_at_crash)
|
||||
{
|
||||
scan_pid_arg(obj, arg, free_at_crash, "environ");
|
||||
}
|
||||
|
||||
void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
char *buf = NULL;
|
||||
char *buf2;
|
||||
int bytes_read, total_read;
|
||||
int i = 0;
|
||||
|
||||
buf = readfile(obj->data.s, &total_read);
|
||||
if(buf != NULL) {
|
||||
for(bytes_read = 0; bytes_read < total_read; buf[i-1] = ';') {
|
||||
buf2 = strdup(buf+bytes_read);
|
||||
bytes_read += strlen(buf2)+1;
|
||||
sscanf(buf2, "%[^=]", buf+i);
|
||||
free(buf2);
|
||||
i = strlen(buf) + 1;
|
||||
}
|
||||
buf[i-1] = 0;
|
||||
snprintf(p, p_max_size, "%s", buf);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void scan_pid_exe_arg(struct text_object *obj, const char *arg, void* free_at_crash)
|
||||
{
|
||||
scan_pid_arg(obj, arg, free_at_crash, "exe");
|
||||
}
|
||||
|
||||
void print_pid_readlink(struct text_object *obj, char *p, int p_max_size)
|
||||
void pid_readlink(char *file, char *p, int p_max_size)
|
||||
{
|
||||
char buf[p_max_size];
|
||||
|
||||
memset(buf, 0, p_max_size);
|
||||
if(readlink(obj->data.s, buf, p_max_size) >= 0) {
|
||||
if(readlink(file, buf, p_max_size) >= 0) {
|
||||
snprintf(p, p_max_size, "%s", buf);
|
||||
} else {
|
||||
NORM_ERR(READERR, obj->data.s);
|
||||
NORM_ERR(READERR, file);
|
||||
}
|
||||
}
|
||||
|
||||
void scan_pid_chroot_arg(struct text_object *obj, const char *arg, void* free_at_crash) {
|
||||
scan_pid_arg(obj, arg, free_at_crash, "root");
|
||||
}
|
||||
|
||||
void print_pid_chroot(struct text_object *obj, char *p, int p_max_size) {
|
||||
print_pid_readlink(obj, p, p_max_size);
|
||||
}
|
||||
|
||||
void print_pid_exe(struct text_object *obj, char *p, int p_max_size) {
|
||||
print_pid_readlink(obj, p, p_max_size);
|
||||
}
|
||||
|
||||
void scan_pid_state_arg(struct text_object *obj, const char *arg, void* free_at_crash) {
|
||||
scan_pid_arg(obj, arg, free_at_crash, "status");
|
||||
}
|
||||
|
||||
void print_pid_state(struct text_object *obj, char *p, int p_max_size) {
|
||||
char *begin, *end, *buf = NULL;
|
||||
int bytes_read;
|
||||
|
||||
buf = readfile(obj->data.s, &bytes_read);
|
||||
if(buf != NULL) {
|
||||
begin = strstr(buf, STATE_ENTRY);
|
||||
if(begin != NULL) {
|
||||
begin += strlen(STATE_ENTRY) + 3; // +3 will strip the char representing the short state and the space and '(' that follow
|
||||
end = strchr(begin, '\n');
|
||||
if(end != NULL) {
|
||||
*(end-1) = 0;
|
||||
}
|
||||
snprintf(p, p_max_size, "%s", begin);
|
||||
} else {
|
||||
NORM_ERR(STATENOTFOUND, obj->data.s);
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void scan_pid_stderr_arg(struct text_object *obj, const char *arg, void* free_at_crash) {
|
||||
scan_pid_arg(obj, arg, free_at_crash, "fd/2");
|
||||
}
|
||||
|
||||
void print_pid_stderr(struct text_object *obj, char *p, int p_max_size) {
|
||||
print_pid_readlink(obj, p, p_max_size);
|
||||
}
|
||||
|
||||
void scan_pid_stdin_arg(struct text_object *obj, const char *arg, void* free_at_crash) {
|
||||
scan_pid_arg(obj, arg, free_at_crash, "fd/0");
|
||||
}
|
||||
|
||||
void print_pid_stdin(struct text_object *obj, char *p, int p_max_size) {
|
||||
print_pid_readlink(obj, p, p_max_size);
|
||||
}
|
||||
|
||||
void scan_pid_stdout_arg(struct text_object *obj, const char *arg, void* free_at_crash) {
|
||||
scan_pid_arg(obj, arg, free_at_crash, "fd/1");
|
||||
}
|
||||
|
||||
void print_pid_stdout(struct text_object *obj, char *p, int p_max_size) {
|
||||
print_pid_readlink(obj, p, p_max_size);
|
||||
}
|
||||
|
||||
void scan_pid_openfiles_arg(struct text_object *obj, const char *arg, void* free_at_crash) {
|
||||
scan_pid_arg(obj, arg, free_at_crash, "fd");
|
||||
}
|
||||
|
||||
struct ll_string {
|
||||
char *string;
|
||||
struct ll_string* next;
|
||||
@ -297,6 +102,112 @@ int inlist(struct ll_string* front, char* string) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_pid_chroot(struct text_object *obj, char *p, int p_max_size) {
|
||||
char *buffer;
|
||||
|
||||
asprintf(&buffer, PROCDIR "/%s/root", obj->data.s);
|
||||
print_pid_readlink(buffer, p, p_max_size);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
char* buf;
|
||||
int i, bytes_read;
|
||||
|
||||
asprintf(&buf, PROCDIR "/%s/cmdline", obj->data.s);
|
||||
strcpy(obj->data.s, buf);
|
||||
free(buf);
|
||||
buf = readfile(obj->data.s, &bytes_read, 1);
|
||||
if(buf != NULL) {
|
||||
for(i = 0; i < bytes_read-1; i++) {
|
||||
if(buf[i] == 0) {
|
||||
buf[i] = ' ';
|
||||
}
|
||||
}
|
||||
snprintf(p, p_max_size, "%s", buf);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_cwd(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
char buf[p_max_size];
|
||||
int bytes_read;
|
||||
|
||||
sprintf(buf, PROCDIR "/%s/cwd", obj->data.s);
|
||||
strcpy(obj->data.s, buf);
|
||||
bytes_read = readlink(obj->data.s, buf, p_max_size);
|
||||
if(bytes_read != -1) {
|
||||
buf[bytes_read] = 0;
|
||||
snprintf(p, p_max_size, "%s", buf);
|
||||
} else {
|
||||
NORM_ERR(READERR, obj->data.s);
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_environ(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
int i, total_read;
|
||||
pid_t pid;
|
||||
char *buf, *file, *var=strdup(obj->data.s);;
|
||||
|
||||
if(sscanf(obj->data.s, "%d %s", &pid, var) == 2) {
|
||||
for(i = 0; var[i] != 0; i++) {
|
||||
var[i] = toupper(var[i]);
|
||||
}
|
||||
asprintf(&file, PROCDIR "/%d/environ", pid);
|
||||
buf = readfile(file, &total_read, 1);
|
||||
free(file);
|
||||
if(buf != NULL) {
|
||||
for(i = 0; i < total_read; i += strlen(buf + i) + 1) {
|
||||
if(strncmp(buf + i, var, strlen(var)) == 0 && *(buf + i + strlen(var)) == '=') {
|
||||
snprintf(p, p_max_size, "%s", buf + i + strlen(var) + 1);
|
||||
free(buf);
|
||||
free(var);
|
||||
return;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
free(var);
|
||||
*p = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
char *buf = NULL;
|
||||
char *buf2;
|
||||
int bytes_read, total_read;
|
||||
int i = 0;
|
||||
|
||||
asprintf(&buf, PROCDIR "/%s/environ", obj->data.s);
|
||||
strcpy(obj->data.s, buf);
|
||||
free(buf);
|
||||
buf = readfile(obj->data.s, &total_read, 1);
|
||||
if(buf != NULL) {
|
||||
for(bytes_read = 0; bytes_read < total_read; buf[i-1] = ';') {
|
||||
buf2 = strdup(buf+bytes_read);
|
||||
bytes_read += strlen(buf2)+1;
|
||||
sscanf(buf2, "%[^=]", buf+i);
|
||||
free(buf2);
|
||||
i = strlen(buf) + 1;
|
||||
}
|
||||
buf[i-1] = 0;
|
||||
snprintf(p, p_max_size, "%s", buf);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_exe(struct text_object *obj, char *p, int p_max_size) {
|
||||
char *buffer;
|
||||
|
||||
asprintf(&buffer, PROCDIR "/%s/exe", obj->data.s);
|
||||
print_pid_readlink(buffer, p, p_max_size);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size) {
|
||||
DIR* dir;
|
||||
struct dirent *entry;
|
||||
@ -329,3 +240,119 @@ void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size) {
|
||||
p[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_state(struct text_object *obj, char *p, int p_max_size) {
|
||||
char *begin, *end, *buf = NULL;
|
||||
int bytes_read;
|
||||
|
||||
asprintf(&buf, PROCDIR "/%s/status", obj->data.s);
|
||||
strcpy(obj->data.s, buf);
|
||||
free(buf);
|
||||
buf = readfile(obj->data.s, &bytes_read, 1);
|
||||
if(buf != NULL) {
|
||||
begin = strstr(buf, STATE_ENTRY);
|
||||
if(begin != NULL) {
|
||||
begin += strlen(STATE_ENTRY) + 3; // +3 will strip the char representing the short state and the space and '(' that follow
|
||||
end = strchr(begin, '\n');
|
||||
if(end != NULL) {
|
||||
*(end-1) = 0;
|
||||
}
|
||||
snprintf(p, p_max_size, "%s", begin);
|
||||
} else {
|
||||
NORM_ERR(STATENOTFOUND, obj->data.s);
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_state_short(struct text_object *obj, char *p, int p_max_size) {
|
||||
char *begin, *buf = NULL;
|
||||
int bytes_read;
|
||||
|
||||
asprintf(&buf, PROCDIR "/%s/status", obj->data.s);
|
||||
strcpy(obj->data.s, buf);
|
||||
free(buf);
|
||||
buf = readfile(obj->data.s, &bytes_read, 1);
|
||||
if(buf != NULL) {
|
||||
begin = strstr(buf, STATE_ENTRY);
|
||||
if(begin != NULL) {
|
||||
snprintf(p, p_max_size, "%c", *begin);
|
||||
} else {
|
||||
NORM_ERR(STATENOTFOUND, obj->data.s);
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void print_pid_stderr(struct text_object *obj, char *p, int p_max_size) {
|
||||
char *buffer;
|
||||
|
||||
asprintf(&buffer, PROCDIR "/%s/fd/2", obj->data.s);
|
||||
print_pid_readlink(buffer, p, p_max_size);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
void print_pid_stdin(struct text_object *obj, char *p, int p_max_size) {
|
||||
char *buffer;
|
||||
|
||||
asprintf(&buffer, PROCDIR "/%s/fd/0", obj->data.s);
|
||||
print_pid_readlink(buffer, p, p_max_size);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
void print_pid_stdout(struct text_object *obj, char *p, int p_max_size) {
|
||||
char *buffer;
|
||||
|
||||
asprintf(&buffer, PROCDIR "/%s/fd/1", obj->data.s);
|
||||
print_pid_readlink(buffer, p, p_max_size);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg, void* free_at_crash) {
|
||||
unsigned int i;
|
||||
|
||||
if(strlen(arg) > 0) {
|
||||
obj->data.s = strdup(arg);
|
||||
for(i = 0; obj->data.s[i] != 0; i++) {
|
||||
while(obj->data.s[i] == ' ' && obj->data.s[i + 1] == ' ') {
|
||||
memmove(obj->data.s + i, obj->data.s + i + 1, strlen(obj->data.s + i + 1) + 1);
|
||||
}
|
||||
}
|
||||
if(obj->data.s[i - 1] == ' ') {
|
||||
obj->data.s[i - 1] = 0;
|
||||
}
|
||||
} else {
|
||||
CRIT_ERR(obj, free_at_crash, "${cmdline_to_pid commandline}");
|
||||
}
|
||||
}
|
||||
|
||||
void print_cmdline_to_pid(struct text_object *obj, char *p, int p_max_size) {
|
||||
DIR* dir;
|
||||
struct dirent *entry;
|
||||
char *filename, *buf;
|
||||
int bytes_read, i;
|
||||
|
||||
dir = opendir(PROCDIR);
|
||||
if(dir != NULL) {
|
||||
while ((entry = readdir(dir))) {
|
||||
asprintf(&filename, PROCDIR "/%s/cmdline", entry->d_name);
|
||||
buf = readfile(filename, &bytes_read, 0);
|
||||
free(filename);
|
||||
if(buf != NULL) {
|
||||
for(i = 0; i < bytes_read - 1; i++) {
|
||||
if(buf[i] == 0) buf[i] = ' ';
|
||||
}
|
||||
if(strcmp(buf, obj->data.s) == 0) {
|
||||
snprintf(p, p_max_size, "%s", entry->d_name);
|
||||
free(buf);
|
||||
closedir(dir);
|
||||
return;
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
} else {
|
||||
NORM_ERR(READERR, PROCDIR);
|
||||
}
|
||||
}
|
||||
|
32
src/proc.h
32
src/proc.h
@ -34,42 +34,18 @@
|
||||
#define READSIZE 128
|
||||
#define STATE_ENTRY "State:\t"
|
||||
|
||||
struct environ_data {
|
||||
char *file;
|
||||
char *var;
|
||||
};
|
||||
|
||||
void scan_pid_chroot_arg(struct text_object *obj, const char *arg, void* free_at_crash);
|
||||
void print_pid_chroot(struct text_object *obj, char *p, int p_max_size);
|
||||
|
||||
void scan_pid_cmdline_arg(struct text_object *obj, const char *arg, void* free_at_crash);
|
||||
void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size);
|
||||
|
||||
void scan_pid_cwd_arg(struct text_object *obj, const char *arg, void* free_at_crash);
|
||||
void print_pid_cwd(struct text_object *obj, char *p, int p_max_size);
|
||||
|
||||
void scan_pid_environ_arg(struct text_object *obj, const char *arg, void* free_at_crash);
|
||||
void print_pid_environ(struct text_object *obj, char *p, int p_max_size);
|
||||
|
||||
void free_pid_environ(struct text_object *obj);
|
||||
|
||||
void scan_pid_environ_list_arg(struct text_object *obj, const char *arg, void* free_at_crash);
|
||||
void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size);
|
||||
|
||||
void scan_pid_exe_arg(struct text_object *obj, const char *arg, void* free_at_crash);
|
||||
void print_pid_exe(struct text_object *obj, char *p, int p_max_size);
|
||||
|
||||
void scan_pid_state_arg(struct text_object *obj, const char *arg, void* free_at_crash);
|
||||
void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size);
|
||||
void print_pid_state(struct text_object *obj, char *p, int p_max_size);
|
||||
|
||||
void scan_pid_stderr_arg(struct text_object *obj, const char *arg, void* free_at_crash);
|
||||
void print_pid_state_short(struct text_object *obj, char *p, int p_max_size);
|
||||
void print_pid_stderr(struct text_object *obj, char *p, int p_max_size);
|
||||
|
||||
void scan_pid_stdin_arg(struct text_object *obj, const char *arg, void* free_at_crash);
|
||||
void print_pid_stdin(struct text_object *obj, char *p, int p_max_size);
|
||||
|
||||
void scan_pid_stdout_arg(struct text_object *obj, const char *arg, void* free_at_crash);
|
||||
void print_pid_stdout(struct text_object *obj, char *p, int p_max_size);
|
||||
|
||||
void scan_pid_openfiles_arg(struct text_object *obj, const char *arg, void* free_at_crash);
|
||||
void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size);
|
||||
void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg, void* free_at_crash);
|
||||
void print_cmdline_to_pid(struct text_object *obj, char *p, int p_max_size);
|
||||
|
@ -233,6 +233,7 @@ enum text_object_type {
|
||||
OBJ_nodename,
|
||||
OBJ_nvidia,
|
||||
OBJ_pre_exec,
|
||||
OBJ_cmdline_to_pid,
|
||||
OBJ_pid_chroot,
|
||||
OBJ_pid_cmdline,
|
||||
OBJ_pid_cwd,
|
||||
@ -241,6 +242,7 @@ enum text_object_type {
|
||||
OBJ_pid_exe,
|
||||
OBJ_pid_openfiles,
|
||||
OBJ_pid_state,
|
||||
OBJ_pid_state_short,
|
||||
OBJ_pid_stderr,
|
||||
OBJ_pid_stdin,
|
||||
OBJ_pid_stdout,
|
||||
|
Loading…
x
Reference in New Issue
Block a user