4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.2 2008/02/14 16:21:17 james
14 * *** empty log message ***
16 * Revision 1.1 2008/02/14 12:51:14 james
17 * *** empty log message ***
19 * Revision 1.4 2008/02/14 10:39:14 james
20 * *** empty log message ***
22 * Revision 1.3 2008/02/13 09:12:21 james
23 * *** empty log message ***
25 * Revision 1.2 2008/02/12 22:36:46 james
26 * *** empty log message ***
28 * Revision 1.1 2008/02/09 15:47:28 james
29 * *** empty log message ***
31 * Revision 1.2 2008/02/07 11:11:14 staffcvs
32 * *** empty log message ***
34 * Revision 1.1 2008/02/07 01:02:52 james
35 * *** empty log message ***
37 * Revision 1.3 2008/02/06 17:53:28 james
38 * *** empty log message ***
40 * Revision 1.2 2008/02/04 02:05:06 james
41 * *** empty log message ***
43 * Revision 1.1 2008/02/04 01:32:39 james
44 * *** empty log message ***
59 char *lockfiles[NLOCKFILES];
60 char *potential_lockfiles[NLOCKFILES];
61 struct timeval last_content_check;
77 static int uuid = -1, ugid;
81 if (pw = getpwnam("uucp")) {
88 return fchown(fd, uuid, ugid);
91 int make_lockfile(char *name)
93 char buf[1024],tmpfn[1024];
100 ptr=rindex(tmpfn,'/');
105 ptr+=sprintf(ptr,"LTMP.%d",getpid());
108 i=sprintf(buf,"%10d\n",getpid());
110 fd=open(tmpfn,O_WRONLY|O_CREAT|O_TRUNC,0444);
118 if( chown_uucp(fd)) {
126 if (link(tmpfn,name)<0) {
137 void construct_lock_file_name_by_name(char *ptr)
140 printf("lock by file %s\n",ptr);
143 void construct_lock_file_name_by_device(dev_t dev)
146 printf("lock by dev %x\n",dev);
151 int construct_possible_lock_files(char *device)
156 struct stat dev_stat,ent_stat;
160 if (stat(device,&dev_stat)) return -1;
161 if (!S_ISCHR(dev_stat.st_mode)) return -1;
163 construct_lock_file_name_by_device(dev_stat.st_rdev);
165 construct_lock_file_name_by_name(device);
167 for (d=opendir(DEV);(de=readdir(d));)
170 strcat(buf,de->d_name);
172 if (stat(buf,&ent_stat)) continue;
173 if (!S_ISCHR(ent_stat.st_mode)) continue;
174 if (ent_stat.st_rdev!=dev_stat.st_rdev) continue;
176 construct_lock_file_name_by_name(buf);
185 serial_check_lock(Serial *t)
191 serial_close (TTY * _t)
193 Serial *t = (Serial *) _t;
205 serial_read (TTY * _t, void *buf, int len)
207 Serial *t = (Serial *) _t;
210 serial_check_lock(t);
211 if (t->blocked) return 0;
216 red = wrap_read (t->fd, buf, len);
234 ptty_write (TTY * _t, void *buf, int len)
237 Serial *t = (Serial *) _t;
239 serial_check_lock(t);
240 if (t->blocked) return 0;
245 writ = wrap_write (t->fd, buf, len);
262 serial_open (char *path)
267 struct winsize winsize = { 0 };
268 struct termios termios;
272 default_termios (&termios);
274 fd=open(path,O_RDWR);
276 set_nonblocking (fd);
278 t = (Serial *) malloc (sizeof (Serial));
280 strncpy (t->name, path, sizeof (t->name));
281 t->name[sizeof (t->name) - 1] = 0;
283 t->recv = serial_read;
284 //t->xmit = serial_write;
285 t->close = serial_close;
289 t->size.x = VT102_COLS;
290 t->size.y = VT102_ROWS;