How to align Z axis of two actors?

Hello,

I have an actor with two sockets defined. On each of these sockets there are two other actors. Each of these socketed actors have their z axis (Up direction) pointing in a direction of my interest, relative to the parent actor.

What I want to do is to align two parent actors, by the actor in the sockets I click, facing each Z axis to the opposite.

I have started implementing this calculating the cross product of the Up direction of each socketed actor, to use it as a axis rotator, and then calculating the angle between them, but it seems that I have to take into consideration many cases (cross product being a 0 vector, angle sign, etc).

Is there a more direct way to do this calculations?