Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


sd_bus_message_read(3) — Linux manual page

NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |NOTES |EXAMPLES |HISTORY |SEE ALSO |COLOPHON

SD_BUS_MESSAGE_READ(3)     sd_bus_message_readSD_BUS_MESSAGE_READ(3)

NAME        top

       sd_bus_message_read, sd_bus_message_readv,       sd_bus_message_peek_type - Read a sequence of values from a       message

SYNOPSIS        top

#include <systemd/sd-bus.h>int sd_bus_message_read(sd_bus_message *m, const char *types,...);int sd_bus_message_readv(sd_bus_message *m, const char *types,va_listap);int sd_bus_message_peek_type(sd_bus_message *m, char *type,const char **contents);

DESCRIPTION        top

sd_bus_message_read()reads a sequence of fields from the D-Bus       message objectm and advances the read position in the message.       The type stringtypes describes the types of items expected in the       message and the field arguments that follow. The type string may       beNULLor empty, in which case nothing is read.       The type string is composed of the elements described insd_bus_message_append(3), i.e. basic and container types. It must       contain zero or more single "complete types". The type string isNUL-terminated.       For each type specified in the type string, one or more arguments       need to be specified after thetypes parameter, in the same order.       The arguments must be pointers to appropriate types (a pointer toint8_tfor a "y" in the type string, a pointer toint32_tfor an       "i", a pointer toconst char*for an "s", ...) which are set based       on the values in the message. As an exception, in case of array       and variant types, the first argument is an "input" argument that       further specifies how the message should be read. See the table       below for a complete list of allowed arguments and their types.       Note that, if the basic type is a pointer (e.g.,const char *in       the case of a string), the argument is a pointer to a pointer, and       also the pointer value that is written is only borrowed and the       contents must be copied if they are to be used after the end of       the message's lifetime. If the type is "h" (UNIX file descriptor),       the descriptor is not duplicated by this call and the returned       descriptor remains in possession of the message object, and needs       to be duplicated by the caller in order to keep an open reference       to it after the message object is freed.       Each argument may also beNULL, in which case the value is read       and ignored.Table 1. Item type specifiers       ┌───────────┬──────────────────────────────┬────────────────┬──────────────┬──────────────┐       │SpecifierConstantDescriptionType of theTypes of the│       │           │                              │                │firstsubsequent│       │           │                              │                │argumentarguments,│       │           │                              │                │              │if any│       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "y"       │SD_BUS_TYPE_BYTE│ 8-bit          │uint8_t *│              │       │           │                              │ unsigned       │              │              │       │           │                              │ integer        │              │              │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "b"       │SD_BUS_TYPE_BOOLEAN│ boolean        │int *(NB:   │              │       │           │                              │                │ notbool *)  │              │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "n"       │SD_BUS_TYPE_INT16│ 16-bit         │int16_t *│              │       │           │                              │ signed         │              │              │       │           │                              │ integer        │              │              │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "q"       │SD_BUS_TYPE_UINT16│ 16-bit         │uint16_t *│              │       │           │                              │ unsigned       │              │              │       │           │                              │ integer        │              │              │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "i"       │SD_BUS_TYPE_INT32│ 32-bit         │int32_t *│              │       │           │                              │ signed         │              │              │       │           │                              │ integer        │              │              │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "u"       │SD_BUS_TYPE_UINT32│ 32-bit         │uint32_t *│              │       │           │                              │ unsigned       │              │              │       │           │                              │ integer        │              │              │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "x"       │SD_BUS_TYPE_INT64│ 64-bit         │int64_t *│              │       │           │                              │ signed         │              │              │       │           │                              │ integer        │              │              │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "t"       │SD_BUS_TYPE_UINT64│ 64-bit         │uint64_t *│              │       │           │                              │ unsigned       │              │              │       │           │                              │ integer        │              │              │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "d"       │SD_BUS_TYPE_DOUBLE│ IEEE 754       │double *│              │       │           │                              │ double         │              │              │       │           │                              │ precision      │              │              │       │           │                              │ floating-point │              │              │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "s"       │SD_BUS_TYPE_STRING│ UTF-8 string   │const char│              │       │           │                              │                │**│              │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "o"       │SD_BUS_TYPE_OBJECT_PATH│ D-Bus object   │const char│              │       │           │                              │ path string    │**│              │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "g"       │SD_BUS_TYPE_SIGNATURE│ D-Bus          │const char│              │       │           │                              │ signature      │**│              │       │           │                              │ string         │              │              │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "h"       │SD_BUS_TYPE_UNIX_FD│ UNIX file      │int *│              │       │           │                              │ descriptor     │              │              │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "a"       │SD_BUS_TYPE_ARRAY│ array          │int, which   │n sets of    │       │           │                              │                │ specifies    │ arguments    │       │           │                              │                │ the expected │ appropriate  │       │           │                              │                │ lengthn of  │ for the      │       │           │                              │                │ the array    │ array        │       │           │                              │                │              │ element type │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┼──────────────┤       │ "v"       │SD_BUS_TYPE_VARIANT│ variant        │ signature    │ arguments    │       │           │                              │                │ string       │ appropriate  │       │           │                              │                │              │ for the      │       │           │                              │                │              │ types        │       │           │                              │                │              │ specified by │       │           │                              │                │              │ the          │       │           │                              │                │              │ signature    │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┴──────────────┤       │ "("       │SD_BUS_TYPE_STRUCT_BEGIN│ array start    │ arguments appropriate       │       ├───────────┼──────────────────────────────┼────────────────┤ for the structure           │       │ ")"       │SD_BUS_TYPE_STRUCT_END│ array end      │ elements                    │       ├───────────┼──────────────────────────────┼────────────────┼──────────────┬──────────────┤       │ "{"       │SD_BUS_TYPE_DICT_ENTRY_BEGIN│ dictionary     │ arguments    │ arguments    │       │           │                              │ entry start    │ appropriate  │ appropriate  │       ├───────────┼──────────────────────────────┼────────────────┤ for the      │ for the      │       │ "}"       │SD_BUS_TYPE_DICT_ENTRY_END│ dictionary     │ first type   │ second type  │       │           │                              │ entry end      │ in the pair  │ in the pair  │       └───────────┴──────────────────────────────┴────────────────┴──────────────┴──────────────┘       If objects of the specified types are not present at the current       position in the message, an error is returned.       Thesd_bus_message_readv()is equivalent to thesd_bus_message_read(), except that it is called with a "va_list"       instead of a variable number of arguments. This function does not       call theva_end()macro. Because it invokes theva_arg()macro,       the value ofap is undefined after the call.sd_bus_message_peek_type()determines the type of the next element       inm to be read bysd_bus_message_read()or similar functions. On       success, the type is stored intype, if it is notNULL. If the       type is a container type, the type of its elements is stored incontents, if it is notNULL. If this function successfully       determines the type of the next element inm, it returns a       positive integer. If there are no more elements to be read, it       returns zero.

RETURN VALUE        top

       On success, these functions return a non-negative integer. On       failure, they return a negative errno-style error code.Errors       Returned errors may indicate the following problems:-EINVAL           Specified type string is invalid or the message parameter isNULL.-ENXIO           The message does not contain the specified type at current           position.-EBADMSG           The message cannot be parsed.-EBUSY           When reading from a container, this error will be returned if           unread elements are left in the container.           Added in version 251.

NOTES        top

       Functions described here are available as a shared library, which       can be compiled against and linked to with thelibsystemd pkg-config(1) file.       The code described here usesgetenv(3), which is declared to be       not multi-thread-safe. This means that the code calling the       functions described here must not callsetenv(3) from a parallel       thread. It is recommended to only do calls tosetenv()from an       early phase of the program when no other threads have been       started.

EXAMPLES        top

       Read a single basic type (a 64-bit integer):           sd_bus_message *m;           int64_t x;           sd_bus_message_read(m, "x", &x);       Read a boolean value:           sd_bus_message *m;           int x; /* Do not use C99 "bool" type here, it is typically smaller                     in memory and would cause memory corruption */           sd_bus_message_read(m, "b", &x);       Read all types of integers:           uint8_t y;           int16_t n;           uint16_t q;           int32_t i;           uint32_t u;           int32_t x;           uint32_t t;           double d;           sd_bus_message_read(m, "ynqiuxtd", &y, &n, &q, &i, &u, &x, &t, &d);       Read a structure composed of a string and a D-Bus path:           const char *s, *p;           sd_bus_message_read(m, "(so)", &s, &p);       Read a variant, with the real type "gt" (signature, unsigned       integer):           const char *s;           uint64_t *v;           sd_bus_message_read(m, "v", "gt", &s, &v);       Read a dictionary containing three pairs of type       {integer=>string}:           int i, j, k;           const char *s, *t, *u;           sd_bus_message_read(m, "a{is}", 3, &i, &s, &j, &t, &k, &u);       Read a single file descriptor, and duplicate it in order to keep       it open after the message is freed.           sd_bus_message *m;           int fd, fd_copy;           sd_bus_message_read(m, "h", &fd);           fd_copy = fcntl(fd, FD_DUPFD_CLOEXEC, 3);

HISTORY        top

sd_bus_message_read()andsd_bus_message_readv()were added in       version 240.sd_bus_message_peek_type()was added in version 246.

SEE ALSO        top

systemd(1),sd-bus(3),sd_bus_message_read_basic(3),sd_bus_message_skip(3),sd_bus_message_append(3),sd_bus_message_enter_container(3)

COLOPHON        top

       This page is part of thesystemd (systemd system and service       manager) project.  Information about the project can be found at       ⟨http://www.freedesktop.org/wiki/Software/systemd⟩.  If you have a       bug report for this manual page, see       ⟨http://www.freedesktop.org/wiki/Software/systemd/#bugreports⟩.       This page was obtained from the project's upstream Git repository       ⟨https://github.com/systemd/systemd.git⟩ on 2025-08-11.  (At that       time, the date of the most recent commit that was found in the       repository was 2025-08-11.)  If you discover any rendering       problems in this HTML version of the page, or you believe there is       a better or more up-to-date source for the page, or you have       corrections or improvements to the information in this COLOPHON       (which isnot part of the original manual page), send a mail to       man-pages@man7.orgsystemd 258~rc2SD_BUS_MESSAGE_READ(3)

Pages that refer to this page:sd-bus(3)sd_bus_message_at_end(3)sd_bus_message_open_container(3)sd_bus_message_read_array(3)sd_bus_message_read_basic(3)sd_bus_message_read_strv(3)sd_bus_message_rewind(3)sd_bus_message_skip(3)systemd.directives(7)systemd.index(7)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp