diff options
author | james <> | 2008-02-15 16:48:56 +0000 |
---|---|---|
committer | james <> | 2008-02-15 16:48:56 +0000 |
commit | 6da9efdb2f23555f1e90ef04944017372e6dd01a (patch) | |
tree | 38353b81fd22f5fdb486ca30257b367442416d5a /src/lockfile.c | |
parent | 19f0d6f858f40d948ea9d2f9537adc2f094dbad4 (diff) | |
download | sympathy-6da9efdb2f23555f1e90ef04944017372e6dd01a.tar.gz sympathy-6da9efdb2f23555f1e90ef04944017372e6dd01a.tar.bz2 sympathy-6da9efdb2f23555f1e90ef04944017372e6dd01a.zip |
*** empty log message ***
Diffstat (limited to 'src/lockfile.c')
-rw-r--r-- | src/lockfile.c | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/src/lockfile.c b/src/lockfile.c index 4f94c57..9dd2925 100644 --- a/src/lockfile.c +++ b/src/lockfile.c @@ -10,8 +10,160 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.2 2008/02/15 16:48:56 james + * *** empty log message *** + * * Revision 1.1 2008/02/15 15:09:17 james * *** empty log message *** * */ +#define LOCK_ASCII +#undef LOCK_BINARY + + +Filelist *filelist_new(void) +{ + + + +} + + +static int +chown_uucp (fd) + int fd; +{ + static int uuid = -1, ugid; + struct passwd *pw; + + if (uuid < 0) + { + if (pw = getpwnam ("uucp")) + { + uuid = pw->pw_uid; + ugid = pw->pw_gid; + } + else + { + return -1; + } + } + return fchown (fd, uuid, ugid); +} + +int +lockfile_make +{ + char buf[1024], tmpfn[1024]; + char *ptr; + int fd; + int i; + + strcpy (tmpfn, name); + + ptr = rindex (tmpfn, '/'); + if (!ptr) + return -1; + + ptr++; + + ptr += sprintf (ptr, "LTMP.%d", getpid ()); + *ptr = 0; + + i = sprintf (buf, "%10d\n", getpid ()); + + fd = open (tmpfn, O_WRONLY | O_CREAT | O_TRUNC, 0444); + if (fd < 0) + { + unlink (tmpfn); + return -1; + } + + write (fd, buf, i); + fchmod (fd, 044); + if (chown_uucp (fd)) + { + close (fd); + unlink (tmpfn); + return -1; + } + + close (fd); + + if (link (tmpfn, name) < 0) + { + unlink (tmpfn); + return -1; + } + + unlink (tmpfn); + return 0; +} + + + +void +lockfile_add_name_from_path (File_list *fl,char *ptr) +{ + printf ("lock by file %s\n", ptr); +} + +void +lockfile_add_name_from_dev (File_list *fl,dev_t dev) +{ + printf ("lock by dev %x\n", dev); +} + +void lockfile_check_dir_for_dev(File_list *fl,char *dir,dev_t dev) +{ + char buf[1024]; + struct stat ent_stat; + struct dirent *de; + DIR *d; + + for (d = opendir (DEV); (de = readdir (d));) + { + strcpy (buf, DEV); + strcat (buf, de->d_name); + + if (stat (buf, &ent_stat)) + continue; + if (!S_ISCHR (ent_stat.st_mode)) + continue; + if (ent_stat.st_rdev != dev) + continue; + + lockfile_add_name_from_path (fl,buf); + + } + closedir (d); +} + +File_list * +construct_possible_lock_files (char *device) +{ + struct stat dev_stat; + File_list *ret=NULL; + + + if (stat (device, &dev_stat)) + return ret; + if (!S_ISCHR (dev_stat.st_mode)) + return ret; + + ret=filelist_new(); + + lockfile_add_name_from_dev (ret,dev_stat.st_rdev); + + lockfile_add_name_from_path (ret,device); + + lockfile_check_dir_for_dev(ret,"/dev/",dev_stat.st_rdev); + lockfile_check_dir_for_dev(ret,"/dev/usb/",dev_stat.st_rdev); + lockfile_check_dir_for_dev(ret,"/dev/tts/",dev_stat.st_rdev); + + return ret; +} + + + |