MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / ttydev_open

Function ttydev_open

components/lwp/terminal/freebsd/tty.c:258–371  ·  view source on GitHub ↗

* Operations that are exposed through the character device in /dev. */

Source from the content-addressed store, hash-verified

256 * Operations that are exposed through the character device in /dev.
257 */
258static int ttydev_open(struct lwp_tty *tp, int oflags, int devtype,
259 struct rt_thread *td)
260{
261 rt_device_t dev = &tp->parent;
262 int error;
263
264 error = 0;
265 tty_lock(tp);
266 if (tty_gone(tp))
267 {
268 /* Device is already gone. */
269 tty_unlock(tp);
270 return -ENXIO;
271 }
272
273 /*
274 * Block when other processes are currently opening or closing
275 * the TTY.
276 */
277 while (tp->t_flags & TF_OPENCLOSE)
278 {
279 error = tty_wait(tp, &tp->t_dcdwait);
280 if (error != 0)
281 {
282 tty_unlock(tp);
283 return error;
284 }
285 }
286 tp->t_flags |= TF_OPENCLOSE;
287
288 /*
289 * Make sure the "tty" and "cua" device cannot be opened at the
290 * same time. The console is a "tty" device.
291 */
292 if (TTY_CALLOUT(tp, dev))
293 {
294 if (tp->t_flags & (TF_OPENED_CONS | TF_OPENED_IN))
295 {
296 error = EBUSY;
297 goto done;
298 }
299 }
300 else
301 {
302 if (tp->t_flags & TF_OPENED_OUT)
303 {
304 error = EBUSY;
305 goto done;
306 }
307 }
308
309 if (tp->t_flags & TF_EXCLUDE && priv_check(td, PRIV_TTY_EXCLUSIVE))
310 {
311 error = EBUSY;
312 goto done;
313 }
314
315 if (!tty_opened(tp))

Callers

nothing calls this directly

Calls 8

tty_waitFunction · 0.85
priv_checkFunction · 0.85
ttydevsw_paramFunction · 0.85
ttydevsw_modemFunction · 0.85
ttydevsw_openFunction · 0.85
ttydisc_openFunction · 0.85
tty_watermarksFunction · 0.85
ttydev_leaveFunction · 0.85

Tested by

no test coverage detected