本文整理汇总了C++中sd_event_default函数的典型用法代码示例。如果您正苦于以下问题:C++ sd_event_default函数的具体用法?C++ sd_event_default怎么用?C++ sd_event_default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sd_event_default函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: new0
Manager *manager_new(void) {
Manager *m;
int r;
m = new0(Manager, 1);
if (!m)
return NULL;
m->machines = hashmap_new(&string_hash_ops);
m->machine_units = hashmap_new(&string_hash_ops);
m->machine_leaders = hashmap_new(NULL);
if (!m->machines || !m->machine_units || !m->machine_leaders) {
manager_free(m);
return NULL;
}
r = sd_event_default(&m->event);
if (r < 0) {
manager_free(m);
return NULL;
}
sd_event_set_watchdog(m->event, true);
return m;
}
示例2: manager_new
static int manager_new(Manager **ret) {
_cleanup_(manager_unrefp) Manager *m = NULL;
int r;
assert(ret);
m = new0(Manager, 1);
if (!m)
return -ENOMEM;
m->machines = hashmap_new(&string_hash_ops);
m->machine_units = hashmap_new(&string_hash_ops);
m->machine_leaders = hashmap_new(NULL);
if (!m->machines || !m->machine_units || !m->machine_leaders)
return -ENOMEM;
r = sd_event_default(&m->event);
if (r < 0)
return r;
r = sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL);
if (r < 0)
return r;
r = sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL);
if (r < 0)
return r;
(void) sd_event_set_watchdog(m->event, true);
*ret = TAKE_PTR(m);
return 0;
}
示例3: raw_export_new
int raw_export_new(
RawExport **ret,
sd_event *event,
RawExportFinished on_finished,
void *userdata) {
_cleanup_(raw_export_unrefp) RawExport *e = NULL;
int r;
assert(ret);
e = new0(RawExport, 1);
if (!e)
return -ENOMEM;
e->output_fd = e->input_fd = -1;
e->on_finished = on_finished;
e->userdata = userdata;
RATELIMIT_INIT(e->progress_rate_limit, 100 * USEC_PER_MSEC, 1);
e->last_percent = (unsigned) -1;
if (event)
e->event = sd_event_ref(event);
else {
r = sd_event_default(&e->event);
if (r < 0)
return r;
}
*ret = TAKE_PTR(e);
return 0;
}
示例4: event_attach_mainloop
static int
event_attach_mainloop(void)
{
int r;
sd_event *e = NULL;
if (_ctx.mainloop_source)
return 0;
r = sd_event_default(&e);
if (r < 0)
return r;
_ctx.mainloop_source = event_create_source(e);
if (!_ctx.mainloop_source)
goto fail;
sd_event_add_defer(e, &_ctx.ping, _event_mainloop_running, &_ctx);
return 0;
fail:
sd_event_unref(e);
return -ENOMEM;
}
示例5: sd_event_default
static struct rtsp *start_test_client(void)
{
int r, fds[2] = { };
r = sd_event_default(&event);
ck_assert_int_ge(r, 0);
r = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
ck_assert_int_ge(r, 0);
ck_assert_int_ge(fds[0], 0);
ck_assert_int_ge(fds[1], 0);
r = rtsp_open(&server, fds[0]);
ck_assert_int_ge(r, 0);
r = rtsp_attach_event(server, event, 0);
ck_assert_int_ge(r, 0);
r = rtsp_open(&client, fds[1]);
ck_assert_int_ge(r, 0);
r = rtsp_attach_event(client, event, 0);
ck_assert_int_ge(r, 0);
return client;
}
示例6: new0
Manager *manager_new(void) {
Manager *m;
int r;
m = new0(Manager, 1);
if (!m)
return NULL;
m->machines = hashmap_new(string_hash_func, string_compare_func);
m->machine_units = hashmap_new(string_hash_func, string_compare_func);
m->machine_leaders = hashmap_new(trivial_hash_func, trivial_compare_func);
if (!m->machines || !m->machine_units || !m->machine_leaders) {
manager_free(m);
return NULL;
}
r = sd_event_default(&m->event);
if (r < 0) {
manager_free(m);
return NULL;
}
return m;
}
示例7: DbusApiInit
void DbusApiInit(int sock)
{
fd = sock;
sd_event_source *busSource = NULL;
sd_bus_slot *slot = NULL;
int ret = sd_event_default(&event);
char tmp = '0';
read(fd, &tmp, sizeof(char));
ret = sd_bus_open_system(&bus);
ret = sd_bus_add_object_vtable(bus, &slot, "/org/watchdogd1",
"org.watchdogd1", watchdogPmon, NULL);
ret = sd_bus_request_name(bus, "org.watchdogd1", 0);
if (ret < 0) {
ReloadDbusDaemon();
ret = sd_bus_request_name(bus, "org.watchdogd1", 0);
}
sd_event_add_io(event, &busSource, sd_bus_get_fd(bus), EPOLLIN, BusHandler, NULL);
sd_event_loop(event);
}
示例8: test_pty
static void test_pty(void) {
pid_t pid;
Pty *pty;
rcvsiz = 0;
zero(rcvbuf);
assert_se(sd_event_default(&event) >= 0);
pid = pty_fork(&pty, event, pty_fn, NULL, 80, 25);
assert_se(pid >= 0);
if (pid == 0) {
/* child */
run_child(pty);
exit(0);
}
/* parent */
run_parent(pty);
/* Make sure the PTY recycled the child; yeah, this is racy if the
* PID was already reused; but that seems fine for a test. */
assert_se(waitpid(pid, NULL, WNOHANG) < 0 && errno == ECHILD);
pty_unref(pty);
sd_event_unref(event);
}
示例9: main
int main(int argc, char *argv[]) {
Context context = {};
int r, n, fd;
log_parse_environment();
log_open();
r = parse_argv(argc, argv);
if (r <= 0)
goto finish;
r = sd_event_default(&context.event);
if (r < 0) {
log_error_errno(r, "Failed to allocate event loop: %m");
goto finish;
}
r = sd_resolve_default(&context.resolve);
if (r < 0) {
log_error_errno(r, "Failed to allocate resolver: %m");
goto finish;
}
r = sd_resolve_attach_event(context.resolve, context.event, 0);
if (r < 0) {
log_error_errno(r, "Failed to attach resolver: %m");
goto finish;
}
sd_event_set_watchdog(context.event, true);
n = sd_listen_fds(1);
if (n < 0) {
log_error("Failed to receive sockets from parent.");
r = n;
goto finish;
} else if (n == 0) {
log_error("Didn't get any sockets passed in.");
r = -EINVAL;
goto finish;
}
for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) {
r = add_listen_socket(&context, fd);
if (r < 0)
goto finish;
}
r = sd_event_loop(context.event);
if (r < 0) {
log_error_errno(r, "Failed to run event loop: %m");
goto finish;
}
finish:
context_free(&context);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
示例10: dkr_pull_new
int dkr_pull_new(
DkrPull **ret,
sd_event *event,
const char *index_url,
const char *image_root,
DkrPullFinished on_finished,
void *userdata) {
_cleanup_(dkr_pull_unrefp) DkrPull *i = NULL;
char *e;
int r;
assert(ret);
assert(index_url);
if (!http_url_is_valid(index_url))
return -EINVAL;
i = new0(DkrPull, 1);
if (!i)
return -ENOMEM;
i->on_finished = on_finished;
i->userdata = userdata;
i->image_root = strdup(image_root ?: "/var/lib/machines");
if (!i->image_root)
return -ENOMEM;
i->grow_machine_directory = path_startswith(i->image_root, "/var/lib/machines");
i->index_url = strdup(index_url);
if (!i->index_url)
return -ENOMEM;
e = endswith(i->index_url, "/");
if (e)
*e = 0;
if (event)
i->event = sd_event_ref(event);
else {
r = sd_event_default(&i->event);
if (r < 0)
return r;
}
r = curl_glue_new(&i->glue, i->event);
if (r < 0)
return r;
i->glue->on_finished = pull_job_curl_on_finished;
i->glue->userdata = i;
*ret = i;
i = NULL;
return 0;
}
示例11: manager_new
int manager_new(Manager **ret) {
_cleanup_manager_free_ Manager *m = NULL;
int r;
m = new0(Manager, 1);
if (!m)
return -ENOMEM;
r = sd_event_default(&m->event);
if (r < 0)
return r;
sd_event_set_watchdog(m->event, true);
r = sd_rtnl_open(&m->rtnl, RTMGRP_LINK | RTMGRP_IPV4_IFADDR);
if (r < 0)
return r;
r = sd_bus_default_system(&m->bus);
if (r < 0 && r != -ENOENT) /* TODO: drop when we can rely on kdbus */
return r;
r = setup_signals(m);
if (r < 0)
return r;
m->udev = udev_new();
if (!m->udev)
return -ENOMEM;
/* udev does not initialize devices inside containers,
* so we rely on them being already initialized before
* entering the container */
if (detect_container(NULL) > 0) {
m->udev_monitor = udev_monitor_new_from_netlink(m->udev, "kernel");
if (!m->udev_monitor)
return -ENOMEM;
} else {
m->udev_monitor = udev_monitor_new_from_netlink(m->udev, "udev");
if (!m->udev_monitor)
return -ENOMEM;
}
m->links = hashmap_new(uint64_hash_func, uint64_compare_func);
if (!m->links)
return -ENOMEM;
m->netdevs = hashmap_new(string_hash_func, string_compare_func);
if (!m->netdevs)
return -ENOMEM;
LIST_HEAD_INIT(m->networks);
*ret = m;
m = NULL;
return 0;
}
示例12: main
int main(int argc, char *argv[]) {
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
_cleanup_(sd_bus_track_unrefp) sd_bus_track *x = NULL, *y = NULL;
_cleanup_(sd_bus_unrefp) sd_bus *a = NULL, *b = NULL;
const char *unique;
int r;
r = sd_event_default(&event);
assert_se(r >= 0);
r = sd_bus_open_system(&a);
if (IN_SET(r, -ECONNREFUSED, -ENOENT)) {
log_info("Failed to connect to bus, skipping tests.");
return EXIT_TEST_SKIP;
}
assert_se(r >= 0);
r = sd_bus_attach_event(a, event, SD_EVENT_PRIORITY_NORMAL);
assert_se(r >= 0);
r = sd_bus_open_system(&b);
assert_se(r >= 0);
r = sd_bus_attach_event(b, event, SD_EVENT_PRIORITY_NORMAL);
assert_se(r >= 0);
/* Watch b's name from a */
r = sd_bus_track_new(a, &x, track_cb_x, NULL);
assert_se(r >= 0);
r = sd_bus_get_unique_name(b, &unique);
assert_se(r >= 0);
r = sd_bus_track_add_name(x, unique);
assert_se(r >= 0);
/* Watch's a's own name from a */
r = sd_bus_track_new(a, &y, track_cb_y, NULL);
assert_se(r >= 0);
r = sd_bus_get_unique_name(a, &unique);
assert_se(r >= 0);
r = sd_bus_track_add_name(y, unique);
assert_se(r >= 0);
/* Now make b's name disappear */
sd_bus_close(b);
r = sd_event_loop(event);
assert_se(r >= 0);
assert_se(track_cb_called_x);
assert_se(track_cb_called_y);
return 0;
}
示例13: device_wait_for_initialization
int device_wait_for_initialization(sd_device *device, const char *subsystem, sd_device **ret) {
_cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor = NULL;
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
struct DeviceMonitorData data = {};
int r;
assert(device);
assert(subsystem);
if (sd_device_get_is_initialized(device) > 0) {
if (ret)
*ret = sd_device_ref(device);
return 0;
}
assert_se(sd_device_get_sysname(device, &data.sysname) >= 0);
/* Wait until the device is initialized, so that we can get access to the ID_PATH property */
r = sd_event_default(&event);
if (r < 0)
return log_error_errno(r, "Failed to get default event: %m");
r = sd_device_monitor_new(&monitor);
if (r < 0)
return log_error_errno(r, "Failed to acquire monitor: %m");
r = sd_device_monitor_filter_add_match_subsystem_devtype(monitor, subsystem, NULL);
if (r < 0)
return log_error_errno(r, "Failed to add %s subsystem match to monitor: %m", subsystem);
r = sd_device_monitor_attach_event(monitor, event);
if (r < 0)
return log_error_errno(r, "Failed to attach event to device monitor: %m");
r = sd_device_monitor_start(monitor, device_monitor_handler, &data);
if (r < 0)
return log_error_errno(r, "Failed to start device monitor: %m");
/* Check again, maybe things changed. Udev will re-read the db if the device wasn't initialized
* yet. */
if (sd_device_get_is_initialized(device) > 0) {
if (ret)
*ret = sd_device_ref(device);
return 0;
}
r = sd_event_loop(event);
if (r < 0)
return log_error_errno(r, "Event loop failed: %m");
if (ret)
*ret = TAKE_PTR(data.device);
return 0;
}
示例14: manager_new
int manager_new(Manager **ret) {
_cleanup_manager_free_ Manager *m = NULL;
int r;
m = new0(Manager, 1);
if (!m)
return -ENOMEM;
r = sd_event_default(&m->event);
if (r < 0)
return r;
sd_event_set_watchdog(m->event, true);
r = sd_rtnl_open(RTMGRP_LINK | RTMGRP_IPV4_IFADDR, &m->rtnl);
if (r < 0)
return r;
m->udev = udev_new();
if (!m->udev)
return -ENOMEM;
m->udev_monitor = udev_monitor_new_from_netlink(m->udev, "udev");
if (!m->udev_monitor)
return -ENOMEM;
m->links = hashmap_new(uint64_hash_func, uint64_compare_func);
if (!m->links)
return -ENOMEM;
m->bridges = hashmap_new(string_hash_func, string_compare_func);
if (!m->bridges)
return -ENOMEM;
LIST_HEAD_INIT(m->networks);
m->network_dirs = strv_new("/etc/systemd/network/",
"/run/systemd/network/",
"/usr/lib/systemd/network",
#ifdef HAVE_SPLIT_USER
"/lib/systemd/network",
#endif
NULL);
if (!m->network_dirs)
return -ENOMEM;
if (!path_strv_canonicalize_uniq(m->network_dirs))
return -ENOMEM;
*ret = m;
m = NULL;
return 0;
}
示例15: main
int main(int argc, char *argv[]) {
Context context = {};
_cleanup_event_unref_ sd_event *event = NULL;
_cleanup_bus_close_unref_ sd_bus *bus = NULL;
int r;
log_set_target(LOG_TARGET_AUTO);
log_parse_environment();
log_open();
umask(0022);
mac_selinux_init("/etc");
if (argc != 1) {
log_error("This program takes no arguments.");
r = -EINVAL;
goto finish;
}
if (argc != 1) {
log_error("This program takes no arguments.");
r = -EINVAL;
goto finish;
}
r = sd_event_default(&event);
if (r < 0) {
log_error_errno(r, "Failed to allocate event loop: %m");
goto finish;
}
sd_event_set_watchdog(event, true);
r = connect_bus(&context, event, &bus);
if (r < 0)
goto finish;
r = context_read_data(&context);
if (r < 0) {
log_error_errno(r, "Failed to read hostname and machine information: %m");
goto finish;
}
r = bus_event_loop_with_idle(event, bus, "org.freedesktop.hostname1", DEFAULT_EXIT_USEC, NULL, NULL);
if (r < 0) {
log_error_errno(r, "Failed to run event loop: %m");
goto finish;
}
finish:
context_free(&context);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}