[systemd-devel] [PATCH v2] sd-login: add a public accessor for the VT number

Lennart Poettering lennart at poettering.net
Wed Sep 11 10:09:39 PDT 2013


On Wed, 11.09.13 18:48, Giovanni Campagna (scampa.giovanni at gmail.com) wrote:

> From: Giovanni Campagna <gcampagn at redhat.com>
> 
> The VT number was already part of the DBus API, but was not
> exposed in the C API.

Thanks! Applied with minor changes (replaced strtoul with our own
safe_atou() which is a ton easier to use).

> ---
>  man/sd_session_is_active.xml   | 13 +++++++++++++
>  src/login/libsystemd-login.sym |  5 +++++
>  src/login/sd-login.c           | 18 ++++++++++++++++++
>  src/systemd/sd-login.h         |  3 +++
>  4 files changed, 39 insertions(+)
> 
> diff --git a/man/sd_session_is_active.xml b/man/sd_session_is_active.xml
> index e89117d..9362fbc 100644
> --- a/man/sd_session_is_active.xml
> +++ b/man/sd_session_is_active.xml
> @@ -52,6 +52,7 @@
>                  <refname>sd_session_get_class</refname>
>                  <refname>sd_session_get_display</refname>
>                  <refname>sd_session_get_tty</refname>
> +                <refname>sd_session_get_vt</refname>
>                  <refpurpose>Determine state of a specific session</refpurpose>
>          </refnamediv>
>  
> @@ -111,6 +112,12 @@
>                                  <paramdef>const char* <parameter>session</parameter></paramdef>
>                                  <paramdef>char** <parameter>tty</parameter></paramdef>
>                          </funcprototype>
> +
> +                        <funcprototype>
> +                                <funcdef>int <function>sd_session_get_vt</function></funcdef>
> +                                <paramdef>const char* <parameter>session</parameter></paramdef>
> +                                <paramdef>unsigned* <parameter>vt</parameter></paramdef>
> +                        </funcprototype>
>                  </funcsynopsis>
>          </refsynopsisdiv>
>  
> @@ -202,6 +209,12 @@
>                  <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
>                  call after use.</para>
>  
> +                <para><function>sd_session_get_vt()</function>
> +                may be used to determine the VT number of the
> +                session identified by the specified session
> +                identifier. This function will return an error if
> +                the seat does not support VTs.</para>
> +
>                  <para>If the <varname>session</varname> parameter of
>                  any of these functions is passed as
>                  <constant>NULL</constant> the operation is executed
> diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym
> index 0720704..7512ef5 100644
> --- a/src/login/libsystemd-login.sym
> +++ b/src/login/libsystemd-login.sym
> @@ -80,3 +80,8 @@ LIBSYSTEMD_LOGIN_205 {
>  global:
>          sd_pid_get_slice;
>  } LIBSYSTEMD_LOGIN_203;
> +
> +LIBSYSTEMD_LOGIN_206 {
> +global:
> +        sd_session_get_vt;
> +} LIBSYSTEMD_LOGIN_205;
> \ No newline at end of file
> diff --git a/src/login/sd-login.c b/src/login/sd-login.c
> index 0658792..6a6e04e 100644
> --- a/src/login/sd-login.c
> +++ b/src/login/sd-login.c
> @@ -347,6 +347,24 @@ _public_ int sd_session_get_tty(const char *session, char **tty) {
>          return session_get_string(session, "TTY", tty);
>  }
>  
> +_public_ int sd_session_get_vt(const char *session, unsigned *vtnr) {
> +        _cleanup_free_ char *vtnr_string;
> +        char *end;
> +        int r;
> +        unsigned long v;
> +
> +        r = session_get_string(session, "VTNr", &vtnr_string);
> +        if (r < 0)
> +                return r;
> +
> +        v = strtoul(vtnr_string, &end, 10);
> +        if (end == vtnr_string || *end)
> +                return -EINVAL;
> +
> +        *vtnr = v;
> +        return 0;
> +}
> +
>  _public_ int sd_session_get_service(const char *session, char **service) {
>          return session_get_string(session, "SERVICE", service);
>  }
> diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h
> index e37aeda..c5837f0 100644
> --- a/src/systemd/sd-login.h
> +++ b/src/systemd/sd-login.h
> @@ -124,6 +124,9 @@ int sd_session_get_display(const char *session, char **display);
>  /* Determine the TTY of this session. */
>  int sd_session_get_tty(const char *session, char **display);
>  
> +/* Determine the VT number of this session. */
> +int sd_session_get_vt(const char *session, unsigned *vtnr);
> +
>  /* Return active session and user of seat */
>  int sd_seat_get_active(const char *seat, char **session, uid_t *uid);
>  


Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list