Idle CPU Usage of usbmuxd

Here is the culprit:

struct timespec
{
	time_t tv_sec;
	long int tv_nsec;
};

If usbmuxd is compiled with 64 bit time_t, but ppoll expects it to be 32 bit, the following timespec data is interpreted by ppoll:

// little endianness: timeout is 100 seconds
int32_t tv_sec = 100;
int32_t tv_nsec = 0;
int32_t unused = 0;

// big endianness: timeout is 100 nano-seconds
int32_t tv_sec = 0;
int32_t tv_nsec = 100;
int32_t unused = 0;

I was able to confirm this by defining a timespec32 structure, setting tv_sec = 1 and then casting its pointer to (struct timespec *). This results in timeouts of 1 second as expected. Only big endianness CPUs are affected. That's why I have no issues with WRT3200ACM, while the old TL-WR1043ND is affected.
Before I submit a patch, I need to find why usbmuxd is compiled with 64 bit time_t and change it to match ppoll. This looks like wrong include paths or incorrect macros.

Edit: issue and fix

1 Like