--- embedtools/src/pceng.c 2011/07/22 14:45:30 1.1.2.4 +++ embedtools/src/pceng.c 2011/07/22 15:03:30 1.1.2.5 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: pceng.c,v 1.1.2.4 2011/07/22 14:45:30 misho Exp $ + * $Id: pceng.c,v 1.1.2.5 2011/07/22 15:03:30 misho Exp $ * ************************************************************************* The ELWIX and AITNET software is distributed under the following @@ -58,10 +58,10 @@ Usage() { printf( "-= PCEngines =- events managment tool\n" "=== %s === %s@%s ===\n\n" - " Syntax: pceng [options]\n" + " Syntax: pceng [options] [[led_no <0|1>] ...]\n" "\n" "\t-v\t\tVerbose ...\n" - "\t-b\t\tRun in batch mode ...\n" + "\t-D\t\tRun in background mode ...\n" "\t-c \tConfig events file ...\n" "\n", compiled, compiledby, compilehost); } @@ -93,17 +93,17 @@ sigHand(int sig) int main(int argc, char **argv) { - char ch; - int io, ret = 0, mode = 0; + char ch, ledno; + int i, io, ret = 0, mode = 1; struct sigaction sact; - while ((ch = getopt(argc, argv, "vhbc:")) != -1) + while ((ch = getopt(argc, argv, "vhDc:")) != -1) switch (ch) { case 'c': strlcpy(szConf, optarg, sizeof szConf); break; - case 'b': - mode = 1; + case 'D': + mode = 0; break; case 'v': Verbose++; @@ -116,11 +116,32 @@ main(int argc, char **argv) argc -= optind; argv += optind; - openlog("pceng", LOG_CONS | LOG_PID, LOG_DAEMON); + if (!mode) + openlog("pceng", LOG_CONS | LOG_PID, LOG_DAEMON); + else + openlog("pceng", LOG_CONS | LOG_PID | LOG_PERROR, LOG_USER); + io = open(_PATH_DEVIO, O_RDWR); + if (io == -1) { + printf("Error:: in open dev %s #%d - %s\n", _PATH_DEVIO, errno, strerror(errno)); + ret = 2; + goto end; + } + + if (argc > 1 && !(argc % 2)) { + for (i = 0; !ret && i < argc; i += 2) { + ledno = (char) strtol(argv[i], NULL, 0); + ch = (char) strtol(argv[i + 1], NULL, 0); + ret = LED(io, (u_char) ledno, (u_char) ch); + } + if (ret) + goto end; + } + if (LoadConfig(szConf, &cfg)) { printf("Error:: #%d - %s\n", cfg_GetErrno(), cfg_GetError()); - return 1; + ret = 1; + goto end; } sact.sa_handler = sigHand; @@ -129,13 +150,6 @@ main(int argc, char **argv) sigaction(SIGTERM, &sact, NULL); sigaction(SIGCHLD, &sact, NULL); - io = open(_PATH_DEVIO, O_RDWR); - if (io == -1) { - printf("Error:: in open dev %s #%d - %s\n", _PATH_DEVIO, errno, strerror(errno)); - ret = 2; - goto end; - } - if (!mode) switch (fork()) { case -1: @@ -164,9 +178,9 @@ main(int argc, char **argv) ret = Run(io); end: + UnloadConfig(&cfg); if (io > 2) close(io); - UnloadConfig(&cfg); closelog(); return ret; }