For the GnomeKeyring backend I would rather check if "DBUS_SESSION_BUS_ADDRESS" is set, which means a session bus is running. Because if DISPLAY is set and DBUS_SESSION_BUS_ADDRESS is not gnomekeyring will fail. And some value in DBUS_SESSION_BUS_ADDRESS implies a non empty DISPLAY.
For the GnomeKeyring backend I would rather check if "DBUS_SESSION_ BUS_ADDRESS" is set, which means a session bus is running. Because if DISPLAY is set and DBUS_SESSION_ BUS_ADDRESS is not gnomekeyring will fail. And some value in DBUS_SESSION_ BUS_ADDRESS implies a non empty DISPLAY.