OSSP CVS Repository

ossp - Check-in [3439]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 3439
Date: 2003-Jun-12 16:24:32 (local)
2003-Jun-12 14:24:32 (UTC)
User:ms
Branch:
Comment: Fix shebang handling.
Tickets:
Inspections:
Files:
ossp-pkg/rc/rc_const.h      1.22 -> 1.23     1 inserted, 0 deleted
ossp-pkg/rc/rc_proc.c      1.43 -> 1.44     29 inserted, 24 deleted

ossp-pkg/rc/rc_const.h 1.22 -> 1.23

--- rc_const.h   2003/06/12 13:27:44     1.22
+++ rc_const.h   2003/06/12 14:24:32     1.23
@@ -129,6 +129,7 @@
 
 /* Nontranslatable machine strings, do not translate */
 #define RC_ECHO_STR   "echo "
+#define RC_BANG_STR   "#! /bin/sh\n"
 
 /* Default values, do not include newlines and special chars must be escaped */
 #define RC_DEF_ON     "1"                       /* Digital switch */


ossp-pkg/rc/rc_proc.c 1.43 -> 1.44

--- rc_proc.c    2003/06/12 13:27:44     1.43
+++ rc_proc.c    2003/06/12 14:24:32     1.44
@@ -88,9 +88,6 @@
     assert(*pRc->m_pAnal->m_pszRcs);
     sBuf = (char *)calloc(1, RC_READ_BUFSIZE);
 
-    /* Stick on the starting shell id line */
-    scriptAppend(pRc->m_pScriptcom, "#! /bin/sh\n", strlen("#! /bin/sh\n"));
-
     /* Open the func file if it exists in the configuration */
     if (pRc->m_pAnal->m_szFuncs) {
         if ((nFdfunc = open(pRc->m_pAnal->m_szFuncs, O_RDONLY)) >= 0) {
@@ -190,22 +187,23 @@
 ************************************************/
 rc_return_t procRun(rc_proc_t *pRc)
 {
-    int   nTmp      = 0;              /* Generic index       */
-    size_t nBytes   = 0;              /* Size in bytes       */
-    int   nTmpname  = 0;              /* Temp file name size */
-    int   nRcs      = 0;              /* Rc index            */
-    int   nSecs     = 0;              /* Section index       */
-    int   nSectuid  = -1;             /* The section's user id           */
-    int   nRunuid   = -1;             /* The current user id             */
-    pid_t Pidexec   = -1;             /* When spawning before execv(3)   */
-    char *szTmpfile = NULL;           /* Path of temporary file          */
-    char *szTmp     = NULL;           /* Generic temporary string        */
-    char *szCom     = NULL;           /* Stores common script text       */
-    char *szExec    = NULL;           /* Used only during exec mode      */
-    char *szVerbose = NULL;           /* Used when handling verbose mode */
-    char *pszVec[RC_EXEC_MAXARGS];    /* For passing in to execv(3)      */
-    rc_script_t   *pFatscript = NULL; /* To build a comprehensive script */
-    rc_section_t **ppSectmp   = NULL; /* Used with priority scheduling   */
+    int   nTmp      = 0;                /* Generic index       */
+    size_t nBytes   = 0;                /* Size in bytes       */
+    int   nTmpname  = 0;                /* Temp file name size */
+    int   nRcs      = 0;                /* Rc index            */
+    int   nSecs     = 0;                /* Section index       */
+    int   nSectuid  = -1;               /* The section's user id           */
+    int   nRunuid   = -1;               /* The current user id             */
+    pid_t Pidexec   = -1;               /* When spawning before execv(3)   */
+    char *szTmpfile = NULL;             /* Path of temporary file          */
+    char *szTmp     = NULL;             /* Generic temporary string        */
+    char *szCom     = NULL;             /* Stores common script text       */
+    char *szExec    = NULL;             /* Used only during exec mode      */
+    char *szVerbose = NULL;             /* Used when handling verbose mode */
+    char *pszVec[RC_EXEC_MAXARGS];      /* For passing in to execv(3)      */
+    rc_script_t   *pBangscript = NULL;  /* Common script with the shebang  */
+    rc_script_t   *pFatscript  = NULL;  /* To build a comprehensive script */
+    rc_section_t **ppSectmp    = NULL;  /* Used with priority scheduling   */
 
     /****************************************************/
     /* This will execute, evaluate, or print the script */
@@ -217,6 +215,7 @@
         /* Allocate a block of section pointers to use temporarily */
         ppSectmp = calloc(pRc->m_pAnal->m_nRcs, sizeof(rc_section_t *));
         pFatscript = scriptNew();
+        scriptAppend(pFatscript, RC_BANG_STR, strlen(RC_BANG_STR)); /* Shebang */
         /* Conditionally print common section notice in verbal mode */
         if (configGetval(RC_VRB_VAL)) {
             nBytes = (strlen(RC_PRN_TEXT) + strlen(RC_CMN_TEXT) * 2 + 1) * sizeof (char);
@@ -333,9 +332,10 @@
                         + strlen(RC_ECHO_STR) + strlen("\"\"") + 1) * sizeof (char);
                     szVerbose = malloc(nComverb);
                     sprintf(szVerbose, RC_EXN_TEXT, RC_CMN_TEXT, RC_CMN_TEXT);
-                    nCommon = (strlen(szCom) + 1) * sizeof (char);
+                    nCommon = (strlen(szCom) + strlen(RC_BANG_STR) + 1) * sizeof (char);
                     szExec = malloc(nComverb + nCommon);
-                    strcpy(szExec, RC_ECHO_STR);    /* Start out with the echo string */
+                    strcpy(szExec, RC_BANG_STR);    /* Start out with the bang string */
+                    strcat(szExec, RC_ECHO_STR);    /* Continue with the echo string */
                     strcat(szExec, "\"");           /* Append a quote next to the echo */
                     strcat(szExec, szVerbose);      /* Continue with the verboseity text */
                     strcat(szExec, "\"");           /* Finalize the verbosity notice */
@@ -382,7 +382,8 @@
                 else {
                     szTmp = (char *)sectionGetdata(ppSectmp[nTmp]);
                     szExec = malloc((strlen(szCom) + strlen(szTmp) + 1) * sizeof(char));
-                    strcpy(szExec, szCom); /* Start out with just the common script code */
+                    strcpy(szExec, RC_BANG_STR);    /* Start out with the shebang string */
+                    strcat(szExec, szCom); /* Continue with just the common script code  */
                     strcat(szExec, szTmp); /* And build a section onto the command chain */
                     pszVec[2] = szExec;    /* Actually launch the new process image now  */
 
@@ -415,15 +416,19 @@
     else if (configGetval(RC_PRN_VAL)) {                        /* Print  */
         /* Allocate a block of section pointers to use as a temporary */
         ppSectmp = calloc(pRc->m_pAnal->m_nRcs, sizeof(rc_section_t *));
+        pBangscript = scriptNew();
+        scriptAppend(pBangscript, RC_BANG_STR, (strlen(RC_BANG_STR) + 1) * sizeof (char));
         /* Conditionally print common section notice in verbal mode */
         if (configGetval(RC_VRB_VAL)) {
             nBytes = (strlen(RC_PRN_TEXT) + strlen(RC_CMN_TEXT) * 2 + 1) * sizeof (char);
             szVerbose = malloc(nBytes);
             sprintf(szVerbose, RC_PRN_TEXT, RC_CMN_TEXT, RC_CMN_TEXT);
-            fprintf(stderr, "%s", szVerbose);
+            scriptAppend(pBangscript, szVerbose, (strlen(szVerbose) + 1) * sizeof (char));
             free(szVerbose);
         }
-        scriptDump(pRc->m_pScriptcom); /* Dump the common script */
+        scriptDump(pBangscript);        /* Dump the common script with shebang */
+        scriptDump(pRc->m_pScriptcom);  /* Dump the rest of the common script */
+        scriptDelete(pBangscript);
         for (nSecs = 0; nSecs < pRc->m_pAnal->m_nSecs; nSecs++) {
             for (nRcs = 0; nRcs < pRc->m_pAnal->m_nRcs; nRcs++) {
                 nTmp = 0;

CVSTrac 2.0.1