diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2019-04-08 09:59:15 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2019-04-08 09:59:15 +0200 |
commit | 6ae8ad4acf9252df2b7b043c78af401973c9bd6f (patch) | |
tree | c15f5ad563d66e300e9bebe268f413457678b652 /logind.c | |
parent | b896696f8a2cbc7960cd5da59c917bb03d4e73af (diff) | |
download | drminfo-6ae8ad4acf9252df2b7b043c78af401973c9bd6f.tar.gz |
add device_open helper
Diffstat (limited to 'logind.c')
-rw-r--r-- | logind.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -200,9 +200,34 @@ void logind_fini(void) int logind_open(const char *path) { + const char *session_id, *seat; + + seat = getenv("XDG_SEAT"); + session_id = getenv("XDG_SESSION_ID"); + if (!seat || !session_id) + return -1; + fprintf(stderr, "%s(%s): compiled without logind support.\n", __func__, path); return -1; } #endif + +/* ---------------------------------------------------------------------- */ + +int device_open(const char *device) +{ + int saved_errno, fd; + + fd = open(device, O_RDWR | O_CLOEXEC); + if (fd < 0) { + saved_errno = errno; + fd = logind_open(device); + if (fd < 0) { + fprintf(stderr,"open %s: %s\n", device, strerror(saved_errno)); + exit(1); + } + } + return fd; +} |