4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.3 2008/02/15 03:32:07 james
14 * *** empty log message ***
16 * Revision 1.2 2008/02/14 16:21:17 james
17 * *** empty log message ***
19 * Revision 1.1 2008/02/14 12:51:14 james
20 * *** empty log message ***
22 * Revision 1.4 2008/02/14 10:39:14 james
23 * *** empty log message ***
25 * Revision 1.3 2008/02/13 09:12:21 james
26 * *** empty log message ***
28 * Revision 1.2 2008/02/12 22:36:46 james
29 * *** empty log message ***
31 * Revision 1.1 2008/02/09 15:47:28 james
32 * *** empty log message ***
34 * Revision 1.2 2008/02/07 11:11:14 staffcvs
35 * *** empty log message ***
37 * Revision 1.1 2008/02/07 01:02:52 james
38 * *** empty log message ***
40 * Revision 1.3 2008/02/06 17:53:28 james
41 * *** empty log message ***
43 * Revision 1.2 2008/02/04 02:05:06 james
44 * *** empty log message ***
46 * Revision 1.1 2008/02/04 01:32:39 james
47 * *** empty log message ***
63 char *lockfiles[NLOCKFILES];
64 char *potential_lockfiles[NLOCKFILES];
65 struct timeval last_content_check;
81 static int uuid = -1, ugid;
86 if (pw = getpwnam ("uucp"))
96 return fchown (fd, uuid, ugid);
100 make_lockfile (char *name)
102 char buf[1024], tmpfn[1024];
107 strcpy (tmpfn, name);
109 ptr = rindex (tmpfn, '/');
115 ptr += sprintf (ptr, "LTMP.%d", getpid ());
118 i = sprintf (buf, "%10d\n", getpid ());
120 fd = open (tmpfn, O_WRONLY | O_CREAT | O_TRUNC, 0444);
138 if (link (tmpfn, name) < 0)
151 construct_lock_file_name_by_name (char *ptr)
154 printf ("lock by file %s\n", ptr);
159 construct_lock_file_name_by_device (dev_t dev)
162 printf ("lock by dev %x\n", dev);
168 construct_possible_lock_files (char *device)
173 struct stat dev_stat, ent_stat;
177 if (stat (device, &dev_stat))
179 if (!S_ISCHR (dev_stat.st_mode))
182 construct_lock_file_name_by_device (dev_stat.st_rdev);
184 construct_lock_file_name_by_name (device);
186 for (d = opendir (DEV); (de = readdir (d));)
189 strcat (buf, de->d_name);
191 if (stat (buf, &ent_stat))
193 if (!S_ISCHR (ent_stat.st_mode))
195 if (ent_stat.st_rdev != dev_stat.st_rdev)
198 construct_lock_file_name_by_name (buf);
207 serial_check_lock (Serial * t)
213 serial_close (TTY * _t)
215 Serial *t = (Serial *) _t;
227 serial_read (TTY * _t, void *buf, int len)
229 Serial *t = (Serial *) _t;
232 serial_check_lock (t);
239 red = wrap_read (t->fd, buf, len);
257 ptty_write (TTY * _t, void *buf, int len)
260 Serial *t = (Serial *) _t;
262 serial_check_lock (t);
269 writ = wrap_write (t->fd, buf, len);
286 serial_open (char *path)
291 struct winsize winsize = { 0 };
292 struct termios termios;
296 default_termios (&termios);
298 fd = open (path, O_RDWR);
300 set_nonblocking (fd);
302 t = (Serial *) malloc (sizeof (Serial));
304 strncpy (t->name, path, sizeof (t->name));
305 t->name[sizeof (t->name) - 1] = 0;
307 t->recv = serial_read;
308 //t->xmit = serial_write;
309 t->close = serial_close;
313 t->size.x = VT102_COLS;
314 t->size.y = VT102_ROWS;