• implement fcntl(2)-based advisory locking as an alternative iff flock(2)

is not found, from a suggestion by RT (LP: #912691)
• try harder (in a loop) to acquire a file lock if the locking mechanism
  documents EINTR is a possibility (fcntl always, flock on Linux not .Ox)
• use -std=c99 not -std=gnu99 if it must be at all
This commit is contained in:
tg
2012-03-27 22:36:53 +00:00
parent e3b9f14d88
commit 95a2c63096
6 changed files with 106 additions and 34 deletions

6
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.211 2012/03/25 14:28:14 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.212 2012/03/27 22:36:52 tg Exp $");
extern char **environ;
@ -1721,7 +1721,7 @@ DF(const char *fmt, ...)
va_list args;
struct timeval tv;
(void)flock(shl_dbg_fd, LOCK_EX);
mksh_lockfd(shl_dbg_fd);
gettimeofday(&tv, NULL);
shf_fprintf(shl_dbg, "[%d.%06d:%d] ", (int)tv.tv_sec, (int)tv.tv_usec,
(int)getpid());
@ -1730,6 +1730,6 @@ DF(const char *fmt, ...)
va_end(args);
shf_putc('\n', shl_dbg);
shf_flush(shl_dbg);
(void)flock(shl_dbg_fd, LOCK_UN);
mksh_unlkfd(shl_dbg_fd);
}
#endif