php-systemd icon indicating copy to clipboard operation
php-systemd copied to clipboard

CODE_FILE/CODE_LINE/CODE_FUNC

Open glensc opened this issue 11 years ago • 7 comments

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

glensc avatar Mar 06 '14 18:03 glensc

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

davidstrauss avatar Mar 06 '14 20:03 davidstrauss

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 avatar Mar 06 '14 20:03 glensc

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 avatar Mar 06 '14 20:03 glensc

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 avatar Mar 06 '14 20:03 glensc

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

glensc avatar Mar 06 '14 20:03 glensc

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

davidstrauss avatar Mar 06 '14 21:03 davidstrauss

great!

glensc avatar Mar 06 '14 21:03 glensc