]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Adding command line title capability
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 9 Jul 2024 15:05:33 +0000 (11:05 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 9 Jul 2024 15:05:33 +0000 (11:05 -0400)
app/maild.c
lib/subrou.c
lib/uniprc.c
lib/uniprc.h

index 7e2ba5e9a32ca2238cc116cc700e2101677c833b..bea11beaab366f1676db943ea812516fecd1aee6 100644 (file)
@@ -24,7 +24,8 @@ static void task()
 
 {
 (void) rou_alert(0,"JMPDBG starting task");
-(void) sleep(5);
+(void) prc_settitle("JMPDBG bingo!");
+(void) sleep(10);
 (void) rou_alert(0,"JMPDBG task completed");
 }
 /*
@@ -63,6 +64,7 @@ while (proceed==true) {
           proceed=false;//Dive mode 
       break;
     case 2      :       //initialising process
+      (void) prc_preptitle(argc,argv,environ);
       (void) rou_modesubrou(true);
       (void) par_modeunipar(true);
       (void) prc_modeuniprc(true);
@@ -70,10 +72,13 @@ while (proceed==true) {
     case 3      :       //doing main tash
       (void) task();
       break;
-    default     :       //end of task
+    case 4      :       //doing main tash
+      (void) prc_cleantitle();
       (void) prc_modeuniprc(false);
       (void) par_modeunipar(false);
       (void) rou_modesubrou(false);
+      break;
+    default     :       //end of task
       proceed=false;
       break;
     }
index aca5e46e51dcd9043d6b500bce352e183ea08c9c..ae0ddd998e27acf945baafa4fda3d0d86418d663 100644 (file)
@@ -14,7 +14,7 @@
 
 //version definition 
 #define VERSION "0.1"
-#define RELEASE "9"
+#define RELEASE "10"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level
index f07cef6cc705b5840d5d13546c44b3e89f08f553..4ff3b290f430c4c95e7a56068bd9be9d6a3045f8 100644 (file)
 #include        "subrou.h"
 #include        "uniprc.h"
 
-
 //directory to set lock
 #define DIRLOCK                 "/var/run/"APPNAME
 
-static  _Bool modopen;          //boolean module open/close
+/*Process command override structure (proc)    */
+typedef        struct  {
+       int max;        //title max size
+       char *title;    //title storage area
+       }TITLTYP;
+
+static  TITLTYP *title=(TITLTYP *)0;    //storage area for /proc
+                                        //title display
+static  _Bool modopen;                  //boolean module open/close
+
 /*
 \f
 */
@@ -258,6 +266,96 @@ return childpid;
 #undef OPEP
 }
 /*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to free used by "title" struct memory.*/
+/*                                                      */
+/********************************************************/
+void prc_cleantitle()
+
+{
+if (title!=(TITLTYP *)0) {
+  if (environ!=(char **)0) {
+    int i;
+
+    for (i=0;environ[i]!=(char *)0;i++) {
+      (void) free(environ[i]);
+      environ[i]=(char *)0;
+      }
+    (void) free(environ);
+    environ=(char **)0;
+    }
+  (void) free(title);
+  title=(TITLTYP *)0;
+  }
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*                                                     */
+/*     Procedure to find and limit space to            */
+/*     be used as status information available         */
+/*     from proc (ps ax)                               */
+/*                                                      */
+/********************************************************/
+void prc_preptitle(int argc,char *argv[],char *env[])
+
+{
+char *lastend;
+
+lastend=(char *)0;
+(void) prc_cleantitle();
+title=(TITLTYP *)calloc(1,sizeof(TITLTYP));
+if (argv!=(char **)0) {
+  int i;
+
+  title->title=argv[0];
+  for (i=1;i<argc;i++) {
+    lastend=argv[i]+strlen(argv[i]);
+    argv[i]=(char *)0;
+    }
+  }
+if (env!=(char **)0) {
+  int i;
+
+  environ=(char **)0;
+  for (i=0;env[i]!=(char *)0;i++) {
+    char *valeur;
+
+    lastend=env[i]+strlen(env[i]);
+    valeur=strdup(env[i]);
+    (void) putenv(valeur);
+    }
+  }
+title->max=lastend-title->title;
+}
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to update title information.          */
+/*      Title information is avalable via the           */
+/*      CLI (commande line interface) "ps"              */
+/*                                                      */
+/********************************************************/
+void prc_settitle(const char *fmt,...)
+
+{
+va_list args;
+
+va_start(args,fmt);
+if ((title!=(TITLTYP *)0)&&(title->title!=(char *)0)) {
+  (void) memset(title->title,'\000',title->max);
+  (void) vsnprintf(title->title,title->max,fmt,args);
+  }
+va_end(args);
+}
+/*
 ^L
 */
 /********************************************************/
index 0bea4046bc7982f4d8abd252a2bbc98ba421f2f7..d188ae27c71168d2f8e608e43039f07aa701c5c5 100644 (file)
 
 #include        "subrou.h"
 
+extern char **environ;          //context enviromenent variable
+
 #define LCK_UNLOCK   0 /*unlocking request     */
 #define        LCK_LOCK     1  /*locking requets       */
 
+//To clean the command line title area
+extern void prc_cleantitle();
+
+//To duplicate enviromenet library and used as command line data
+extern void prc_preptitle(int argc,char *argv[],char *env[]);
+
+//To insert a string in the command area
+extern void prc_settitle(const char *fmt,...);
+
 //To allow application to core dump is memory is
 //big trouble need to be investigated
 extern void prc_allow_core_dump();