diff -ur popa3d-0.4/mailbox.c popa3d-0.4.new/mailbox.c --- popa3d-0.4/mailbox.c Thu Mar 25 05:25:55 1999 +++ popa3d-0.4.new/mailbox.c Tue May 16 23:33:56 2000 @@ -8,8 +8,8 @@ #include #include #include -#include #include +#include #include #include @@ -26,6 +26,8 @@ static struct db_message *cmp; +int change_lock(int fd, int what); + /* * If a message has changed since the database was filled in, then we * consider the database stale. This is called for every message when @@ -301,14 +303,14 @@ if (mailbox_fd < 0) return errno != ENOENT; - if (flock_loop(mailbox_fd)) return 1; + if (change_lock(mailbox_fd, F_WRLCK)) return 1; result = mailbox_parse(1); if (!result && time(NULL) == mailbox_mtime) if (sleep_select(1, 0)) result = 1; - if (flock(mailbox_fd, LOCK_UN)) return 1; + if (change_lock(mailbox_fd, F_UNLCK)) return 1; return result; } @@ -321,14 +323,14 @@ if (fstat(mailbox_fd, &stat)) return 1; if (mailbox_mtime == stat.st_mtime) return 0; - if (flock_loop(mailbox_fd)) return 1; + if (change_lock(mailbox_fd, F_WRLCK)) return 1; result = mailbox_parse(0); if (!result && time(NULL) == mailbox_mtime) if (sleep_select(1, 0)) result = 1; - if (flock(mailbox_fd, LOCK_UN)) return 1; + if (change_lock(mailbox_fd, F_UNLCK)) return 1; return result; } @@ -421,12 +423,12 @@ if (mailbox_fd < 0 || !(db.flags & DB_DIRTY)) return 0; - if (flock_loop(mailbox_fd)) return 1; + if (change_lock(mailbox_fd, F_WRLCK)) return 1; if (!(result = mailbox_parse(0))) result = mailbox_write_blocked(); - if (flock(mailbox_fd, LOCK_UN)) return 1; + if (change_lock(mailbox_fd, F_UNLCK)) return 1; return result; } @@ -436,4 +438,15 @@ if (mailbox_fd < 0) return 0; return close(mailbox_fd); +} + +int +change_lock(int fd, int what) +{ + struct flock fl; + + memset(&fl, 0, sizeof(fl)); + fl.l_type = what; + + return fcntl(fd, F_SETLKW, &fl); } diff -ur popa3d-0.4/md5/md5.c popa3d-0.4.new/md5/md5.c --- popa3d-0.4/md5/md5.c Tue Feb 1 06:42:13 2000 +++ popa3d-0.4.new/md5/md5.c Tue May 16 23:39:51 2000 @@ -47,7 +47,11 @@ # ifdef __linux__ # include # else -# include +# ifdef sun +# include +# else +# include +# endif # endif # if __BYTE_ORDER == __BIG_ENDIAN # define WORDS_BIGENDIAN 1 diff -ur popa3d-0.4/md5/md5.h popa3d-0.4.new/md5/md5.h --- popa3d-0.4/md5/md5.h Tue Feb 1 06:42:18 2000 +++ popa3d-0.4.new/md5/md5.h Tue May 16 23:40:01 2000 @@ -36,6 +36,9 @@ #ifdef _LIBC # include +#ifdef sun +#define u_int32_t uint32_t +#endif typedef u_int32_t md5_uint32; #else # if defined __STDC__ && __STDC__ diff -ur popa3d-0.4/misc.c popa3d-0.4.new/misc.c --- popa3d-0.4/misc.c Thu Mar 25 05:25:55 1999 +++ popa3d-0.4.new/misc.c Tue May 16 23:25:38 2000 @@ -17,16 +17,6 @@ return select(0, NULL, NULL, NULL, &timeout); } -int flock_loop(int fd) -{ - while (flock(fd, LOCK_EX)) { - if (errno != EBUSY) return -1; - sleep_select(1, 0); - } - - return 0; -} - int write_loop(int fd, char *buffer, int count) { int offset, block; diff -ur popa3d-0.4/misc.h popa3d-0.4.new/misc.h --- popa3d-0.4/misc.h Thu Mar 25 05:25:55 1999 +++ popa3d-0.4.new/misc.h Tue May 16 23:25:40 2000 @@ -12,11 +12,6 @@ extern int sleep_select(int sec, int usec); /* - * Obtains an exclusive lock, restarting on possible EBUSY errors. - */ -extern int flock_loop(int fd); - -/* * Attempts to write all the supplied data. Returns the number of bytes * written. Any value that differs from the requested count means that * an error has occured; if the value is -1, errno is set appropriately. diff -ur popa3d-0.4/pop_root.c popa3d-0.4.new/pop_root.c --- popa3d-0.4/pop_root.c Tue Feb 1 07:18:12 2000 +++ popa3d-0.4.new/pop_root.c Tue May 16 23:25:46 2000 @@ -23,9 +23,7 @@ #if AUTH_SHADOW #include -#ifdef __GLIBC__ #include -#endif #endif static struct passwd pop_pw;