├── .gitignore ├── LICENSE.txt ├── README.md ├── config.m4 ├── php_systemd.h └── systemd.c /.gitignore: -------------------------------------------------------------------------------- 1 | #*# 2 | *.dsw 3 | *.la 4 | *.lo 5 | *.ncb 6 | *.opt 7 | *.plg 8 | *.tgz 9 | *~ 10 | .#* 11 | .deps 12 | .libs 13 | Debug 14 | Debug_TS 15 | Makefile 16 | Makefile.fragments 17 | Makefile.global 18 | Makefile.objects 19 | Release 20 | Release_TS 21 | Release_TSDbg 22 | Release_TS_inline 23 | Release_inline 24 | acinclude.m4 25 | aclocal.m4 26 | autom4te.cache 27 | build 28 | config.cache 29 | config.guess 30 | config.h 31 | config.h.in 32 | config.log 33 | config.nice 34 | config.status 35 | config.sub 36 | configure 37 | configure.in 38 | conftest 39 | conftest.c 40 | include 41 | install-sh 42 | libtool 43 | ltmain.sh 44 | missing 45 | mkinstalldirs 46 | modules 47 | scan_makefile_in.awk 48 | *.gcda 49 | *.gcno 50 | run-tests.php 51 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2012 David Strauss, david@davidstrauss.net 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | php-systemd 2 | =========== 3 | 4 | PHP extension allowing native interaction with systemd and journald 5 | 6 | Installation 7 | ------------ 8 | 9 | ### Prerequisites 10 | 11 | .deb based 12 | 13 | sudo apt install php5-dev libsystemd-dev 14 | 15 | .rpm based 16 | 17 | sudo dnf install php-devel systemd-devel 18 | 19 | ### Build 20 | 21 | phpize 22 | ./configure --with-systemd 23 | make 24 | 25 | ### Setup 26 | 27 | sudo make install 28 | 29 | Fedora 30 | 31 | echo "extension=systemd.so" | sudo tee /etc/php.d/systemd.ini 32 | 33 | Debian (PHP 5) 34 | 35 | echo "extension=systemd.so" | sudo tee /etc/php5/mods-available/systemd.ini 36 | sudo php5enmod systemd 37 | 38 | ### Basic Test 39 | 40 | echo " 7 | 8 | zend_function_entry systemd_functions[] = { 9 | PHP_FE(sd_journal_send, NULL) 10 | {NULL, NULL, NULL} // Sentinel 11 | }; 12 | 13 | zend_module_entry systemd_module_entry = { 14 | STANDARD_MODULE_HEADER, 15 | PHP_SYSTEMD_EXTNAME, 16 | systemd_functions, 17 | NULL, 18 | NULL, 19 | NULL, 20 | NULL, 21 | NULL, 22 | PHP_SYSTEMD_VERSION, 23 | STANDARD_MODULE_PROPERTIES 24 | }; 25 | 26 | #ifdef COMPILE_DL_SYSTEMD 27 | ZEND_GET_MODULE(systemd) 28 | #endif 29 | 30 | PHP_FUNCTION(sd_journal_send) 31 | { 32 | struct iovec *iov = NULL; 33 | zval *args; 34 | int argc, len, i; 35 | char *val; 36 | 37 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) != SUCCESS) { 38 | return; 39 | } 40 | 41 | // Allocate sufficient iovector space for the arguments. 42 | iov = safe_emalloc(argc, sizeof(struct iovec), 0); 43 | if (!iov) { 44 | // Should probably raise a more clear error. 45 | RETURN_FALSE; 46 | } 47 | 48 | // Iterate through the PHP arguments and fill the iovector. 49 | for (i = 0; i < argc; ++i) { 50 | convert_to_string_ex(&args[i]); 51 | val = Z_STRVAL(args[i]); 52 | len = Z_STRLEN(args[i]); 53 | iov[i].iov_base = val; 54 | iov[i].iov_len = len; 55 | } 56 | 57 | // Send the iovector to journald. 58 | sd_journal_sendv(iov, argc); 59 | 60 | // Free the iovector. The actual strings 61 | // are already managed by PHP. 62 | efree(iov); 63 | 64 | RETURN_TRUE; 65 | } 66 | --------------------------------------------------------------------------------