SD_VARLINK_SERVER_NEW(3)
β¨ sd_varlink_server_new β¨
okay bestie, welcome to the sd_varlink_server_new(3) page π
it's a systemd man page, it lives in section 3, and it's all about birthing a brand new Varlink server object. let's get into it π«Ά
πΈ NAME πΈ
sd_varlink_server_new β allocate a Varlink server object, like, the whole entire thing π
π¦ SYNOPSIS π¦
#include <systemd/sd-varlink.h>
int sd_varlink_server_new(sd_varlink_server** ret,
sd_varlink_server_flags_t flags);
π DESCRIPTION π
so sd_varlink_server_new() allocates a shiny new Varlink server object for you. and like, initially it does not listen on any socket or file descriptor β it's just vibing there, existing, unbound, no cap. the freshly allocated server object gets handed back to you in the ret parameter. when you're done with it (and bestie, you will be done with it), use sd_varlink_server_unref() to release the server object again π
these are the flags you can pass in the flags parameter, and honestly? each one is kind of iconic:
SD_VARLINK_SERVER_ROOT_ONLYβ only allows connections from UID 0, aka the root user π. this has two effects: any incoming connection gets authenticated viaSO_PEERCREDto make sure the UID the kernel reports is zero, and if that check fails the connection is immediately terminated, no discussion, blocked π. plus, when binding a socket inode in the file system, the access mode is set to0600(instead of0666). and heads up β if you use this option, connections on non-AF_UNIXsockets or via pipes are never permitted. ever. periodt.SD_VARLINK_SERVER_MYSELF_ONLYβ very similar toSD_VARLINK_SERVER_ROOT_ONLY, but instead it enforces that the connecting client's UID must match the server's UID (i.e. the UID this function is invoked as). for servers that run as UID 0, these two flags are literally equivalent. and if you specify both flags in combination, then connections are allowed by both UID 0 and the server's own UID β best of both worlds, slay β¨SD_VARLINK_SERVER_ACCOUNT_UIDβ if set, connection accounting per client UID is enabled, and a limit on concurrent connections from the same UID gets enforced. you can set that limit viasd_varlink_server_set_connections_per_uid_max(), and it defaults to3/4thof the total concurrent connection limit, which you can set viasd_varlink_server_set_connections_max()πSD_VARLINK_SERVER_INHERIT_USERDATAβ if set, the user data field for incoming connection (i.e.sd_varlink) objects (as settable viasd_varlink_set_userdata()) is automatically set to the userdata field of the server (i.e.sd_varlink_server) object (as settable viasd_varlink_server_set_userdata()). if you don't specify this flag, the connection's user data field will just default toNULL. sad, but fine π₯²SD_VARLINK_SERVER_INPUT_SENSITIVEβ marks all incoming method call parameters as security sensitive (equivalent to callingsd_json_variant_sensitive()). this is so useful for services that deal with secrets and similar stuff, because it ensures the parameters are kept out of debug logging, and the memory used by the parameters is erased after use π. secrets stay secret, as they should πSD_VARLINK_SERVER_ALLOW_FD_PASSING_INPUTβ if set, allows receiving UNIX file descriptors via the connections, equivalent to callingsd_varlink_set_allow_fd_passing_input()immediately for each incoming connection. note that this only has an effect ifAF_UNIXsockets are used for communication πSD_VARLINK_SERVER_ALLOW_FD_PASSING_OUTPUTβ similar, but this one controls sending of UNIX file descriptors π€SD_VARLINK_SERVER_FD_PASSING_INPUT_STRICTβ this flag can be used in conjunction withSD_VARLINK_SERVER_ALLOW_FD_PASSING_INPUT. if you do, file descriptor passing is turned off on the listening sockets already, ensuring that the connection sockets derived from it at no time have file descriptor passing enabled. but ifSD_VARLINK_SERVER_ALLOW_FD_PASSING_INPUTis used withoutSD_VARLINK_SERVER_FD_PASSING_INPUT_STRICT, then a choice of when to prohibit or allow file descriptor passing can still be made after the connection came in β however, that permits a time window where file descriptors might already be enqueued, that then need to be dropped again π¬ so like, know what you're doing, bestieSD_VARLINK_SERVER_HANDLE_SIGINTβ if set, andsd_varlink_server_loop_auto()is used, incomingSIGINTprocess signals will be caught gracefully and cause the event loop to exit cleanly π§SD_VARLINK_SERVER_HANDLE_SIGTERMβ similar, but does the same thing forSIGTERMπ
β RETURN VALUE β
on success, sd_varlink_server_new() returns a non-negative integer π on failure, it returns a negative errno-style error code π
π Errors
returned errors may indicate the following problems:
-EINVALβ an argument is invalid. rude, but okay.
π NOTES π
the functions described here are available as a shared library, which you can compile against and link to with the libsystemd pkg-config(1) file π οΈ
the code described here uses getenv(3), which is declared to be not multi-thread-safe. this means that the code calling the functions described here must not call setenv(3) from a parallel thread. it is recommended to only do calls to setenv() from an early phase of the program, when no other threads have been started. like, do it at the beginning, before the chaos starts, fr fr π
π HISTORY π
sd_varlink_server_new() was added in version 257. she's new-ish, she's cute, she's here πΈ
π₯ SEE ALSO π₯
and that's the whole page bestie!! π this was systemd 262.1, from the SD_VARLINK_SERVER_NEW(3) era β go forth and allocate your servers, you've got this π«Άβ¨π
π¦ where this page comes from
- arch rolling: systemd-libs 262.1-1 Β· LGPL-2.1-or-later AND CC0-1.0 AND GPL-2.0-or-later WITH Linux-syscall-note
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms