Skip to content

Commit 31632ab

Browse files
committed
Merge pull request #208 from mtomaschewski/testing
do not fail on device create/delete loops
2 parents a63c90c + ecd2a2e commit 31632ab

File tree

14 files changed

+154
-60
lines changed

14 files changed

+154
-60
lines changed

client/ifcheck.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,17 @@ ni_do_ifcheck(int argc, char **argv)
325325
}
326326

327327
if (!ni_fsm_create_client(fsm)) {
328+
/* Severe error we always explicitly return */
329+
status = NI_WICKED_RC_ERROR;
330+
goto cleanup;
331+
}
332+
333+
if (!ni_fsm_refresh_state(fsm)) {
334+
/* Severe error we always explicitly return */
328335
status = NI_WICKED_RC_ERROR;
329336
goto cleanup;
330337
}
331338

332-
ni_fsm_refresh_state(fsm);
333339
status = NI_WICKED_ST_OK;
334340

335341
if (0 == checks.count)

client/ifdown.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,15 @@ ni_do_ifdown(int argc, char **argv)
151151
ifmarker.target_range.min = NI_FSM_STATE_NONE;
152152
ifmarker.target_range.max = max_state;
153153

154-
if (!ni_fsm_create_client(fsm))
154+
if (!ni_fsm_create_client(fsm)) {
155155
/* Severe error we always explicitly return */
156156
return NI_WICKED_RC_ERROR;
157+
}
157158

158-
ni_fsm_refresh_state(fsm);
159+
if (!ni_fsm_refresh_state(fsm)) {
160+
/* Severe error we always explicitly return */
161+
return NI_WICKED_RC_ERROR;
162+
}
159163

160164
/* Get workers that match given criteria */
161165
nmarked = 0;

client/ifreload.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ ni_do_ifreload(int argc, char **argv)
147147
goto cleanup;
148148
}
149149

150-
ni_fsm_refresh_state(fsm);
150+
if (!ni_fsm_refresh_state(fsm)) {
151+
/* Severe error we always explicitly return */
152+
status = NI_WICKED_RC_ERROR;
153+
goto cleanup;
154+
}
151155

152156
if (opt_ifconfig.count == 0) {
153157
const ni_string_array_t *sources = ni_config_sources("ifconfig");

client/ifstatus.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ if_printf(const char *dev, const char *tag, const char *fmt, ...)
215215
va_list ap;
216216

217217
if (!ni_string_empty(dev)) {
218-
printf("%-15s", dev);
218+
printf("%-16s", dev);
219219
} else {
220220
printf("%-6s", "");
221221
}
222222
if (!ni_string_empty(tag)) {
223-
printf("%-8s ", tag);
223+
printf("%-9s ", tag);
224224
}
225225
if (!ni_string_empty(fmt)) {
226226
va_start(ap, fmt);
@@ -563,14 +563,16 @@ ni_do_ifstatus(int argc, char **argv)
563563
}
564564

565565
if (!ni_fsm_create_client(fsm)) {
566+
/* Severe error we always explicitly return */
566567
status = NI_WICKED_ST_ERROR;
567568
goto cleanup;
568569
}
569570

570-
/* TODO: we connect to wickedd here. currently, it
571-
* may exit(1), that is with NI_WICKED_ST_ERROR...
572-
*/
573-
ni_fsm_refresh_state(fsm);
571+
if (!ni_fsm_refresh_state(fsm)) {
572+
/* Severe error we always explicitly return */
573+
status = NI_WICKED_ST_ERROR;
574+
goto cleanup;
575+
}
574576

575577
if (check_config && opt_ifconfig.count == 0) {
576578
const ni_string_array_t *sources = ni_config_sources("ifconfig");

client/ifup.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ ni_do_ifup(int argc, char **argv)
206206
goto cleanup;
207207
}
208208

209-
ni_fsm_refresh_state(fsm);
209+
if (!ni_fsm_refresh_state(fsm)) {
210+
/* Severe error we always explicitly return */
211+
status = NI_WICKED_RC_ERROR;
212+
goto cleanup;
213+
}
210214

211215
if (opt_ifconfig.count == 0) {
212216
const ni_string_array_t *sources = ni_config_sources("ifconfig");

include/wicked/fsm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ extern xml_location_t * ni_fsm_policy_location(const ni_fsm_policy_t *);
251251
extern ni_bool_t ni_fsm_policies_changed_since(const ni_fsm_t *, unsigned int *tstamp);
252252

253253
extern ni_dbus_client_t * ni_fsm_create_client(ni_fsm_t *);
254-
extern void ni_fsm_refresh_state(ni_fsm_t *);
254+
extern ni_bool_t ni_fsm_refresh_state(ni_fsm_t *);
255255
extern unsigned int ni_fsm_schedule(ni_fsm_t *);
256256
extern ni_bool_t ni_fsm_do(ni_fsm_t *fsm, long *timeout_p);
257257
extern void ni_fsm_mainloop(ni_fsm_t *);

nanny/device.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,6 @@ ni_nanny_get_device(ni_nanny_t *mgr, ni_ifworker_t *w)
429429
{
430430
ni_managed_device_t *mdev;
431431

432-
ni_assert(w);
433-
434432
for (mdev = mgr->device_list; mdev; mdev = mdev->next) {
435433
if (mdev->worker == w)
436434
return mdev;

nanny/main.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,10 @@ ni_nanny_netif_state_change_signal_receive(ni_dbus_connection_t *conn, ni_dbus_m
300300
// A new device was added. Could be a virtual device like
301301
// a VLAN or vif, or a hotplug device
302302
// Create a worker and a managed_netif for this device.
303-
w = ni_fsm_recv_new_netif_path(mgr->fsm, object_path);
304-
ni_nanny_register_device(mgr, w);
305-
ni_nanny_schedule_recheck(mgr, w);
303+
if ((w = ni_fsm_recv_new_netif_path(mgr->fsm, object_path))) {
304+
ni_nanny_register_device(mgr, w);
305+
ni_nanny_schedule_recheck(mgr, w);
306+
}
306307
return;
307308
}
308309

@@ -311,19 +312,22 @@ ni_nanny_netif_state_change_signal_receive(ni_dbus_connection_t *conn, ni_dbus_m
311312
signal_name, object_path);
312313
return;
313314
}
314-
315-
ni_assert(w->type == NI_IFWORKER_TYPE_NETDEV);
316-
ni_assert(w->device);
315+
if (w->type != NI_IFWORKER_TYPE_NETDEV || w->device == NULL) {
316+
ni_error("%s: received signal \"%s\" from \"%s\" (not a managed network device)",
317+
w->name, signal_name, object_path);
318+
return;
319+
}
317320

318321
if (event == NI_EVENT_DEVICE_DELETE) {
319-
ni_debug_nanny("%s: received signal %s from %s", w->name, signal_name, object_path);
322+
ni_debug_nanny("%s: received signal \"%s\" from \"%s\"",
323+
w->name, signal_name, object_path);
320324
// delete the worker and the managed netif
321325
ni_nanny_unregister_device(mgr, w);
322326
return;
323327
}
324328

325329
if ((mdev = ni_nanny_get_device(mgr, w)) == NULL) {
326-
ni_debug_nanny("%s: received signal %s from %s (not a managed device)",
330+
ni_debug_nanny("%s: received signal \"%s\" from \"%s\" (not a managed device)",
327331
w->name, signal_name, object_path);
328332
return;
329333
}
@@ -388,9 +392,10 @@ ni_nanny_modem_state_change_signal_receive(ni_dbus_connection_t *conn, ni_dbus_m
388392

389393
// We receive a deviceCreate signal when a modem was plugged in
390394
if (event == NI_EVENT_DEVICE_CREATE) {
391-
w = ni_fsm_recv_new_modem_path(mgr->fsm, object_path);
392-
ni_nanny_register_device(mgr, w);
393-
ni_nanny_schedule_recheck(mgr, w);
395+
if ((w = ni_fsm_recv_new_modem_path(mgr->fsm, object_path))) {
396+
ni_nanny_register_device(mgr, w);
397+
ni_nanny_schedule_recheck(mgr, w);
398+
}
394399
return;
395400
}
396401

@@ -400,10 +405,13 @@ ni_nanny_modem_state_change_signal_receive(ni_dbus_connection_t *conn, ni_dbus_m
400405
return;
401406
}
402407

403-
ni_debug_nanny("%s: received signal %s from %s", w->name, signal_name, object_path);
404-
ni_assert(w->type == NI_IFWORKER_TYPE_MODEM);
405-
ni_assert(w->modem);
408+
if (w->type != NI_IFWORKER_TYPE_MODEM || w->modem == NULL) {
409+
ni_error("%s: received signal \"%s\" from \"%s\" (not a managed modem device)",
410+
w->name, signal_name, object_path);
411+
return;
412+
}
406413

414+
ni_debug_nanny("%s: received signal %s from %s", w->name, signal_name, object_path);
407415
if (event == NI_EVENT_DEVICE_DELETE) {
408416
// delete the worker and the managed modem
409417
ni_nanny_unregister_device(mgr, w);

server/main.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,14 @@ handle_interface_event(ni_netdev_t *dev, ni_event_t event)
347347
/* A new netif was discovered; create a dbus server object
348348
* enacpsulating it. */
349349
object = ni_objectmodel_register_netif(dbus_server, dev, NULL);
350-
} else
351-
if (!(object = ni_objectmodel_get_netif_object(dbus_server, dev))) {
352-
ni_error("cannot send %s event for model \"%s\" - no dbus device",
353-
ni_event_type_to_name(event), dev->name);
350+
} else {
351+
object = ni_objectmodel_get_netif_object(dbus_server, dev);
352+
}
353+
if (!object) {
354+
/* usually a "bad event", e.g. when the underlying netdev
355+
* does not exists any more, but events still arrive ... */
356+
ni_debug_events("cannot handle %s event for model \"%s\" - no dbus object",
357+
ni_event_type_to_name(event), dev->name);
354358
return;
355359
}
356360

src/dbus-object.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ ni_dbus_object_get_service(const ni_dbus_object_t *object, const char *interface
301301
const ni_dbus_service_t *svc;
302302
unsigned int i;
303303

304-
if (object->interfaces == NULL)
304+
if (object == NULL || object->interfaces == NULL)
305305
return NULL;
306306

307307
for (i = 0; (svc = object->interfaces[i]) != NULL; ++i) {
@@ -364,7 +364,7 @@ ni_dbus_object_get_all_services_for_method(const ni_dbus_object_t *object, const
364364
const ni_dbus_service_t *svc;
365365
unsigned int i, found = 0;
366366

367-
if (object->interfaces == NULL || method == NULL)
367+
if (object == NULL || object->interfaces == NULL || method == NULL)
368368
return 0;
369369

370370
for (i = 0; (svc = object->interfaces[i]) != NULL; ++i) {
@@ -383,7 +383,7 @@ ni_dbus_object_get_service_for_signal(const ni_dbus_object_t *object, const char
383383
const ni_dbus_service_t *svc, *best = NULL;
384384
unsigned int i;
385385

386-
if (object->interfaces == NULL)
386+
if (object == NULL || object->interfaces == NULL)
387387
return NULL;
388388

389389
for (i = 0; (svc = object->interfaces[i]) != NULL; ++i) {
@@ -404,7 +404,7 @@ ni_dbus_object_get_service_for_property(const ni_dbus_object_t *object, const ch
404404
const ni_dbus_service_t *svc;
405405
unsigned int i;
406406

407-
if (object->interfaces == NULL)
407+
if (object == NULL || object->interfaces == NULL)
408408
return NULL;
409409

410410
for (i = 0; (svc = object->interfaces[i]) != NULL; ++i) {

0 commit comments

Comments
 (0)