Attached patch adds command line args for
PID file and logging std out/err to files.
In addition the patch modifies vblade
to detach from controlling terminal.

Patch is against vblade-20

--
James R. Leu
Software Architect
INOC
608.204.0203
608.663.4555 fax
j...@inoc.com
www.inoc.com

*** DELIVERING UPTIME ***
diff -uNr vblade-20/aoe.c vblade-20-jleu/aoe.c
--- vblade-20/aoe.c     2009-08-14 13:39:26.000000000 -0500
+++ vblade-20-jleu/aoe.c        2011-08-11 11:01:24.000000000 -0500
@@ -379,7 +379,7 @@
 void
 usage(void)
 {
-       fprintf(stderr, "usage: %s [-b bufcnt] [-d ] [-s] [-r] [ -m 
mac[,mac...] ] shelf slot netif filename\n", 
+       fprintf(stderr, "usage: %s [-b bufcnt] [-d ] [-s] [-r] [-p file] [-l 
dir] [ -m mac[,mac...] ] shelf slot netif filename\n", 
                progname);
        exit(1);
 }
@@ -462,11 +462,16 @@
 main(int argc, char **argv)
 {
        int ch, omode = 0, readonly = 0;
+       long pid;
+       char *pfile = NULL;
+       char *ldir = NULL;
+       char outfile[1024];
+       char errfile[1024];
 
        bufcnt = Bufcount;
        setbuf(stdin, NULL);
        progname = *argv;
-       while ((ch = getopt(argc, argv, "b:dsrm:")) != -1) {
+       while ((ch = getopt(argc, argv, "b:dsrm:p:l:")) != -1) {
                switch (ch) {
                case 'b':
                        bufcnt = atoi(optarg);
@@ -482,6 +487,12 @@
                case 'r':
                        readonly = 1;
                        break;
+               case 'p':
+                       pfile = optarg;
+                       break;
+               case 'l':
+                       ldir = optarg;
+                       break;
                case 'm':
                        setmask(optarg);
                        break;
@@ -506,14 +517,57 @@
        size = getsize(bfd);
        size /= 512;
        ifname = argv[2];
+
+       if (ldir) {
+           if (snprintf(outfile, 1024, "%s/vblade-%d-%d.out", ldir, shelf, 
slot) < 0) {
+               perror("outfile");
+               exit(1);
+           }
+           if (snprintf(errfile, 1024, "%s/vblade-%d-%d.out", ldir, shelf, 
slot) < 0) {
+               perror("errfile");
+               exit(1);
+           }
+       } else {
+           if (snprintf(outfile, 1024, "/dev/null") < 0) {
+               perror("outfile");
+               exit(1);
+           }
+           if (snprintf(errfile, 1024, "/dev/null") < 0) {
+               perror("errfile");
+               exit(1);
+           }
+       }
+
+        pid = fork();
+       if (pid < 0) {
+           /* error */
+           perror("fork");
+           exit(1);
+       }
+       if (pid > 0) {
+           /* parent */
+           if (pfile) {
+               FILE *handle = fopen(pfile, "w");
+               if (handle) {
+                   fprintf(handle, "%ld\n", pid);
+                   fclose(handle);
+               }
+           }
+           printf("pid %ld: e%d.%d, %lld sectors %s\n",
+               pid, shelf, slot, size,
+               readonly ? "O_RDONLY" : "O_RDWR");
+           fflush(stdout);
+           exit(0);
+       }
+
+       /* child */
+       freopen(outfile, "a+", stdout);
+       freopen(errfile, "a+", stderr);
+       setsid();
+
        sfd = dial(ifname, bufcnt);
        getea(sfd, ifname, mac);
-       printf("pid %ld: e%d.%d, %lld sectors %s\n",
-               (long) getpid(), shelf, slot, size,
-               readonly ? "O_RDONLY" : "O_RDWR");
-       fflush(stdout);
        atainit();
        aoe();
        return 0;
 }
-

Attachment: pgpTSZIQ1p8hi.pgp
Description: PGP signature

------------------------------------------------------------------------------
FREE DOWNLOAD - uberSVN with Social Coding for Subversion.
Subversion made easy with a complete admin console. Easy 
to use, easy to manage, easy to install, easy to extend. 
Get a Free download of the new open ALM Subversion platform now.
http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Aoetools-discuss mailing list
Aoetools-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/aoetools-discuss

Reply via email to