4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.2 2008/02/15 16:48:56 james
14 * *** empty log message ***
16 * Revision 1.1 2008/02/15 15:09:17 james
17 * *** empty log message ***
25 Filelist *filelist_new(void)
37 static int uuid = -1, ugid;
42 if (pw = getpwnam ("uucp"))
52 return fchown (fd, uuid, ugid);
58 char buf[1024], tmpfn[1024];
65 ptr = rindex (tmpfn, '/');
71 ptr += sprintf (ptr, "LTMP.%d", getpid ());
74 i = sprintf (buf, "%10d\n", getpid ());
76 fd = open (tmpfn, O_WRONLY | O_CREAT | O_TRUNC, 0444);
94 if (link (tmpfn, name) < 0)
107 lockfile_add_name_from_path (File_list *fl,char *ptr)
109 printf ("lock by file %s\n", ptr);
113 lockfile_add_name_from_dev (File_list *fl,dev_t dev)
115 printf ("lock by dev %x\n", dev);
118 void lockfile_check_dir_for_dev(File_list *fl,char *dir,dev_t dev)
121 struct stat ent_stat;
125 for (d = opendir (DEV); (de = readdir (d));)
128 strcat (buf, de->d_name);
130 if (stat (buf, &ent_stat))
132 if (!S_ISCHR (ent_stat.st_mode))
134 if (ent_stat.st_rdev != dev)
137 lockfile_add_name_from_path (fl,buf);
144 construct_possible_lock_files (char *device)
146 struct stat dev_stat;
150 if (stat (device, &dev_stat))
152 if (!S_ISCHR (dev_stat.st_mode))
157 lockfile_add_name_from_dev (ret,dev_stat.st_rdev);
159 lockfile_add_name_from_path (ret,device);
161 lockfile_check_dir_for_dev(ret,"/dev/",dev_stat.st_rdev);
162 lockfile_check_dir_for_dev(ret,"/dev/usb/",dev_stat.st_rdev);
163 lockfile_check_dir_for_dev(ret,"/dev/tts/",dev_stat.st_rdev);