1 /*****************************************************************************\
3 * | || | ___ | |_ _ __ | | _ _ __ _ |_ ) *
4 * | __ |/ _ \| _|| '_ \| || || |/ _` | / / *
5 * |_||_|\___/ \__|| .__/|_| \_,_|\__, |/___| *
7 \*****************************************************************************/
13 #include <sys/types.h>
15 #include "mem_utils.h"
17 #include "childlist.h"
19 struct hotplug2_child_t
*add_child(struct hotplug2_child_t
*child
, pid_t pid
, event_seqnum_t seqnum
) {
23 child
= xmalloc(sizeof(struct hotplug2_child_t
));
26 for (; child
->next
; child
= child
->next
);
28 child
->next
= xmalloc(sizeof(struct hotplug2_child_t
));
33 child
->seqnum
= seqnum
;
41 struct hotplug2_child_t
*remove_child_by_pid(struct hotplug2_child_t
*child
, pid_t pid
, event_seqnum_t
*largest_seqnum
, int *child_c
) {
42 struct hotplug2_child_t
*tmp_child
;
45 ERROR("remove_child_by_pid", "Invalid child list passed (NULL).");
51 for (; child
->prev
&& child
->pid
!= pid
; child
= child
->prev
);
53 if (child
->pid
!= pid
) {
57 if (child
->prev
!= NULL
)
58 ((struct hotplug2_child_t
*)(child
->prev
))->next
= child
->next
;
60 if (child
->next
!= NULL
)
61 ((struct hotplug2_child_t
*)(child
->next
))->prev
= child
->prev
;
63 if (largest_seqnum
!= NULL
)
64 if (child
->seqnum
> *largest_seqnum
)
65 *largest_seqnum
= child
->seqnum
;
70 if (child
== tmp_child
) {
71 if (child
->next
!= NULL
)
72 tmp_child
= child
->next
;
73 else if (child
->prev
!= NULL
)
74 tmp_child
= child
->prev
;
79 /* We always want the rightmost */
80 if (tmp_child
!= NULL
)
81 for (; tmp_child
->next
; tmp_child
= tmp_child
->next
);