diff options
author | Seunghun Lee <shiin.lee@samsung.com> | 2014-12-09 09:36:42 -0500 |
---|---|---|
committer | Chris Michael <cp.michael@samsung.com> | 2014-12-09 09:36:42 -0500 |
commit | b10ab1a86f35ab793ba6efb49224d9ecdd1b7dbd (patch) | |
tree | a29763a81807d24d4a994dfff9b7098a02e22e45 /src/lib/ecore_drm/ecore_drm_launcher.c | |
parent | 05006e64634359613e093776af19e7b9ca0caec1 (diff) |
ecore-drm: added drm launcher that is allow to determine whether to launch with logind or root privilege.
Summary:
- allow to launch drm backend without systemd-logind with root privilege.
- allow to open drm device node via logind, not directly open it, in case exist systemd-logind.
- fixes issue that couldn't switch session, because ecore-drm couldn't drop master to drm device with no permission. (allow to switch session appropriate.)
Reviewers: gwanglim, devilhorns
Subscribers: torori, cedric
Differential Revision: https://phab.enlightenment.org/D1704
Diffstat (limited to 'src/lib/ecore_drm/ecore_drm_launcher.c')
-rw-r--r-- | src/lib/ecore_drm/ecore_drm_launcher.c | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/src/lib/ecore_drm/ecore_drm_launcher.c b/src/lib/ecore_drm/ecore_drm_launcher.c new file mode 100644 index 0000000000..e2d64d580b --- /dev/null +++ b/src/lib/ecore_drm/ecore_drm_launcher.c | |||
@@ -0,0 +1,139 @@ | |||
1 | #include "ecore_drm_private.h" | ||
2 | #include "ecore_drm_logind.h" | ||
3 | |||
4 | static Eina_Bool logind = EINA_FALSE; | ||
5 | |||
6 | EAPI Eina_Bool | ||
7 | ecore_drm_launcher_connect(Ecore_Drm_Device *dev) | ||
8 | { | ||
9 | if (!(logind = _ecore_drm_logind_connect(dev))) | ||
10 | { | ||
11 | DBG("Launcher: Not Support loignd\n"); | ||
12 | if (geteuid() == 0) | ||
13 | { | ||
14 | DBG("Launcher: Try to keep going with root privilege\n"); | ||
15 | if (!ecore_drm_tty_open(dev, NULL)) | ||
16 | { | ||
17 | ERR("Launcher: failed to open tty with root privilege\n"); | ||
18 | return EINA_FALSE; | ||
19 | } | ||
20 | } | ||
21 | else | ||
22 | { | ||
23 | ERR("Launcher: Need Root Privilege or logind\n"); | ||
24 | return EINA_FALSE; | ||
25 | } | ||
26 | } | ||
27 | DBG("Launcher: Success Connect\n"); | ||
28 | |||
29 | return EINA_TRUE; | ||
30 | } | ||
31 | |||
32 | EAPI void | ||
33 | ecore_drm_launcher_disconnect(Ecore_Drm_Device *dev) | ||
34 | { | ||
35 | if (logind) | ||
36 | { | ||
37 | logind = EINA_FALSE; | ||
38 | _ecore_drm_logind_disconnect(dev); | ||
39 | } | ||
40 | else | ||
41 | { | ||
42 | ecore_drm_tty_close(dev); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | static int | ||
47 | _device_flags_set(int fd, int flags) | ||
48 | { | ||
49 | int fl; | ||
50 | |||
51 | fl = fcntl(fd, F_GETFL); | ||
52 | if (fl < 0) | ||
53 | return -1; | ||
54 | |||
55 | if (flags & O_NONBLOCK) | ||
56 | fl |= O_NONBLOCK; | ||
57 | |||
58 | if (fcntl(fd, F_SETFL, fl) < 0) | ||
59 | return -1; | ||
60 | |||
61 | fl = fcntl(fd, F_GETFD); | ||
62 | if (fl < 0) | ||
63 | return -1; | ||
64 | |||
65 | if (!(flags & O_CLOEXEC)) | ||
66 | fl &= ~FD_CLOEXEC; | ||
67 | |||
68 | if (fcntl(fd, F_SETFD, fl) < 0) | ||
69 | return -1; | ||
70 | |||
71 | return fd; | ||
72 | } | ||
73 | |||
74 | Eina_Bool | ||
75 | _ecore_drm_launcher_device_open(const char *device, Ecore_Drm_Open_Cb callback, void *data, int flags) | ||
76 | { | ||
77 | int fd = -1; | ||
78 | struct stat s; | ||
79 | |||
80 | if (logind) | ||
81 | { | ||
82 | if (!_ecore_drm_logind_device_open(device, callback, data)) | ||
83 | return EINA_FALSE; | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | fd = open(device, flags | O_CLOEXEC); | ||
88 | if (fd < 0) return EINA_FALSE; | ||
89 | if (fstat(fd, &s) == -1) | ||
90 | { | ||
91 | close(fd); | ||
92 | fd = -1; | ||
93 | return EINA_FALSE; | ||
94 | } | ||
95 | |||
96 | callback(data, fd, EINA_FALSE); | ||
97 | } | ||
98 | |||
99 | return EINA_TRUE; | ||
100 | } | ||
101 | |||
102 | int | ||
103 | _ecore_drm_launcher_device_open_no_pending(const char *device, int flags) | ||
104 | { | ||
105 | int fd = -1; | ||
106 | struct stat s; | ||
107 | |||
108 | if (logind) | ||
109 | { | ||
110 | fd = _ecore_drm_logind_device_open_no_pending(device); | ||
111 | if ((fd = _device_flags_set(fd, flags)) == -1) | ||
112 | { | ||
113 | _ecore_drm_logind_device_close(device); | ||
114 | return -1; | ||
115 | } | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | fd = open(device, flags, flags | O_CLOEXEC); | ||
120 | if (fd < 0) return fd; | ||
121 | if (fstat(fd, &s) == -1) | ||
122 | { | ||
123 | close(fd); | ||
124 | return -1; | ||
125 | } | ||
126 | } | ||
127 | |||
128 | DBG("Device opened %s", device); | ||
129 | return fd; | ||
130 | } | ||
131 | |||
132 | void | ||
133 | _ecore_drm_launcher_device_close(const char *device, int fd) | ||
134 | { | ||
135 | if (logind) | ||
136 | return _ecore_drm_logind_device_close(device); | ||
137 | |||
138 | close(fd); | ||
139 | } | ||