diff options
author | Wichert Akkerman <wakkerma@debian.org> | 2000-01-11 01:11:12 +0000 |
---|---|---|
committer | Wichert Akkerman <wakkerma@debian.org> | 2000-01-11 01:11:12 +0000 |
commit | 68c55e2e366d55a657c43c1b519337a820ed2239 (patch) | |
tree | 94e95b5a4d4c4ee62ff0ca7625d562116ca41a20 /dselect/method.cc | |
parent | 4862ae37a46904bc8529ffca00deed1c9627dab9 (diff) | |
download | dpkg-68c55e2e366d55a657c43c1b519337a820ed2239.tar.gz |
dselect/baselist.cc: don't specify SA_INTERRUPT, since it's not portable and the default behaviour
main/enquiry.c: include sys/termios.h (needed on Solaris)
lib/lock.c: use EACCESS instead of EWOULDBLOCK
dselect/main.cc: fix help for -D
dselect/main.cc: try to lock admindir instead of using readwrite
dselect/method.cc: switch to using fcntl for lock since that is more portable, and revamp lockingcode to reduce code duplication
Diffstat (limited to 'dselect/method.cc')
-rw-r--r-- | dselect/method.cc | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/dselect/method.cc b/dselect/method.cc index 69b372f8f..01756a34d 100644 --- a/dselect/method.cc +++ b/dselect/method.cc @@ -55,11 +55,27 @@ static const char *const methoddirectories[]= { static char *methodlockfile= 0; static int methlockfd= -1; +void sthfailed(const char * reasoning) { + char buf[2048]; + + curseson(); + clear(); + sprintf(buf,_("\n\n%s: %s\n"),DSELECT,reasoning); + addstr(buf); + attrset(A_BOLD); + addstr(_("\nPress <enter> to continue.")); + attrset(A_NORMAL); + refresh(); getch(); +} + static void cu_unlockmethod(int, void**) { + struct flock fl; + assert(methodlockfile); assert(methlockfd); - if (flock(methlockfd,LOCK_UN)) - ohshite(_("unable to unlock access method area")); + fl.l_type=F_UNLCK; fl.l_whence= SEEK_SET; fl.l_start=fl.l_len=0; + if (fcntl(methlockfd,F_SETLK,&fl) == -1) + sthfailed("unable to unlock access method area"); } static enum urqresult ensureoptions(void) { @@ -73,10 +89,7 @@ static enum urqresult ensureoptions(void) { for (ccpp= methoddirectories; *ccpp; ccpp++) readmethods(*ccpp, &newoptions, &nread); if (!newoptions) { - curseson(); - addstr(_("No access methods are available.\n\n" - "Press <enter> to continue.")); - refresh(); getch(); + sthfailed("no access methods are available"); return urqr_fail; } options= newoptions; @@ -85,20 +98,9 @@ static enum urqresult ensureoptions(void) { return urqr_normal; } -static void lockfailed(const char * reasoning) { - char buf[2048]; - - curseson(); - clear(); - sprintf(buf,_("\n\n%s: %s\n"),DSELECT,reasoning); - addstr(buf); - attrset(A_BOLD); - addstr(_("\nPress <enter> to continue.")); - attrset(A_NORMAL); - refresh(); getch(); -} - static enum urqresult lockmethod(void) { + struct flock fl; + if (!methodlockfile) { int l; l= strlen(admindir); @@ -110,19 +112,20 @@ static enum urqresult lockmethod(void) { methlockfd= open(methodlockfile, O_RDWR|O_CREAT|O_TRUNC, 0660); if (methlockfd == -1) { if ((errno == EPERM) || (errno == EACCES)) { - lockfailed("requested operation requires superuser privilege"); + sthfailed("requested operation requires superuser privilege"); return urqr_fail; } - lockfailed("unable to open/create access method lockfile"); + sthfailed("unable to open/create access method lockfile"); return urqr_fail; } } - if (flock(methlockfd,LOCK_EX|LOCK_NB)) { + fl.l_type=F_WRLCK; fl.l_whence=SEEK_SET; fl.l_start=fl.l_len=0; + if (fcntl(methlockfd,F_SETLK,&fl) == -1) { if (errno == EWOULDBLOCK || errno == EAGAIN) { - lockfailed("the access method area is already locked"); + sthfailed("the access method area is already locked"); return urqr_fail; } - lockfailed("unable to lock access method area"); + sthfailed("unable to lock access method area"); return urqr_fail; } push_cleanup(cu_unlockmethod,~0, 0,0, 0); @@ -219,10 +222,7 @@ static urqresult runscript(const char *exepath, const char *name) { }; ur= falliblesubprocess(coption->meth->path,name,fallibleargs); } else { - curseson(); - addstr(_("No access method is selected/configured.\n\n" - "Press <enter> to continue.")); - refresh(); getch(); + sthfailed("no access method is selected/configured"); ur= urqr_fail; } pop_cleanup(ehflag_normaltidy); |