|
|
@@ -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);
|