--- embedtools/src/cfexec.c 2009/11/12 10:35:55 1.1 +++ embedtools/src/cfexec.c 2011/06/13 20:04:12 1.2.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: cfexec.c,v 1.1 2009/11/12 10:35:55 misho Exp $ + * $Id: cfexec.c,v 1.2.2.1 2011/06/13 20:04:12 misho Exp $ * *************************************************************************/ #include "global.h" @@ -15,6 +15,7 @@ char szUser[MAX_STR], szMount[MAXPATHLEN], szDev[MAXPA szChroot[MAXPATHLEN], szSess[MAXPATHLEN], szConfig[MAXPATHLEN]; extern char compiled[], compiledby[], compilehost[]; + static void Usage() { @@ -24,7 +25,7 @@ static void Usage() "\t-v\t\tVerbose ...\n" "\t-c \tAfter execute chroot to dir [default=/]\n" "\t-u \tAfter execute suid to user [default=root]\n" - "\t-d \tOther device [default=/dev/ufs/AITBSDonCF]\n" + "\t-d \tOther device [default=/dev/ufs/elwix]\n" "\t-m \tOther mount dir [default=/cf]\n" "\t-t \tTimeout for autolock mount dir after seconds [default=300]\n" "\n", compiled, compiledby, compilehost); @@ -36,7 +37,11 @@ static int update(int flags) memset(&mnt, 0, sizeof mnt); mnt.fspec = szDev; +#ifdef __NetBSD__ + if (mount("ufs", szMount, flags, &mnt, sizeof mnt) == -1) { +#else if (mount("ufs", szMount, flags, &mnt) == -1) { +#endif printf("Error:: can`t update mount %s #%d - %s\n", szMount, errno, strerror(errno)); return -1; } @@ -87,7 +92,7 @@ static int mkevent(struct kevent *chg, struct kevent * memset(chg, 0, sizeof(struct kevent)); memset(evt, 0, sizeof(struct kevent)); - EV_SET(chg, f, EVFILT_VNODE, EV_ADD, NOTE_DELETE | NOTE_RENAME | NOTE_REVOKE, 0, NULL); + EV_SET(chg, f, EVFILT_VNODE, EV_ADD, NOTE_DELETE | NOTE_RENAME | NOTE_REVOKE, 0, (intptr_t) NULL); } return f; @@ -98,7 +103,7 @@ static int mkevent(struct kevent *chg, struct kevent * int main(int argc, char **argv) { char ch; - const char *err; + const char *err = NULL; struct kevent chg, evt; struct timespec ts; pid_t pid; @@ -109,8 +114,12 @@ int main(int argc, char **argv) // Load variables from config if exists if (!LoadConfig(szConfig, &cfg)) { cfg_LoadAttribute(&cfg, CFG("cfexec"), CFG("timeout"), CFG(szUser), MAX_STR, DEFAULT_TIMEOUT); - Timeout = strtonum(szUser, 1, 3600, &err); - if (!Timeout) { +#ifndef HAVE_STRTONUM + Timeout = (int) strtol(szUser, NULL, 0); +#else + Timeout = strtonum(szUser, 0, 3600, &err); +#endif + if (!Timeout && err) { printf("Error:: in seconds for timeout %s - %s\n", optarg, err); UnloadConfig(&cfg); return 1; @@ -148,8 +157,12 @@ int main(int argc, char **argv) strlcpy(szMount, optarg, MAXPATHLEN); break; case 't': - Timeout = strtonum(optarg, 1, 3600, &err); - if (!Timeout) { +#ifndef HAVE_STRTONUM + Timeout = (int) strtol(szUser, NULL, 0); +#else + Timeout = strtonum(optarg, 0, 3600, &err); +#endif + if (!Timeout && err) { printf("Error:: in seconds for timeout %s - %s\n", optarg, err); return 1; @@ -190,9 +203,11 @@ int main(int argc, char **argv) if ((f = mkevent(&chg, &evt)) == -1) return 5; - memset(&ts, 0, sizeof ts); - ts.tv_sec = Timeout; - switch (kevent(kq, &chg, 1, &evt, 1, &ts)) { + if (Timeout) { + memset(&ts, 0, sizeof ts); + ts.tv_sec = Timeout; + } + switch (kevent(kq, &chg, 1, &evt, 1, !Timeout ? NULL : &ts)) { case -1: printf("Error:: can`t execute safe mount #%d - %s\n", errno, strerror(errno)); @@ -236,7 +251,7 @@ int main(int argc, char **argv) if (strncmp(szUser, "root", 5)) setuser(); - chdir("/"); + /* chdir("/"); */ execvp(*argv, argv); } _exit(127);