Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2016 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brad Bishop | 36eb1e5 | 2016-11-01 15:18:36 -0400 | [diff] [blame] | 16 | #include "config.h" |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 17 | #include <stdlib.h> |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 18 | #include <string.h> |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <errno.h> |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 21 | #include <unistd.h> |
| 22 | #include <sys/timerfd.h> |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 23 | #include <systemd/sd-bus.h> |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 24 | #include <systemd/sd-event.h> |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 25 | #include "mapper.h" |
| 26 | |
Brad Bishop | 829181d | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 27 | static const char *async_wait_introspection_match = |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 28 | "type='signal'," |
| 29 | "sender='xyz.openbmc_project.ObjectMapper'," |
| 30 | "interface='xyz.openbmc_project.ObjectMapper.Private'," |
| 31 | "member='IntrospectionComplete'"; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 32 | |
| 33 | static const char *async_wait_interfaces_added_match = |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 34 | "type='signal'," |
| 35 | "interface='org.freedesktop.DBus.ObjectManager'," |
| 36 | "member='InterfacesAdded'"; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 37 | |
Adriana Kobylak | 78edbb6 | 2017-05-04 15:45:19 -0500 | [diff] [blame] | 38 | static const char *interfaces_removed_match = |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 39 | "type='signal'," |
| 40 | "interface='org.freedesktop.DBus.ObjectManager'," |
| 41 | "member='InterfacesRemoved'"; |
Adriana Kobylak | 78edbb6 | 2017-05-04 15:45:19 -0500 | [diff] [blame] | 42 | |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 43 | static const int mapper_busy_retries = 5; |
| 44 | static const uint64_t mapper_busy_delay_interval_usec = 1000000; |
| 45 | |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 46 | struct mapper_async_wait |
| 47 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 48 | char **objs; |
| 49 | void (*callback)(int, void *); |
| 50 | void *userdata; |
| 51 | sd_event *loop; |
| 52 | sd_bus *conn; |
| 53 | sd_bus_slot *introspection_slot; |
| 54 | sd_bus_slot *intf_slot; |
| 55 | int *status; |
| 56 | int count; |
| 57 | int finished; |
| 58 | int r; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | struct async_wait_callback_data |
| 62 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 63 | mapper_async_wait *wait; |
| 64 | const char *path; |
| 65 | sd_event_source *event_source; |
| 66 | int retry; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 67 | }; |
| 68 | |
Adriana Kobylak | 2a8bfc9 | 2017-05-11 09:16:02 -0500 | [diff] [blame] | 69 | struct mapper_async_subtree |
| 70 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 71 | char *namespace; |
| 72 | char *interface; |
| 73 | void (*callback)(int, void *); |
| 74 | void *userdata; |
| 75 | sd_event *loop; |
| 76 | sd_bus *conn; |
| 77 | sd_bus_slot *slot; |
| 78 | sd_event_source *event_source; |
| 79 | int finished; |
| 80 | int op; |
| 81 | int retry; |
Adriana Kobylak | 2a8bfc9 | 2017-05-11 09:16:02 -0500 | [diff] [blame] | 82 | }; |
| 83 | |
Brad Bishop | 829181d | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 84 | static int async_wait_match_introspection_complete(sd_bus_message *, void *, |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 85 | sd_bus_error *); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 86 | static int async_wait_check_done(mapper_async_wait *); |
| 87 | static void async_wait_done(int r, mapper_async_wait *); |
| 88 | static int async_wait_get_objects(mapper_async_wait *); |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 89 | static int async_wait_getobject_callback(sd_bus_message *, void *, |
| 90 | sd_bus_error *); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 91 | |
Adriana Kobylak | 78edbb6 | 2017-05-04 15:45:19 -0500 | [diff] [blame] | 92 | static int async_subtree_match_callback(sd_bus_message *, void *, |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 93 | sd_bus_error *); |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 94 | static void async_subtree_done(int r, mapper_async_subtree *); |
Adriana Kobylak | 025d795 | 2017-05-08 13:30:45 -0500 | [diff] [blame] | 95 | static int async_subtree_getpaths(mapper_async_subtree *); |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 96 | static int async_subtree_getpaths_callback(sd_bus_message *, void *, |
| 97 | sd_bus_error *); |
Adriana Kobylak | 78edbb6 | 2017-05-04 15:45:19 -0500 | [diff] [blame] | 98 | |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 99 | static int sarraylen(char *array[]) |
| 100 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 101 | int count = 0; |
| 102 | char **p = array; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 103 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 104 | while (*p != NULL) |
| 105 | { |
| 106 | ++count; |
| 107 | ++p; |
| 108 | } |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 109 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 110 | return count; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static void sarrayfree(char *array[]) |
| 114 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 115 | char **p = array; |
| 116 | while (*p != NULL) |
| 117 | { |
| 118 | free(*p); |
| 119 | ++p; |
| 120 | } |
| 121 | free(array); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static char **sarraydup(char *array[]) |
| 125 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 126 | int count = sarraylen(array); |
| 127 | int i; |
| 128 | char **ret = NULL; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 129 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 130 | ret = malloc(sizeof(*ret) * count); |
| 131 | if (!ret) |
| 132 | return NULL; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 133 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 134 | for (i = 0; i < count; ++i) |
| 135 | { |
| 136 | ret[i] = strdup(array[i]); |
| 137 | if (!ret[i]) |
| 138 | goto error; |
| 139 | } |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 140 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 141 | return ret; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 142 | |
| 143 | error: |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 144 | sarrayfree(ret); |
| 145 | return NULL; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 146 | } |
| 147 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 148 | static int async_wait_timeout_callback(sd_event_source *s, uint64_t usec, |
| 149 | void *userdata) |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 150 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 151 | int r; |
| 152 | struct async_wait_callback_data *data = userdata; |
| 153 | mapper_async_wait *wait = data->wait; |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 154 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 155 | sd_event_source_unref(data->event_source); |
| 156 | r = sd_bus_call_method_async(wait->conn, NULL, MAPPER_BUSNAME, MAPPER_PATH, |
| 157 | MAPPER_INTERFACE, "GetObject", |
| 158 | async_wait_getobject_callback, data, "sas", |
| 159 | data->path, 0, NULL); |
| 160 | if (r < 0) |
| 161 | { |
| 162 | async_wait_done(r, wait); |
| 163 | free(data); |
| 164 | } |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 165 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 166 | return 0; |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 167 | } |
| 168 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 169 | static int async_wait_getobject_callback(sd_bus_message *m, void *userdata, |
| 170 | sd_bus_error *e) |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 171 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 172 | int i, r; |
| 173 | struct async_wait_callback_data *data = userdata; |
| 174 | mapper_async_wait *wait = data->wait; |
| 175 | uint64_t now; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 176 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 177 | if (wait->finished) |
| 178 | goto exit; |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 179 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 180 | r = sd_bus_message_get_errno(m); |
| 181 | if (r == ENOENT) |
| 182 | goto exit; |
Brad Bishop | 8ccdaed | 2016-09-20 15:54:32 -0400 | [diff] [blame] | 183 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 184 | if (r == EBUSY && data->retry < mapper_busy_retries) |
| 185 | { |
| 186 | r = sd_event_now(wait->loop, CLOCK_MONOTONIC, &now); |
| 187 | if (r < 0) |
| 188 | { |
| 189 | async_wait_done(r, wait); |
| 190 | goto exit; |
| 191 | } |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 192 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 193 | ++data->retry; |
| 194 | r = sd_event_add_time(wait->loop, &data->event_source, CLOCK_MONOTONIC, |
| 195 | now + mapper_busy_delay_interval_usec, 0, |
| 196 | async_wait_timeout_callback, data); |
| 197 | if (r < 0) |
| 198 | { |
| 199 | async_wait_done(r, wait); |
| 200 | goto exit; |
| 201 | } |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 202 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 203 | return 0; |
| 204 | } |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 205 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 206 | if (r) |
| 207 | { |
| 208 | async_wait_done(-r, wait); |
| 209 | goto exit; |
| 210 | } |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 211 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 212 | for (i = 0; i < wait->count; ++i) |
| 213 | { |
| 214 | if (!strcmp(data->path, wait->objs[i])) |
| 215 | { |
| 216 | wait->status[i] = 1; |
| 217 | } |
| 218 | } |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 219 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 220 | if (async_wait_check_done(wait)) |
| 221 | async_wait_done(0, wait); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 222 | |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 223 | exit: |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 224 | free(data); |
| 225 | return 0; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | static int async_wait_get_objects(mapper_async_wait *wait) |
| 229 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 230 | int i, r; |
| 231 | struct async_wait_callback_data *data = NULL; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 232 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 233 | for (i = 0; i < wait->count; ++i) |
| 234 | { |
| 235 | if (wait->status[i]) |
| 236 | continue; |
| 237 | data = malloc(sizeof(*data)); |
| 238 | data->wait = wait; |
| 239 | data->path = wait->objs[i]; |
| 240 | data->retry = 0; |
| 241 | data->event_source = NULL; |
| 242 | r = sd_bus_call_method_async(wait->conn, NULL, MAPPER_BUSNAME, |
| 243 | MAPPER_PATH, MAPPER_INTERFACE, "GetObject", |
| 244 | async_wait_getobject_callback, data, "sas", |
| 245 | wait->objs[i], 0, NULL); |
| 246 | if (r < 0) |
| 247 | { |
| 248 | free(data); |
| 249 | fprintf(stderr, "Error invoking method: %s\n", strerror(-r)); |
| 250 | return r; |
| 251 | } |
| 252 | } |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 253 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 254 | return 0; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 255 | } |
| 256 | |
Brad Bishop | 829181d | 2017-02-24 09:49:14 -0500 | [diff] [blame] | 257 | static int async_wait_match_introspection_complete(sd_bus_message *m, void *w, |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 258 | sd_bus_error *e) |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 259 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 260 | int r; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 261 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 262 | mapper_async_wait *wait = w; |
| 263 | if (wait->finished) |
| 264 | return 0; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 265 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 266 | r = async_wait_get_objects(wait); |
| 267 | if (r < 0) |
| 268 | async_wait_done(r, wait); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 269 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 270 | return 0; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 273 | static void async_wait_done(int r, mapper_async_wait *w) |
| 274 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 275 | if (w->finished) |
| 276 | return; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 277 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 278 | w->finished = 1; |
| 279 | sd_bus_slot_unref(w->introspection_slot); |
| 280 | sd_bus_slot_unref(w->intf_slot); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 281 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 282 | if (w->callback) |
| 283 | w->callback(r, w->userdata); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | static int async_wait_check_done(mapper_async_wait *w) |
| 287 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 288 | int i; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 289 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 290 | if (w->finished) |
| 291 | return 1; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 292 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 293 | for (i = 0; i < w->count; ++i) |
| 294 | if (!w->status[i]) |
| 295 | return 0; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 296 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 297 | return 1; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | void mapper_wait_async_free(mapper_async_wait *w) |
| 301 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 302 | free(w->status); |
| 303 | sarrayfree(w->objs); |
| 304 | free(w); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 305 | } |
| 306 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 307 | int mapper_wait_async(sd_bus *conn, sd_event *loop, char *objs[], |
| 308 | void (*callback)(int, void *), void *userdata, |
| 309 | mapper_async_wait **w) |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 310 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 311 | int r; |
| 312 | mapper_async_wait *wait = NULL; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 313 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 314 | wait = malloc(sizeof(*wait)); |
| 315 | if (!wait) |
| 316 | return -ENOMEM; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 317 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 318 | memset(wait, 0, sizeof(*wait)); |
| 319 | wait->conn = conn; |
| 320 | wait->loop = loop; |
| 321 | wait->callback = callback; |
| 322 | wait->userdata = userdata; |
| 323 | wait->count = sarraylen(objs); |
| 324 | if (!wait->count) |
| 325 | return 0; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 326 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 327 | wait->objs = sarraydup(objs); |
| 328 | if (!wait->objs) |
| 329 | { |
| 330 | r = -ENOMEM; |
| 331 | goto free_wait; |
| 332 | } |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 333 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 334 | wait->status = malloc(sizeof(*wait->status) * wait->count); |
| 335 | if (!wait->status) |
| 336 | { |
| 337 | r = -ENOMEM; |
| 338 | goto free_objs; |
| 339 | } |
| 340 | memset(wait->status, 0, sizeof(*wait->status) * wait->count); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 341 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 342 | r = sd_bus_add_match(conn, &wait->introspection_slot, |
| 343 | async_wait_introspection_match, |
| 344 | async_wait_match_introspection_complete, wait); |
| 345 | if (r < 0) |
| 346 | { |
| 347 | fprintf(stderr, "Error adding match rule: %s\n", strerror(-r)); |
| 348 | goto free_status; |
| 349 | } |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 350 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 351 | r = sd_bus_add_match(conn, &wait->intf_slot, |
| 352 | async_wait_interfaces_added_match, |
| 353 | async_wait_match_introspection_complete, wait); |
| 354 | if (r < 0) |
| 355 | { |
| 356 | fprintf(stderr, "Error adding match rule: %s\n", strerror(-r)); |
| 357 | goto unref_name_slot; |
| 358 | } |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 359 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 360 | r = async_wait_get_objects(wait); |
| 361 | if (r < 0) |
| 362 | { |
| 363 | fprintf(stderr, "Error calling method: %s\n", strerror(-r)); |
| 364 | goto unref_intf_slot; |
| 365 | } |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 366 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 367 | *w = wait; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 368 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 369 | return 0; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 370 | |
| 371 | unref_intf_slot: |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 372 | sd_bus_slot_unref(wait->intf_slot); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 373 | unref_name_slot: |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 374 | sd_bus_slot_unref(wait->introspection_slot); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 375 | free_status: |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 376 | free(wait->status); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 377 | free_objs: |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 378 | sarrayfree(wait->objs); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 379 | free_wait: |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 380 | free(wait); |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 381 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 382 | return r; |
Brad Bishop | 2afe718 | 2016-08-13 14:08:17 -0400 | [diff] [blame] | 383 | } |
| 384 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 385 | static int async_subtree_timeout_callback(sd_event_source *s, uint64_t usec, |
| 386 | void *userdata) |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 387 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 388 | int r; |
| 389 | struct mapper_async_subtree *subtree = userdata; |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 390 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 391 | sd_event_source_unref(subtree->event_source); |
| 392 | r = sd_bus_call_method_async( |
| 393 | subtree->conn, NULL, MAPPER_BUSNAME, MAPPER_PATH, MAPPER_INTERFACE, |
| 394 | "GetSubTreePaths", async_subtree_getpaths_callback, subtree, "sias", |
| 395 | subtree->namespace, 0, 1, subtree->interface); |
| 396 | if (r < 0) |
| 397 | async_subtree_done(r, subtree); |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 398 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 399 | return 0; |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 400 | } |
| 401 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 402 | static int async_subtree_getpaths_callback(sd_bus_message *m, void *userdata, |
| 403 | sd_bus_error *e) |
Adriana Kobylak | 025d795 | 2017-05-08 13:30:45 -0500 | [diff] [blame] | 404 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 405 | int r; |
| 406 | char *intf = NULL; |
| 407 | struct mapper_async_subtree *subtree = userdata; |
| 408 | uint64_t now; |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 409 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 410 | if (subtree->finished) |
| 411 | goto exit; |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 412 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 413 | r = sd_bus_message_get_errno(m); |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 414 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 415 | if (r == ENOENT) |
| 416 | { |
| 417 | if (subtree->op == MAPPER_OP_REMOVE) |
| 418 | r = 0; |
| 419 | else |
| 420 | goto exit; |
| 421 | } |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 422 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 423 | if (r == EBUSY && subtree->retry < mapper_busy_retries) |
| 424 | { |
| 425 | r = sd_event_now(subtree->loop, CLOCK_MONOTONIC, &now); |
| 426 | if (r < 0) |
| 427 | { |
| 428 | async_subtree_done(r, subtree); |
| 429 | goto exit; |
| 430 | } |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 431 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 432 | ++subtree->retry; |
| 433 | r = sd_event_add_time(subtree->loop, &subtree->event_source, |
| 434 | CLOCK_MONOTONIC, |
| 435 | now + mapper_busy_delay_interval_usec, 0, |
| 436 | async_subtree_timeout_callback, subtree); |
| 437 | if (r < 0) |
| 438 | { |
| 439 | async_subtree_done(r, subtree); |
| 440 | goto exit; |
| 441 | } |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 442 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 443 | return 0; |
| 444 | } |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 445 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 446 | if (r) |
| 447 | { |
| 448 | async_subtree_done(-r, subtree); |
| 449 | goto exit; |
| 450 | } |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 451 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 452 | sd_bus_message_read(m, "as", 1, &intf); |
| 453 | if (subtree->op == MAPPER_OP_REMOVE) |
| 454 | { |
| 455 | /* For remove, operation is complete when the interface is not present |
| 456 | */ |
| 457 | if (intf == NULL) |
| 458 | async_subtree_done(0, subtree); |
| 459 | } |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 460 | |
| 461 | exit: |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 462 | return 0; |
Adriana Kobylak | 025d795 | 2017-05-08 13:30:45 -0500 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | static int async_subtree_getpaths(mapper_async_subtree *subtree) |
| 466 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 467 | int r = 0; |
Adriana Kobylak | 025d795 | 2017-05-08 13:30:45 -0500 | [diff] [blame] | 468 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 469 | subtree->retry = 0; |
| 470 | subtree->event_source = NULL; |
| 471 | r = sd_bus_call_method_async( |
| 472 | subtree->conn, NULL, MAPPER_BUSNAME, MAPPER_PATH, MAPPER_INTERFACE, |
| 473 | "GetSubTreePaths", async_subtree_getpaths_callback, subtree, "sias", |
| 474 | subtree->namespace, 0, 1, subtree->interface); |
| 475 | if (r < 0) |
| 476 | { |
| 477 | fprintf(stderr, "Error invoking method: %s\n", strerror(-r)); |
| 478 | return r; |
| 479 | } |
Adriana Kobylak | 025d795 | 2017-05-08 13:30:45 -0500 | [diff] [blame] | 480 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 481 | return 0; |
Adriana Kobylak | 025d795 | 2017-05-08 13:30:45 -0500 | [diff] [blame] | 482 | } |
| 483 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 484 | static int async_subtree_match_callback(sd_bus_message *m, void *t, |
| 485 | sd_bus_error *e) |
Adriana Kobylak | 78edbb6 | 2017-05-04 15:45:19 -0500 | [diff] [blame] | 486 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 487 | int r; |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 488 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 489 | mapper_async_subtree *subtree = t; |
| 490 | if (subtree->finished) |
| 491 | return 0; |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 492 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 493 | r = async_subtree_getpaths(subtree); |
| 494 | if (r < 0) |
| 495 | async_subtree_done(r, subtree); |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 496 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 497 | return 0; |
Adriana Kobylak | 78edbb6 | 2017-05-04 15:45:19 -0500 | [diff] [blame] | 498 | } |
| 499 | |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 500 | static void async_subtree_done(int r, mapper_async_subtree *t) |
| 501 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 502 | if (t->finished) |
| 503 | return; |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 504 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 505 | t->finished = 1; |
| 506 | sd_bus_slot_unref(t->slot); |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 507 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 508 | if (t->callback) |
| 509 | t->callback(r, t->userdata); |
Adriana Kobylak | b2f2681 | 2017-05-08 13:58:02 -0500 | [diff] [blame] | 510 | } |
| 511 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 512 | int mapper_subtree_async(sd_bus *conn, sd_event *loop, char *namespace, |
| 513 | char *interface, void (*callback)(int, void *), |
| 514 | void *userdata, mapper_async_subtree **t, int op) |
Adriana Kobylak | 2a8bfc9 | 2017-05-11 09:16:02 -0500 | [diff] [blame] | 515 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 516 | int r = 0; |
| 517 | mapper_async_subtree *subtree = NULL; |
Adriana Kobylak | 78edbb6 | 2017-05-04 15:45:19 -0500 | [diff] [blame] | 518 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 519 | subtree = malloc(sizeof(*subtree)); |
| 520 | if (!subtree) |
| 521 | return -ENOMEM; |
Adriana Kobylak | 78edbb6 | 2017-05-04 15:45:19 -0500 | [diff] [blame] | 522 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 523 | memset(subtree, 0, sizeof(*subtree)); |
| 524 | subtree->conn = conn; |
| 525 | subtree->loop = loop; |
| 526 | subtree->namespace = namespace; |
| 527 | subtree->interface = interface; |
| 528 | subtree->callback = callback; |
| 529 | subtree->userdata = userdata; |
| 530 | subtree->op = op; |
Adriana Kobylak | 78edbb6 | 2017-05-04 15:45:19 -0500 | [diff] [blame] | 531 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 532 | if (subtree->op == MAPPER_OP_REMOVE) |
| 533 | { |
| 534 | r = sd_bus_add_match(conn, &subtree->slot, interfaces_removed_match, |
| 535 | async_subtree_match_callback, subtree); |
| 536 | if (r < 0) |
| 537 | { |
| 538 | fprintf(stderr, "Error adding match rule: %s\n", strerror(-r)); |
| 539 | goto unref_slot; |
| 540 | } |
| 541 | } |
| 542 | else |
| 543 | { |
| 544 | /* Operation not supported */ |
| 545 | r = -EINVAL; |
| 546 | goto free_subtree; |
| 547 | } |
Adriana Kobylak | 78edbb6 | 2017-05-04 15:45:19 -0500 | [diff] [blame] | 548 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 549 | r = async_subtree_getpaths(subtree); |
| 550 | if (r < 0) |
| 551 | { |
| 552 | fprintf(stderr, "Error calling method: %s\n", strerror(-r)); |
| 553 | goto unref_slot; |
| 554 | } |
Adriana Kobylak | 025d795 | 2017-05-08 13:30:45 -0500 | [diff] [blame] | 555 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 556 | *t = subtree; |
Adriana Kobylak | 78edbb6 | 2017-05-04 15:45:19 -0500 | [diff] [blame] | 557 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 558 | return 0; |
Adriana Kobylak | 78edbb6 | 2017-05-04 15:45:19 -0500 | [diff] [blame] | 559 | |
| 560 | unref_slot: |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 561 | sd_bus_slot_unref(subtree->slot); |
Adriana Kobylak | 78edbb6 | 2017-05-04 15:45:19 -0500 | [diff] [blame] | 562 | free_subtree: |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 563 | free(subtree); |
Adriana Kobylak | 2a8bfc9 | 2017-05-11 09:16:02 -0500 | [diff] [blame] | 564 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 565 | return r; |
Adriana Kobylak | 2a8bfc9 | 2017-05-11 09:16:02 -0500 | [diff] [blame] | 566 | } |
| 567 | |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 568 | int mapper_get_object(sd_bus *conn, const char *obj, sd_bus_message **reply) |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 569 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 570 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 571 | sd_bus_message *request = NULL; |
| 572 | int r, retry = 0; |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 573 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 574 | r = sd_bus_message_new_method_call(conn, &request, MAPPER_BUSNAME, |
| 575 | MAPPER_PATH, MAPPER_INTERFACE, |
| 576 | "GetObject"); |
| 577 | if (r < 0) |
| 578 | goto exit; |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 579 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 580 | r = sd_bus_message_append(request, "s", obj); |
| 581 | if (r < 0) |
| 582 | goto exit; |
| 583 | r = sd_bus_message_append(request, "as", 0, NULL); |
| 584 | if (r < 0) |
| 585 | goto exit; |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 586 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 587 | while (retry < mapper_busy_retries) |
| 588 | { |
| 589 | sd_bus_error_free(&error); |
| 590 | r = sd_bus_call(conn, request, 0, &error, reply); |
| 591 | if (r < 0 && sd_bus_error_get_errno(&error) == EBUSY) |
| 592 | { |
| 593 | ++retry; |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 594 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 595 | if (retry != mapper_busy_retries) |
| 596 | usleep(mapper_busy_delay_interval_usec); |
| 597 | continue; |
| 598 | } |
| 599 | break; |
| 600 | } |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 601 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 602 | if (r < 0) |
| 603 | goto exit; |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 604 | |
| 605 | exit: |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 606 | sd_bus_error_free(&error); |
| 607 | sd_bus_message_unref(request); |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 608 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 609 | return r; |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | int mapper_get_service(sd_bus *conn, const char *obj, char **service) |
| 613 | { |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 614 | sd_bus_message *reply = NULL; |
| 615 | const char *tmp; |
| 616 | int r; |
Brad Bishop | 3d46879 | 2016-09-20 15:39:38 -0400 | [diff] [blame] | 617 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 618 | r = mapper_get_object(conn, obj, &reply); |
| 619 | if (r < 0) |
| 620 | goto exit; |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 621 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 622 | r = sd_bus_message_enter_container(reply, 0, NULL); |
| 623 | if (r < 0) |
| 624 | goto exit; |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 625 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 626 | r = sd_bus_message_enter_container(reply, 0, NULL); |
| 627 | if (r < 0) |
| 628 | goto exit; |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 629 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 630 | r = sd_bus_message_read(reply, "s", &tmp); |
| 631 | if (r < 0) |
| 632 | goto exit; |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 633 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 634 | *service = strdup(tmp); |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 635 | |
| 636 | exit: |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 637 | sd_bus_message_unref(reply); |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 638 | |
Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 639 | return r; |
Brad Bishop | 62ece2b | 2016-07-25 09:00:51 -0400 | [diff] [blame] | 640 | } |