systemd / php-systemd

PHP extension allowing native interaction with systemd and its journal
MIT License
47 stars 13 forks source link

CODE_FILE/CODE_LINE/CODE_FUNC #2

Open glensc opened 10 years ago

glensc commented 10 years ago

could those values be adjusted to be addresses of php sourcecode, not C where it was compiled from?

[pid  2520] sendmsg(16, {msg_name(29)={sa_family=AF_LOCAL, sun_path="/run/systemd/journal/socket"}, msg_iov(11)=[{"MESSAGE=hello world", 19}, {"\n", 1}, {"CODE_FILE=/home/users/glen/relup/BUILD.x86_64-linux/php-systemd-0.1/systemd.c", 77}, {"\n", 1}, {"CODE_LINE=58", 12}, {"\n", 1}, {"CODE_FUNC=zif_sd_journal_send", 29}, {"\n", 1}, {"SYSLOG_IDENTIFIER=", 18}, {"php", 3}, {"\n", 1}], msg_controllen=0, msg_flags=0}, MSG_NOSIGNAL) = 163
davidstrauss commented 10 years ago

I'm not actually sure how to fix that for PHP.

glensc commented 10 years ago

could i provide same named attributes myself, or systemd c-library always overrides those? i mean perhaps it fills them if the code itself does not send?

glensc commented 10 years ago

at least it was worth to try. current answer is no:

$ echo "<?php echo sd_journal_send('MESSAGE=hello world', 'CODE_FILE=php.test.php', 'CODE_FUNC=phpfunc', 'CODE_LINE=1');" | strace -ff -esendmsg -s2000 php 
Process 14069 attached
Process 14070 attached
[pid 14070] +++ exited with 0 +++
[pid 14068] sendmsg(16, {msg_name(29)={sa_family=AF_LOCAL, sun_path="/run/systemd/journal/socket"}, msg_iov(17)=[{"MESSAGE=hello world", 19}, {"\n", 1}, {"CODE_FILE=php.test.php", 22}, {"\n", 1}, {"CODE_FUNC=phpfunc", 17}, {"\n", 1}, {"CODE_LINE=1", 11}, {"\n", 1}, {"CODE_FILE=/home/users/glen/relup/BUILD.x86_64-linux/php-systemd-0.1/systemd.c", 77}, {"\n", 1}, {"CODE_LINE=58", 12}, {"\n", 1}, {"CODE_FUNC=zif_sd_journal_send", 29}, {"\n", 1}, {"SYSLOG_IDENTIFIER=", 18}, {"php", 3}, {"\n", 1}], msg_controllen=0, msg_flags=0}, MSG_NOSIGNAL) = 216
1[pid 14069] +++ exited with 0 +++
+++ exited with 0 +++

but i think it should be something in similar manner. as not all journal messages contain CODE_FILE so it must be something that can be changed.

glensc commented 10 years ago

it seems to be configured at build time with SD_JOURNAL_SUPPRESS_LOCATION define: https://github.com/systemd/systemd/blob/v209/src/systemd/sd-journal.h#L53-60

so, perhaps just undefine them always to get access to original symbols? and do the php source code location extraction php way.

btw, i looked python binding, and it also fills the CODE_{FILE,LINE,FUNCTION} from python stracktrace if user hasn't specified them yet:

https://github.com/systemd/python-systemd/blob/master/systemd/journal.py#L46-54

glensc commented 10 years ago

oh wait, better define SD_JOURNAL_SUPPRESS_LOCATION instead of undefining functions, then it's likely future safe as well :)

davidstrauss commented 10 years ago

So, I know it's possible to inject a language-specific file and line. We already do this in python-systemd.

glensc commented 10 years ago

great!