--- embedtools/src/cfexec.c 2017/10/08 22:28:26 1.5.20.3 +++ embedtools/src/cfexec.c 2018/01/01 23:48:32 1.5.20.6 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: cfexec.c,v 1.5.20.3 2017/10/08 22:28:26 misho Exp $ + * $Id: cfexec.c,v 1.5.20.6 2018/01/01 23:48:32 misho Exp $ * ************************************************************************* The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2017 +Copyright 2004 - 2018 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -71,17 +71,34 @@ Usage() "\n", compiled, compiledby, compilehost); } +struct statfs * +getmntpt(const char *name) +{ + struct statfs *mntbuf; + int i, mntsize; + + mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); + for (i = mntsize - 1; i >= 0; i--) { + if (!strcmp(mntbuf[i].f_mntfromname, name) || + !strcmp(mntbuf[i].f_mntonname, name)) + return &mntbuf[i]; + } + + return NULL; +} + static int update(int flags) { struct ufs_args mnt; + struct statfs *mntfs = getmntpt(AIT_GET_STR(&Mount)); memset(&mnt, 0, sizeof mnt); - mnt.fspec = AIT_GET_STR(&Dev); + mnt.fspec = mntfs->f_mntfromname; #ifdef __NetBSD__ - if (mount("ufs", AIT_GET_STR(&Mount), flags, &mnt, sizeof mnt) == -1) { + if (mount(mntfs->f_fstypename, mntfs->f_mntonname, flags, &mnt, sizeof mnt) == -1) { #else - if (mount("ufs", AIT_GET_STR(&Mount), flags, &mnt) == -1) { + if (mount(mntfs->f_fstypename, mntfs->f_mntonname, flags, &mnt) == -1) { #endif printf("Error:: can`t update mount %s #%d - %s\n", AIT_GET_STR(&Mount), errno, strerror(errno)); @@ -160,7 +177,7 @@ static int s_unlck() { if (access(szSLCK, F_OK)) - return 1; + return 2; if (access(szSess, F_OK) && update(MNT_UPDATE | MNT_RDONLY) == -1) return 8; @@ -177,14 +194,14 @@ s_lck(const char *reason) char szStr[STRSIZ]; if (!access(szSLCK, F_OK)) { - printf("cfexec:: Service held lock ...\n"); + printf("cfexec already held service lock ...\n"); return 127; } f = open(szSLCK, O_CREAT | O_WRONLY | O_TRUNC, 0644); if (f == -1) { printf("Error:: can`t service lock session #%d - %s\n", errno, strerror(errno)); - return 5; + return 4; } else { memset(szStr, 0, sizeof szStr); snprintf(szStr, sizeof szStr, "[%d] - %s", getpid(), reason); @@ -194,7 +211,7 @@ s_lck(const char *reason) if (update(MNT_UPDATE) == -1) { unlink(szSLCK); - return 4; + return 5; } VERB(3) printf("Lock & created service lock file %s\n", szSLCK); @@ -325,8 +342,10 @@ main(int argc, char **argv) if ((f = mkevent(&chg, &evt)) == -1) return 4; - if (update(MNT_UPDATE) == -1) - return 5; + if (update(MNT_UPDATE) == -1) { + stat = 5; + goto skip; + } if (Timeout) { memset(&ts, 0, sizeof ts); @@ -349,7 +368,7 @@ main(int argc, char **argv) if (access(szSLCK, F_OK) && update(MNT_UPDATE | MNT_RDONLY) == -1) stat = 8; } - +skip: close(kq); close(f); unlink(szSess); @@ -368,8 +387,10 @@ main(int argc, char **argv) else close(f); - if (update(MNT_UPDATE) == -1) + if (update(MNT_UPDATE) == -1) { + unlink(szSess); return 5; + } switch ((pid = vfork())) { case -1: