mirror of
https://github.com/troglobit/finit.git
synced 2026-10-23 11:44:37 +00:00
libink/finit: properties, and org.finit on the system bus
Runlevel and version are state, not actions, so they belong behind org.freedesktop.DBus.Properties rather than another method each. Finit also claims org.finit on the system bus when it finds one, so ordinary D-Bus clients can reach it without knowing about /run/finit/bus. Opportunistic on purpose: no dbus-daemon is a normal state for the systems Finit runs on, not an error to report. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
dd1390a6c2
commit
ebc0ef62e6
22 files changed
+1474
-154
No files matched your search
+57
-1
@@ -15,6 +15,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -35,7 +36,7 @@ struct link_client {
|
||||
size_t rxlen;
|
||||
};
|
||||
|
||||
link_client_t *link_client_open(const char *path)
|
||||
link_client_t *link_client_open_timeout(const char *path, int timeout_ms)
|
||||
{
|
||||
struct sockaddr_un sun = { .sun_family = AF_UNIX };
|
||||
link_client_t *c;
|
||||
@@ -48,6 +49,20 @@ link_client_t *link_client_open(const char *path)
|
||||
fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
if (timeout_ms > 0) {
|
||||
struct timeval tv = {
|
||||
.tv_sec = timeout_ms / 1000,
|
||||
.tv_usec = (timeout_ms % 1000) * 1000,
|
||||
};
|
||||
/* Cover both directions so the AUTH write and the
|
||||
* subsequent read both honour the budget. setsockopt
|
||||
* failure is non-fatal -- the bus may still respond
|
||||
* quickly enough; we just lose the safety net. */
|
||||
(void)setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
|
||||
(void)setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||
}
|
||||
|
||||
if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) < 0) {
|
||||
close(fd);
|
||||
return NULL;
|
||||
@@ -67,6 +82,11 @@ link_client_t *link_client_open(const char *path)
|
||||
return c;
|
||||
}
|
||||
|
||||
link_client_t *link_client_open(const char *path)
|
||||
{
|
||||
return link_client_open_timeout(path, 0);
|
||||
}
|
||||
|
||||
void link_client_close(link_client_t *c)
|
||||
{
|
||||
if (!c)
|
||||
@@ -76,6 +96,18 @@ void link_client_close(link_client_t *c)
|
||||
free(c);
|
||||
}
|
||||
|
||||
int link_client_steal_fd(link_client_t *c)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (!c)
|
||||
return -1;
|
||||
fd = c->fd;
|
||||
c->fd = -1;
|
||||
free(c);
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* read_full / send_all live in libink/io.c. */
|
||||
#define read_full(fd, buf, len) __io_read_full ((fd), (buf), (len))
|
||||
#define send_all(fd, buf, len) __io_write_all((fd), (buf), (len))
|
||||
@@ -229,6 +261,30 @@ const link_reply_t *link_client_reply(link_client_t *c)
|
||||
return &c->reply;
|
||||
}
|
||||
|
||||
int link_reply_get_string(const link_reply_t *r, const char **out)
|
||||
{
|
||||
link_reader_t reader;
|
||||
|
||||
if (out)
|
||||
*out = NULL;
|
||||
if (!r || !r->body || !out)
|
||||
return -1;
|
||||
link_reader_init(&reader, r->body, r->body_len);
|
||||
return link_r_string(&reader, out);
|
||||
}
|
||||
|
||||
int link_reply_get_u32(const link_reply_t *r, uint32_t *out)
|
||||
{
|
||||
link_reader_t reader;
|
||||
|
||||
if (out)
|
||||
*out = 0;
|
||||
if (!r || !r->body || !out)
|
||||
return -1;
|
||||
link_reader_init(&reader, r->body, r->body_len);
|
||||
return link_r_u32(&reader, out);
|
||||
}
|
||||
|
||||
/* Marshal varargs into `body` (capacity `cap`) according to `sig`.
|
||||
* Returns the marshalled length on success, -1 on overflow or
|
||||
* unsupported type code. */
|
||||
|
||||
Reference in new issue
Block a user