[systemd-commits] 5 commits - Makefile.am man/custom-html.xsl man/systemd.unit.xml src/core src/journal src/python-systemd

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Wed May 8 19:35:19 PDT 2013


 Makefile.am                       |   26 +++++
 man/custom-html.xsl               |   23 ++++
 man/systemd.unit.xml              |    5 -
 src/core/condition.c              |    2 
 src/core/socket.h                 |    7 -
 src/journal/journal-internal.h    |    9 +
 src/journal/mmap-cache.c          |    5 -
 src/journal/sd-journal.c          |    2 
 src/python-systemd/_daemon.c      |    4 
 src/python-systemd/_journal.c     |   21 ++++
 src/python-systemd/_reader.c      |   18 ---
 src/python-systemd/daemon.py      |    3 
 src/python-systemd/docs/index.rst |    1 
 src/python-systemd/docs/login.rst |    5 +
 src/python-systemd/id128.c        |    5 -
 src/python-systemd/journal.py     |    2 
 src/python-systemd/login.c        |  176 ++++++++++++++++++++++++++++++++++++++
 src/python-systemd/pyutil.c       |   16 +++
 src/python-systemd/pyutil.h       |    1 
 19 files changed, 294 insertions(+), 37 deletions(-)

New commits:
commit b62ee5249da92ff8960322eab770f742425831e3
Author: Karol Lewandowski <k.lewandowsk at samsung.com>
Date:   Tue May 7 13:21:46 2013 +0200

    condition, man: Add support for ConditionSecurity=smack
    
    According to Documentation/security/Smack.txt:
      In keeping with the intent of Smack, configuration data is minimal
      and not strictly required. The most important configuration step is
      mounting the smackfs pseudo filesystem.
    This means that checking the mount point should be enough.

diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
index 49103da..c56837a 100644
--- a/man/systemd.unit.xml
+++ b/man/systemd.unit.xml
@@ -984,8 +984,9 @@
                                 may be used to check whether the given
                                 security module is enabled on the
                                 system.  Currently the only recognized
-                                values are <varname>selinux</varname>
-                                and <varname>apparmor</varname>.
+                                values are <varname>selinux</varname>,
+                                <varname>apparmor</varname>, and
+                                <varname>smack</varname>.
                                 The test may be negated by prepending
                                 an exclamation
                                 mark.</para>
diff --git a/src/core/condition.c b/src/core/condition.c
index 4aa5530..16cae6d 100644
--- a/src/core/condition.c
+++ b/src/core/condition.c
@@ -164,6 +164,8 @@ static bool test_security(const char *parameter) {
 #endif
 	if (streq(parameter, "apparmor"))
 		return access("/sys/kernel/security/apparmor/", F_OK) == 0;
+	if (streq(parameter, "smack"))
+		return access("/sys/fs/smackfs", F_OK) == 0;
         return false;
 }
 

commit 539e0a4d583bca7db837275b07a20a933b7f8f83
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Wed May 8 19:46:49 2013 -0400

    systemd-python: add wrappers for easy functions in sd-login
    
    sd_get_uids, sd_get_seats, sd_get_sessions, and sd_get_machine_names.

diff --git a/Makefile.am b/Makefile.am
index 6200610..1e7c9df 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3698,7 +3698,8 @@ pkgpyexec_LTLIBRARIES = \
 	_journal.la \
 	id128.la \
 	_daemon.la \
-	_reader.la
+	_reader.la \
+	login.la
 
 _journal_la_SOURCES = \
 	src/python-systemd/_journal.c
@@ -3784,6 +3785,29 @@ _reader_la_LIBADD = \
 	libsystemd-shared.la \
 	libsystemd-daemon-internal.la
 
+login_la_SOURCES = \
+	src/python-systemd/login.c \
+	src/python-systemd/pyutil.c \
+	src/python-systemd/pyutil.h
+
+login_la_CFLAGS = \
+	$(AM_CFLAGS) \
+	-fvisibility=default \
+	$(PYTHON_CFLAGS)
+
+login_la_LDFLAGS = \
+	$(AM_LDFLAGS) \
+	-shared \
+	-module \
+	-avoid-version
+
+login_la_LIBADD = \
+	$(PYTHON_LIBS) \
+	libsystemd-journal.la \
+	libsystemd-login.la \
+	libsystemd-shared.la \
+	libsystemd-daemon-internal.la
+
 dist_pkgpyexec_PYTHON = \
 	src/python-systemd/journal.py \
 	src/python-systemd/daemon.py \
diff --git a/src/python-systemd/_reader.c b/src/python-systemd/_reader.c
index 50ad889..d20c58d 100644
--- a/src/python-systemd/_reader.c
+++ b/src/python-systemd/_reader.c
@@ -213,19 +213,7 @@ static PyObject* Reader_get_timeout_ms(Reader *self, PyObject *args)
     if (r < 0)
         return NULL;
 
-    if (t == (uint64_t) -1)
-        return PyLong_FromLong(-1);
-    else {
-        struct timespec ts;
-        uint64_t n;
-        int msec;
-
-        clock_gettime(CLOCK_MONOTONIC, &ts);
-        n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
-        msec = t > n ? (int) ((t - n + 999) / 1000) : 0;
-
-        return PyLong_FromLong(msec);
-    }
+    return absolute_timeout(t);
 }
 
 
diff --git a/src/python-systemd/docs/index.rst b/src/python-systemd/docs/index.rst
index 8a94d07..e78d966 100644
--- a/src/python-systemd/docs/index.rst
+++ b/src/python-systemd/docs/index.rst
@@ -14,6 +14,7 @@ Contents:
    journal
    id128
    daemon
+   login
 
 Indices and tables
 ==================
diff --git a/src/python-systemd/docs/login.rst b/src/python-systemd/docs/login.rst
new file mode 100644
index 0000000..2cd9d8c
--- /dev/null
+++ b/src/python-systemd/docs/login.rst
@@ -0,0 +1,5 @@
+`systemd.login` module
+=======================
+
+.. automodule:: systemd.login
+   :members:
diff --git a/src/python-systemd/login.c b/src/python-systemd/login.c
new file mode 100644
index 0000000..1dbe5ac
--- /dev/null
+++ b/src/python-systemd/login.c
@@ -0,0 +1,176 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2013 Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#define PY_SSIZE_T_CLEAN
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wredundant-decls"
+#include <Python.h>
+#pragma GCC diagnostic pop
+
+#include "systemd/sd-login.h"
+#include "pyutil.h"
+#include "util.h"
+#include "strv.h"
+
+PyDoc_STRVAR(module__doc__,
+             "Python interface to the libsystemd-login library."
+);
+
+#define helper(name)                                                    \
+static PyObject* name(PyObject *self, PyObject *args) {                 \
+        _cleanup_strv_free_ char **list = NULL;                         \
+        int r;                                                          \
+        PyObject *ans;                                                  \
+                                                                        \
+        assert(args == NULL);                                           \
+                                                                        \
+        r = sd_get_##name(&list);                                       \
+        if (r < 0) {                                                    \
+                errno = -r;                                             \
+                return PyErr_SetFromErrno(PyExc_IOError);               \
+        }                                                               \
+                                                                        \
+        ans = PyList_New(r);                                            \
+        if (!ans)                                                       \
+                return NULL;                                            \
+                                                                        \
+        for (r--; r >= 0; r--) {                                        \
+                PyObject *s = unicode_FromString(list[r]);              \
+                if (!s) {                                               \
+                        Py_DECREF(ans);                                 \
+                        return NULL;                                    \
+                }                                                       \
+                                                                        \
+                PyList_SetItem(ans, r, s);                              \
+        }                                                               \
+                                                                        \
+        return ans;                                                     \
+}
+
+helper(seats)
+helper(sessions)
+helper(machine_names)
+#undef helper
+
+static PyObject* uids(PyObject *self, PyObject *args) {
+        _cleanup_free_ uid_t *list = NULL;
+        int r;
+        PyObject *ans;
+
+        assert(args == NULL);
+
+        r = sd_get_uids(&list);
+        if (r < 0) {
+                errno = -r;
+                return PyErr_SetFromErrno(PyExc_IOError);
+        }
+
+        ans = PyList_New(r);
+        if (!ans)
+                return NULL;
+
+        for (r--; r >= 0; r--) {
+                PyObject *s = long_FromLong(list[r]);
+                if (!s) {
+                        Py_DECREF(ans);
+                        return NULL;
+                }
+
+                PyList_SetItem(ans, r, s);
+        }
+
+        return ans;
+}
+
+PyDoc_STRVAR(seats__doc__,
+             "seats() -> list\n\n"
+             "Returns a list of currently available local seats.\n"
+             "Wraps sd_get_seats(3)."
+);
+
+PyDoc_STRVAR(sessions__doc__,
+             "sessions() -> list\n\n"
+             "Returns a list of current login sessions.\n"
+             "Wraps sd_get_sessions(3)."
+);
+
+PyDoc_STRVAR(machine_names__doc__,
+             "machine_names() -> list\n\n"
+             "Returns a list of currently running virtual machines\n"
+             "and containers on the system.\n"
+             "Wraps sd_get_machine_names(3)."
+);
+
+PyDoc_STRVAR(uids__doc__,
+             "uids() -> list\n\n"
+             "Returns a list of uids of users who currently have login sessions.\n"
+             "Wraps sd_get_uids(3)."
+);
+
+static PyMethodDef methods[] = {
+        { "seats", seats, METH_NOARGS, seats__doc__},
+        { "sessions", sessions, METH_NOARGS, sessions__doc__},
+        { "machine_names", machine_names, METH_NOARGS, machine_names__doc__},
+        { "uids", uids, METH_NOARGS, uids__doc__},
+        {} /* Sentinel */
+};
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmissing-prototypes"
+
+#if PY_MAJOR_VERSION < 3
+
+PyMODINIT_FUNC initlogin(void) {
+        PyObject *m;
+
+        m = Py_InitModule3("login", methods, module__doc__);
+        if (m == NULL)
+                return;
+        PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION);
+}
+#else
+
+static struct PyModuleDef module = {
+        PyModuleDef_HEAD_INIT,
+        "login", /* name of module */
+        module__doc__, /* module documentation, may be NULL */
+        -1, /* size of per-interpreter state of the module */
+        methods
+};
+
+PyMODINIT_FUNC PyInit_login(void) {
+        PyObject *m;
+
+        m = PyModule_Create(&module);
+        if (m == NULL)
+                return NULL;
+
+        if (PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) {
+                Py_DECREF(m);
+                return NULL;
+        }
+
+        return m;
+}
+
+#endif
+
+#pragma GCC diagnostic pop
diff --git a/src/python-systemd/pyutil.c b/src/python-systemd/pyutil.c
index 79065a1..9510acd 100644
--- a/src/python-systemd/pyutil.c
+++ b/src/python-systemd/pyutil.c
@@ -28,3 +28,19 @@ void cleanup_Py_DECREFp(PyObject **p) {
 
         Py_DECREF(*p);
 }
+
+PyObject* absolute_timeout(uint64_t t) {
+    if (t == (uint64_t) -1)
+        return PyLong_FromLong(-1);
+    else {
+        struct timespec ts;
+        uint64_t n;
+        int msec;
+
+        clock_gettime(CLOCK_MONOTONIC, &ts);
+        n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
+        msec = t > n ? (int) ((t - n + 999) / 1000) : 0;
+
+        return PyLong_FromLong(msec);
+    }
+}
diff --git a/src/python-systemd/pyutil.h b/src/python-systemd/pyutil.h
index 2163fda..5c7ea37 100644
--- a/src/python-systemd/pyutil.h
+++ b/src/python-systemd/pyutil.h
@@ -27,6 +27,7 @@
 #endif
 
 void cleanup_Py_DECREFp(PyObject **p);
+PyObject* absolute_timeout(uint64_t t);
 
 #define _cleanup_Py_DECREF_ __attribute__((cleanup(cleanup_Py_DECREFp)))
 

commit 5afbe712db5cc68213a24c45396ffb43fab05e3e
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Wed May 8 21:08:14 2013 -0400

    systemd-python: add __version__ strings

diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index d81e4dd..c21712b 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -415,7 +415,7 @@ _public_ void sd_journal_flush_matches(sd_journal *j) {
 }
 
 static int compare_entry_order(JournalFile *af, Object *_ao,
-                         JournalFile *bf, uint64_t bp) {
+                               JournalFile *bf, uint64_t bp) {
 
         uint64_t a, b;
         Object *ao, *bo;
diff --git a/src/python-systemd/_daemon.c b/src/python-systemd/_daemon.c
index ce20649..d3b4807 100644
--- a/src/python-systemd/_daemon.c
+++ b/src/python-systemd/_daemon.c
@@ -291,6 +291,7 @@ PyMODINIT_FUNC init_daemon(void) {
                 return;
 
         PyModule_AddIntConstant(m, "LISTEN_FDS_START", SD_LISTEN_FDS_START);
+        PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION);
 }
 
 #else
@@ -310,7 +311,8 @@ PyMODINIT_FUNC PyInit__daemon(void) {
         if (m == NULL)
                 return NULL;
 
-        if (PyModule_AddIntConstant(m, "LISTEN_FDS_START", SD_LISTEN_FDS_START)) {
+        if (PyModule_AddIntConstant(m, "LISTEN_FDS_START", SD_LISTEN_FDS_START) ||
+            PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) {
                 Py_DECREF(m);
                 return NULL;
         }
diff --git a/src/python-systemd/_journal.c b/src/python-systemd/_journal.c
index 2de0d4f..f8e0b4f 100644
--- a/src/python-systemd/_journal.c
+++ b/src/python-systemd/_journal.c
@@ -119,7 +119,13 @@ static PyMethodDef methods[] = {
 #if PY_MAJOR_VERSION < 3
 
 PyMODINIT_FUNC init_journal(void) {
-        (void) Py_InitModule("_journal", methods);
+        PyObject *m;
+
+        m = Py_InitModule("_journal", methods);
+        if (m == NULL)
+                return;
+
+        PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION);
 }
 
 #else
@@ -133,7 +139,18 @@ static struct PyModuleDef module = {
 };
 
 PyMODINIT_FUNC PyInit__journal(void) {
-        return PyModule_Create(&module);
+        PyObject *m;
+
+        m = PyModule_Create(&module);
+        if (m == NULL)
+                return NULL;
+
+        if (PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) {
+                Py_DECREF(m);
+                return NULL;
+        }
+
+        return m;
 }
 
 #endif
diff --git a/src/python-systemd/_reader.c b/src/python-systemd/_reader.c
index b836597..50ad889 100644
--- a/src/python-systemd/_reader.c
+++ b/src/python-systemd/_reader.c
@@ -30,6 +30,7 @@
 #include "pyutil.h"
 #include "macro.h"
 #include "util.h"
+#include "build.h"
 
 typedef struct {
     PyObject_HEAD
@@ -1126,7 +1127,8 @@ init_reader(void)
         PyModule_AddIntConstant(m, "INVALIDATE", SD_JOURNAL_INVALIDATE) ||
         PyModule_AddIntConstant(m, "LOCAL_ONLY", SD_JOURNAL_LOCAL_ONLY) ||
         PyModule_AddIntConstant(m, "RUNTIME_ONLY", SD_JOURNAL_RUNTIME_ONLY) ||
-        PyModule_AddIntConstant(m, "SYSTEM_ONLY", SD_JOURNAL_SYSTEM_ONLY)) {
+        PyModule_AddIntConstant(m, "SYSTEM_ONLY", SD_JOURNAL_SYSTEM_ONLY) ||
+        PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) {
 #if PY_MAJOR_VERSION >= 3
         Py_DECREF(m);
         return NULL;
diff --git a/src/python-systemd/daemon.py b/src/python-systemd/daemon.py
index 4a02204..e2829d1 100644
--- a/src/python-systemd/daemon.py
+++ b/src/python-systemd/daemon.py
@@ -1,4 +1,5 @@
-from ._daemon import (booted,
+from ._daemon import (__version__,
+                      booted,
                       _listen_fds,
                       _is_fifo,
                       _is_socket,
diff --git a/src/python-systemd/id128.c b/src/python-systemd/id128.c
index 1c2fe5d..ec1d9fb 100644
--- a/src/python-systemd/id128.c
+++ b/src/python-systemd/id128.c
@@ -19,8 +19,6 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <stdbool.h>
-
 #include <Python.h>
 
 #include <systemd/sd-messages.h>
@@ -126,6 +124,7 @@ PyMODINIT_FUNC initid128(void) {
 #define JOINER ;
 #include "id128-constants.h"
 #undef JOINER
+        PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION);
 }
 
 #else
@@ -149,7 +148,7 @@ PyMODINIT_FUNC PyInit_id128(void) {
 #define JOINER ||
 #include "id128-constants.h"
 #undef JOINER
-                false) {
+            PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) {
                 Py_DECREF(m);
                 return NULL;
         }
diff --git a/src/python-systemd/journal.py b/src/python-systemd/journal.py
index 9e40cbc..9ef1ede 100644
--- a/src/python-systemd/journal.py
+++ b/src/python-systemd/journal.py
@@ -31,7 +31,7 @@ if _sys.version_info >= (3,3):
     from collections import ChainMap as _ChainMap
 from syslog import (LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
                     LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG)
-from ._journal import sendv, stream_fd
+from ._journal import __version__, sendv, stream_fd
 from ._reader import (_Reader, NOP, APPEND, INVALIDATE,
                       LOCAL_ONLY, RUNTIME_ONLY, SYSTEM_ONLY,
                       _get_catalog)

commit 6866780115a7c0af034f287d965f4bf6b02c1e6d
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue May 7 21:07:39 2013 -0400

    Rearrange a few fields to reduce holes

diff --git a/src/core/socket.h b/src/core/socket.h
index 4826bb3..9d48cde 100644
--- a/src/core/socket.h
+++ b/src/core/socket.h
@@ -130,6 +130,10 @@ struct Socket {
         bool broadcast;
         bool pass_cred;
         bool pass_sec;
+
+        /* Only for INET6 sockets: issue IPV6_V6ONLY sockopt */
+        SocketAddressBindIPv6Only bind_ipv6_only;
+
         int priority;
         int mark;
         size_t receive_buffer;
@@ -142,9 +146,6 @@ struct Socket {
         long mq_maxmsg;
         long mq_msgsize;
 
-        /* Only for INET6 sockets: issue IPV6_V6ONLY sockopt */
-        SocketAddressBindIPv6Only bind_ipv6_only;
-
         char *smack;
         char *smack_ip_in;
         char *smack_ip_out;
diff --git a/src/journal/journal-internal.h b/src/journal/journal-internal.h
index eea56e4..c7e585d 100644
--- a/src/journal/journal-internal.h
+++ b/src/journal/journal-internal.h
@@ -74,19 +74,20 @@ typedef enum LocationType {
 struct Location {
         LocationType type;
 
+        bool seqnum_set;
+        bool realtime_set;
+        bool monotonic_set;
+        bool xor_hash_set;
+
         uint64_t seqnum;
         sd_id128_t seqnum_id;
-        bool seqnum_set;
 
         uint64_t realtime;
-        bool realtime_set;
 
         uint64_t monotonic;
         sd_id128_t boot_id;
-        bool monotonic_set;
 
         uint64_t xor_hash;
-        bool xor_hash_set;
 };
 
 struct Directory {
diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c
index 54bf114..767f555 100644
--- a/src/journal/mmap-cache.c
+++ b/src/journal/mmap-cache.c
@@ -41,9 +41,9 @@ struct Window {
         bool keep_always;
         bool in_unused;
 
+        int prot;
         void *ptr;
         uint64_t offset;
-        int prot;
         size_t size;
 
         FileDescriptor *fd;
@@ -70,12 +70,11 @@ struct FileDescriptor {
 
 struct MMapCache {
         int n_ref;
+        unsigned n_windows;
 
         Hashmap *fds;
         Hashmap *contexts;
 
-        unsigned n_windows;
-
         LIST_HEAD(Window, unused);
         Window *last_unused;
 };

commit fa13e4a78487971a5093db3fdc61cad224d47c16
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon May 6 20:00:16 2013 -0400

    man: add permalinks to subsection titles too

diff --git a/man/custom-html.xsl b/man/custom-html.xsl
index 2e40ab1..dde9d7a 100644
--- a/man/custom-html.xsl
+++ b/man/custom-html.xsl
@@ -48,7 +48,6 @@
         <xsl:text>Permalink to this headline</xsl:text>
       </xsl:attribute>
       <xsl:attribute name="href">
-        <!--        <xsl:call-template name="href.target.uri" /> -->
         <xsl:text>#</xsl:text>
         <xsl:call-template name="inline.charseq"/>
       </xsl:attribute>
@@ -57,6 +56,28 @@
   </h2>
 </xsl:template>
 
+<xsl:template match="refsect2/title|refsect2/info/title">
+  <h3>
+    <xsl:attribute name="id">
+      <xsl:call-template name="inline.charseq"/>
+    </xsl:attribute>
+    <xsl:apply-templates/>
+    <a>
+      <xsl:attribute name="class">
+        <xsl:text>headerlink</xsl:text>
+      </xsl:attribute>
+      <xsl:attribute name="title">
+        <xsl:text>Permalink to this headline</xsl:text>
+      </xsl:attribute>
+      <xsl:attribute name="href">
+        <xsl:text>#</xsl:text>
+        <xsl:call-template name="inline.charseq"/>
+      </xsl:attribute>
+      <xsl:text>¶</xsl:text>
+    </a>
+  </h3>
+</xsl:template>
+
 <xsl:template match="varlistentry">
   <dt>
     <xsl:attribute name="id">



More information about the systemd-commits mailing list