Commit graph

197 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
9d0b8bbaf0 build-sys: add MANIFEST.in to properly include all files 2015-07-05 21:32:42 -04:00
Zbigniew Jędrzejewski-Szmek
e1ce6a2802 Use python-systemd as the name
We want the package to be installed under this name.
This is also used for sdist, and we want python-systemd-<version>.tar.xz.
2015-07-05 21:32:42 -04:00
Zbigniew Jędrzejewski-Szmek
410f054ddf Update LICENSE file and classifiers
The license was originally MIT, but when this module became part of systemd,
it was changed to LGPLv2+. All files had correct headers, so only the LICENSE
file needs updating. Take the opportunity to add classifiers to setup.py.
2015-07-05 20:16:51 -04:00
Zbigniew Jędrzejewski-Szmek
31baccc855 build-sys: update setup.py to build everything 2015-07-05 15:10:30 -04:00
Zbigniew Jędrzejewski-Szmek
022c9b5be4 Merge development in systemd upstream 2015-07-05 14:19:22 -04:00
Kay Sievers
2a3fc158a5 remove gudev and gtk-doc
The library moved to:
  https://git.gnome.org/browse/libgudev/
2015-07-05 14:19:22 -04:00
Simon Farnsworth
d6c4257815 python-systemd: fix is_socket_inet to cope with ports
Just a couple of trivial oversights.
2015-07-05 14:19:22 -04:00
Dave Reisner
7ea37c0d40 python-systemd: avoid hitting assert in __exit__
Reader_close() asserts that 'args' is always NULL, but the __exit__
function forwards a non-NULL args.
2015-07-05 14:19:22 -04:00
Zbigniew Jędrzejewski-Szmek
a68a57ed71 Always prefer our headers to system headers
In practice this shouldn't make much difference, but
sometimes our headers might be newer, and we want to
test them.
2015-07-05 14:19:22 -04:00
Zbigniew Jędrzejewski-Szmek
4398250261 systemd-python: fix failing assert
A parameter which was always null before, now get's set to
the module.
2015-07-05 14:19:21 -04:00
Zbigniew Jędrzejewski-Szmek
583f1a9441 systemd-python: use .hex instead of .get_hex()
It turns out the latter got removed in Python 3.

https://bugs.freedesktop.org/show_bug.cgi?id=77086
2015-07-05 14:19:21 -04:00
Lennart Poettering
f7cf47eb64 python: reindent _reader.c
All files should follow our coding style, and that means 8ch indenting.
Let's correct that.
2015-07-05 14:19:21 -04:00
Lennart Poettering
ce4e46ae66 macro: introduce nice macro for disabling -Wmissing-prototypes warnigs 2015-07-05 14:19:21 -04:00
Lennart Poettering
5e1d42a180 util: use alloca0() intead of alloca() + memzero() 2015-07-05 14:19:21 -04:00
Greg KH
5cf9be60ca use memzero(foo, length); for all memset(foo, 0, length); calls
In trying to track down a stupid linker bug, I noticed a bunch of
memset() calls that should be using memzero() to make it more "obvious"
that the options are correct (i.e. 0 is not the length, but the data to
set).  So fix up all current calls to memset(foo, 0, length) to
memzero(foo, length).
2015-07-05 14:19:21 -04:00
Zbigniew Jędrzejewski-Szmek
d109c7035f systemd-python: fix listen_fds under Python 2 2015-07-05 14:19:21 -04:00
Zbigniew Jędrzejewski-Szmek
73f327ce21 systemd-python: fix setting of exception codes
The return value of 0 would be treated as failure by mistake,
resulting in " SystemError: error return without exception set".
The way that set_error() is used is changed to be the same
everywhere.
2015-07-05 14:19:21 -04:00
Thomas Hindoe Paaboel Andersen
2ebe9bf6c3 trivial coding style clean ups
- Add space between if/for and the opening parentheses
- Place the opening brace on same line as the function (not for  udev)

From the CODING_STYLE
Try to use this:
    void foo() {
    }
instead of this:
    void foo()
    {
    }
2015-07-05 14:19:21 -04:00
Zbigniew Jędrzejewski-Szmek
07c1d9a144 systemd-python: fix booted() and add two functions to docs
For some reason sphinx doesn't want to show inherited C functions.
2015-07-05 14:19:21 -04:00
Richard Marko
7bb40a26e0 systemd-python: convert keyword value to string
Allows using journal.send('msg', PRIORITY=journal.LOG_CRIT)

Before this commit this results in
TypeError: cannot concatenate 'str' and 'int' objects
and requires passing PRIORITY value as string to work.
2015-07-05 14:19:21 -04:00
Zbigniew Jędrzejewski-Szmek
39970127f2 systemd-python: check for oom, give nicer error messages 2015-07-05 14:19:21 -04:00
Steven Hiscocks
ec9078e45e systemd-python: fix initialization of _Reader objects
https://bugzilla.redhat.com/show_bug.cgi?id=995575
2015-07-05 14:19:21 -04:00
Zbigniew Jędrzejewski-Szmek
ac8b2b3eb3 systemd-python: fix gcc warning
src/python-systemd/_reader.c: In function Reader_get_catalog:
src/python-systemd/_reader.c:912:53: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             assert(mid_len > l);
                            ^
2015-07-05 14:19:21 -04:00
Zbigniew Jędrzejewski-Szmek
7583998db7 systemd-python: use modern C 2015-07-05 14:19:20 -04:00
Zbigniew Jędrzejewski-Szmek
c0d8b4e810 systemd-python: also update the documentation
sphinx, oh sphinx, why do you require manual ficksups all the time?
2015-07-05 14:19:20 -04:00
Zbigniew Jędrzejewski-Szmek
2bfb849c70 systemd-python: add support for sd_j_open_files
Also export missing flags.
2015-07-05 14:19:20 -04:00
Zbigniew Jędrzejewski-Szmek
2c0317be82 systemd-python: fix iteration
Back in 6a58bf4135 raising stop iteration was removed from the C
code, but wasn't added in the Python counterpart.
2015-07-05 14:19:20 -04:00
Zbigniew Jędrzejewski-Szmek
d9a07b11ea systemd-python: wrap sd_notify
_listen_fds() is modified to accept unset_environment arg as keyword,
to match new notify().
2015-07-05 14:19:20 -04:00
Zbigniew Jędrzejewski-Szmek
0a3463cd5b journal: add ability to filter by current user
This is the just the library part.

SD_JOURNAL_CURRENT_USER flags is added to sd_j_open(), to open
files from current user.

SD_JOURNAL_SYSTEM_ONLY is renamed to SD_JOURNAL_SYSTEM,
and changed to mean to (also) open system files. This way various
flags can be combined, which gives them nicer semantics, especially
if other ones are added later.

Backwards compatibility is kept, because SD_JOURNAL_SYSTEM_ONLY
is equivalent to SD_JOURNAL_SYSTEM if used alone, and before there
we no other flags.
2015-07-05 14:19:20 -04:00
Zbigniew Jędrzejewski-Szmek
98f187ea64 systemd-python: do not attempt to convert str to bytes
Bug-spotted-by: Steven Hiscocks <steven-systemd@hiscocks.me.uk>
2015-07-05 14:19:20 -04:00
Zbigniew Jędrzejewski-Szmek
d9e0a12c2a systemd-python: allow threads around flush
flush() is potentially costly.
2015-07-05 14:19:20 -04:00
Zbigniew Jędrzejewski-Szmek
cba4e76b2f systemd-python: use consistent indentation 2015-07-05 14:19:20 -04:00
Zbigniew Jędrzejewski-Szmek
3ac545a83d systemd-python: wrap sd_login_monitor 2015-07-05 14:19:20 -04:00
Zbigniew Jędrzejewski-Szmek
466a9b7fe1 systemd-python: add wrappers for easy functions in sd-login
sd_get_uids, sd_get_seats, sd_get_sessions, and sd_get_machine_names.
2015-07-05 14:19:20 -04:00
Zbigniew Jędrzejewski-Szmek
7b3e876dde systemd-python: add __version__ strings 2015-07-05 14:19:20 -04:00
Ville Skyttä
cfcc187067 Spelling fixes 2015-07-05 14:19:20 -04:00
Zbigniew Jędrzejewski-Szmek
dbf3584a15 systemd-python: attach fields to JournalHandler, add SYSLOG_IDENTIFIER
Arbitrary fields can be attached at the level of the handler,
and they'll be sent with all messages from this handler.

This facility is used to attach SYSLOG_IDENTIFIER to all messages,
since otherwise journald attaches SYSLOG_IDENTIFIER=python or
something similar, which is completely useless.
2015-07-05 14:19:19 -04:00
Zbigniew Jędrzejewski-Szmek
756d44fc44 systemd-python: wrap sd_journal_add_conjunction 2015-07-05 14:19:19 -04:00
Harald Hoyer
fdb41b9f70 move _cleanup_ attribute in front of the type
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2015-07-05 14:19:19 -04:00
Zbigniew Jędrzejewski-Szmek
68db467eea sd-messages.h: add new bootchart message id 2015-07-05 14:19:19 -04:00
Zbigniew Jędrzejewski-Szmek
0035bc19b1 Report about syntax errors with metadata
The information about the unit for which files are being parsed
is passed all the way down. This way messages land in the journal
with proper UNIT=... or USER_UNIT=... attribution.

'systemctl status' and 'journalctl -u' not displaying those messages
has been a source of confusion for users, since the journal entry for
a misspelt setting was often logged quite a bit earlier than the
failure to start a unit.

Based-on-a-patch-by: Oleksii Shevchuk <alxchk@gmail.com>
2015-07-05 14:19:19 -04:00
Steven Hiscocks
6238295ba7 python-systemd: Reader return special fields and _Reader changes
Changes to _Reader make it match closer to C API, by removing `get_next`
and `get_previous`. A `get_all` method added, which returns dictionary
of fields using C API SD_JOURNAL_FOREACH_DATA macro, which can be used
in conjunction with `next`.

_Reader `get`, `next`, `get_{realtime,monotonic,cursor}` and new
`previous` methods are made private. This is so the traversal and
getting of journal fields can be made transparent in the python
interface.

Reader now solely implements `get_next` and `get_previous`, returning a
standard dictionary (future: other mapping types?) with all standard and
special fields through the converters. This makes the output the same as
journalctl json/export format output.

Iterator methods also moved to Reader, as they do not function as intend
with changes to _Reader.

These changes also mean that more optimised journal interfaces can be
made more easily from _Reader, by avoiding getting of unrequired fields
by using the `_get` method, and avoiding field conversions.
2015-07-05 14:19:19 -04:00
Zbigniew Jędrzejewski-Szmek
81d7790578 systemd-python: export new sd_journal_{process,get_events,get_timeout}
get_timeout_ms is added as a convenience function, since
it is abysmally hard to call clock_gettime() in Python
versions lower than 3.3. And even for Python 3.3 users
it saves a few lines.
2015-07-05 14:19:19 -04:00
Zbigniew Jędrzejewski-Szmek
f805090312 systemd-python: fix formatting in docstring 2015-07-05 14:19:19 -04:00
Steven Hiscocks
d9dc73a923 systemd-python: fix wait bug 2015-07-05 14:19:19 -04:00
Zbigniew Jędrzejewski-Szmek
06e0c9012f Use initalization instead of explicit zeroing
Before, we would initialize many fields twice: first
by filling the structure with zeros, and then a second
time with the real values. We can let the compiler do
the job for us, avoiding one copy.

A downside of this patch is that text gets slightly
bigger. This is because all zero() calls are effectively
inlined:

$ size build/.libs/systemd
         text    data     bss     dec     hex filename
before 897737  107300    2560 1007597   f5fed build/.libs/systemd
after  897873  107300    2560 1007733   f6075 build/.libs/systemd

… actually less than 1‰.

A few asserts that the parameter is not null had to be removed. I
don't think this changes much, because first, it is quite unlikely
for the assert to fail, and second, an immediate SEGV is almost as
good as an assert.
2015-07-05 14:19:19 -04:00
Zbigniew Jędrzejewski-Szmek
0c9613000a systemd-python: allow retrieval of single fields
This can give huge efficiency gains, e.g. if only MESSAGE
is required and all other fields can be ignored.
2015-07-05 14:19:19 -04:00
Zbigniew Jędrzejewski-Szmek
530a0dcbc3 systemd-python: split out realtime and monotonic into separate functions
This matches the C API more closely, and also enables the
user to get just partial information, should she desire to
do so.

Functions names in error messages are modified to not include
the class name, because Python uses just the function name
into functions declared as METH_NOARGS, and error messages
were inconsistent.
2015-07-05 14:19:19 -04:00
Zbigniew Jędrzejewski-Szmek
3507ff227b systemd-python: implement _Reader.test_cursor
Getting the cursor is split out from .get_next() into
.get_cursor(). This mirrors the C API more closely, and
also makes things a bit faster if the cursor is not needed.
2015-07-05 14:19:19 -04:00
Zbigniew Jędrzejewski-Szmek
8057e1c7e7 systemd-python: cleanup up usec_t handling
The behaviour wrt. seconds vs. microseconds was inconsistent.
Now _Reader always uses native units (us), while Reader always
uses seconds and accepts both floats and ints. This way the
conversion is always done in the Python layer, and the lower
level API allows access to the journal API without the potentially
lossy conversion between double and uint64_t.
2015-07-05 14:19:18 -04:00