pseudo_util: Add log severity flags
PATCH 1/1 pseudo_util: Add log severity flags
From: Dmitry Sakhonchik <[email protected]>
Create an infrastructure to make use of severity flags from pseudo_tables.
After that it is now possible to set severity flags from env (PSEUDO_SEVERITY) and from terminal via optargs.
[YOCTO #12141]
--- pseudo.c | 8 +++++++- pseudo.h | 3 +++ pseudo_util.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-)
pseudo.c +7 -1
@@ -134,7 +134,10 @@ main(int argc, char *argv[]) {* wrong. The + suppresses this annoying behavior, but may not * be compatible with sane option libraries. */ -while ((o =getopt (argc, argv,"+BCdfhi:lm:M:p:P:r:R:St:vVx:" )) !=-1 ) { +while ((o =getopt (argc, argv,"+BCdfhi:lm:M:p:P:r:R:St:vVx:k:" )) !=-1 ) { +/* ^^^^^ */ +/* which letter to choose for severity is a topic for discussion */ +/* I've chosen 'k' simply because it was not used yet */ switch (o) {case 'B' :/* rebuild database */ opt_B =1 ;
@@ -231,6 +234,9 @@ main(int argc, char *argv[]) {printf ("Set PSEUDO_PREFIX to run with a different prefix.\n" );exit (0 );break ; +case 'k' :/* debug severity */ +pseudo_severity_set (optarg); +break ;case 'x' :/* debug flags */ pseudo_debug_set (optarg);break ;
pseudo.h +3 -0
@@ -26,8 +26,11 @@ extern void pseudo_debug_terse(void);extern void pseudo_debug_set (char *);extern void pseudo_debug_clear (char *);extern void pseudo_debug_flags_finalize (void ); +extern void pseudo_severity_set (char *); +extern void pseudo_severity_flags_finalize (void );extern unsigned long pseudo_util_debug_flags;extern unsigned long pseudo_util_evlog_flags; +extern unsigned long pseudo_util_severity_flags;extern int pseudo_util_debug_fd;extern int pseudo_disabled;extern int pseudo_allow_fsync;
pseudo_util.c +44 -0
84 lines not on this page · raw message
Sorry for the late reply.
Quoted 19 lines · Dmitry Sakhonchik via lists.yoctoproject.org
From: Dmitry Sakhonchik <[email protected]>
Create an infrastructure to make use of severity flags from
pseudo_tables.
After that it is now possible to set severity flags from env (PSEUDO_SEVERITY) and from terminal via optargs.[YOCTO #12141]
Signed-off-by Dmitry Sakhonchik <[email protected]>--- pseudo.c | 8 +++++++- pseudo.h | 3 +++ pseudo_util.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-)pseudo.c +0
-0
pseudo.c main(int argc, char *argv[]) { · line 137
Quoted 5 lines
pseudo.c +1
-1@@ -134,7 +134,10 @@ main(int argc, char *argv[]) {* wrong. The + suppresses this annoying behavior, but may not * be compatible with sane option libraries. */ -while ((o =getopt (argc, argv,"+BCdfhi:lm:M:p:P:r:R:St:vVx:" )) !=-1 ) { +while ((o =getopt (argc, argv,"+BCdfhi:lm:M:p:P:r:R:St:vVx:k:" )) !=-1 ) {
In the above string, the letters should be in alphabetic order. So the new line should be:
+BCdfhi:klm:M:p:P:r:R:St:vVx:
pseudo.c main(int argc, char *argv[]) { · line 140
Quoted 3 lines
pseudo.c +3
-0+/* ^^^^^ */ +/* which letter to choose for severity is a topic for discussion */ +/* I've chosen 'k' simply because it was not used yet */
I've no objections to 'k'. We're out of easily letters at this point.. :(
Quoted 133 lines
pseudo.c +3
-0switch (o) {case 'B' :/* rebuild database */ opt_B =1 ;@@ -231,6 +234,9 @@ main(int argc, char *argv[]) {printf ("Set PSEUDO_PREFIX to run with a different prefix.\n" );exit (0 );break ; +case 'k' :/* debug severity */ +pseudo_severity_set (optarg); +break ;case 'x' :/* debug flags */ pseudo_debug_set (optarg);break ;pseudo.h +3
-0@@ -26,8 +26,11 @@ extern void pseudo_debug_terse(void);extern void pseudo_debug_set (char *);extern void pseudo_debug_clear (char *);extern void pseudo_debug_flags_finalize (void ); +extern void pseudo_severity_set (char *); +extern void pseudo_severity_flags_finalize (void );extern unsigned long pseudo_util_debug_flags;extern unsigned long pseudo_util_evlog_flags; +extern unsigned long pseudo_util_severity_flags;extern int pseudo_util_debug_fd;extern int pseudo_disabled;extern int pseudo_allow_fsync;pseudo_util.c +44
-1@@ -63,6 +63,7 @@ static struct pseudo_variables pseudo_env[] = {#endif { "PSEUDO_EVLOG", 12, NULL }, { "PSEUDO_EVLOG_FILE", 17, NULL }, + { "PSEUDO_SEVERITY", 15, NULL }, { NULL, 0, NULL } /* Magic terminator */ };@@ -90,6 +91,7 @@ static int pseudo_evlog_next_entry = 0;static void pseudo_evlog_set (char *);static void pseudo_evlog_flags_finalize (void );static unsigned long pseudo_debug_flags_in (char *); +static unsigned long pseudo_severity_flags_in (char *);/* -1 - init hasn't been run yet * 0 - init has been run @@ -247,10 +249,17 @@ pseudo_init_util(void) {pseudo_evlog_flags_finalize (); }free (env); + env =pseudo_get_value ("PSEUDO_SEVERITY" ); +if (env) { +pseudo_severity_set (env); +pseudo_severity_flags_finalize (); + } +free (env); }unsigned long pseudo_util_debug_flags =0 ;unsigned long pseudo_util_evlog_flags =0 ; +unsigned long pseudo_util_severity_flags =0 ;int pseudo_util_debug_fd =2 ;int pseudo_util_evlog_fd =2 ;static int debugged_newline =1 ;@@ -433,6 +442,11 @@ pseudo_evlog_set(char *s) { pseudo_util_evlog_flags =pseudo_debug_flags_in (s); } +void +pseudo_severity_set (char *s) { + pseudo_util_severity_flags =pseudo_severity_flags_in (s); +} +/* This exists because we don't want to allocate a bunch of strings * and free them immediately if you have several flags set. */ @@ -457,6 +471,11 @@ pseudo_evlog_flags_finalize(void) {pseudo_flags_finalize (pseudo_util_evlog_flags,"PSEUDO_EVLOG" ); } +void +pseudo_severity_flags_finalize (void ) { +pseudo_flags_finalize (pseudo_util_severity_flags,"PSEUDO_SEVERITY" ); +} +static unsigned long pseudo_debug_flags_in (char *s) {unsigned long flags =0 ;@@ -471,6 +490,31 @@ pseudo_debug_flags_in(char *s) {return flags; } +static unsigned long +pseudo_severity_flags_in (char *s) { +unsigned long flags =0 ; +char *token =NULL ; +char *saveptr =NULL ; +char *s_copy =NULL ; + +if (!s) +return flags; + + s_copy =strdup (s); + + token =strtok_r (s_copy," ,;" , &saveptr); +while (token !=NULL ) { +pseudo_sev_t id =pseudo_sev_id (token); +if (id >SEVERITY_NONE && id <SEVERITY_MAX ) { + flags |= (1UL << id); + } + token =strtok_r (NULL ," ,;" , &saveptr); + } + +free (s_copy); +return flags; +} +void pseudo_debug_clear (char *s) {if (!s) -=-=-=-=-=-=-=-=-=-=-=-Links: You receive all messages sent to this group.
View/Reply Online (#4074): https://lists.yoctoproject.org/g/yocto-patches/message/4074
Mute This Topic: https://lists.yoctoproject.org/mt/119511285/3616948
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/yocto-patches/leave/13201099/3616948/947757854/xyzzy [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-