3 part mechanical joint following 1 bone? I am making a 3 part mechanical joint, with the different axis of rotation being in 3 different places. This is fairly easy to make a basic rig for:

The problem is that i'd like to control this with a single bone. In this setup, each of the deform bones is using copy rotation to copy the corresponding local axis of the big control bone. It works if I'm only rotating one axis at a time, but once I already have rotation on one, it stops working correctly as the axis become desynched.

What is the proper way to make this work?
I have seen some IK setups for similar joints. I have tried that, but they don't seem to work with this join order. I have the order Z, Y, X. With an IK setup, I can't control the Y roll. If I had the order Z, X, Y, then i'd be able to by putting a copy rotation or something on the final bone. But you can't influence the rotation of a bone in the middle of an IK chain without problems.
UPDATE:
Some answers have used 1 less joint, but the 3rd is necessary. The cylinder was a stand-in for a 2 part joint. The cylinder can't be allowed to rotate on X. Here's a picture showing what the desired joint is like.

File:
Dissolve the middle bone (you just need two bones for your rig). the first bone's constraint wouldn't be changed. for the second bone set world space to world space.

if you want the hinge to be oriented as you wish do above works and add another bone called hinge and make it child of your z bone. assign a locked track constraint to it and set either tail of ctrl or last deforming tail as the target and also set y as the locked axis and -z as the following axis. the result is like below.