Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
6
66
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eric Vidal
66
Commits
7df1e682
Commit
7df1e682
authored
2 years ago
by
Eric Vidal
Browse files
Options
Downloads
Patches
Plain Diff
adapt to new state format
parent
e1717952
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/66/66-instate.c
+60
-63
60 additions, 63 deletions
src/66/66-instate.c
with
60 additions
and
63 deletions
src/66/66-instate.c
+
60
−
63
View file @
7df1e682
...
@@ -31,13 +31,14 @@
...
@@ -31,13 +31,14 @@
#include
<66/utils.h>
#include
<66/utils.h>
#include
<66/constants.h>
#include
<66/constants.h>
#include
<66/state.h>
#include
<66/state.h>
#include
<66/config.h>
#define MAXOPTS
7
#define MAXOPTS
11
static
wchar_t
const
field_suffix
[]
=
L" :"
;
static
wchar_t
const
field_suffix
[]
=
L" :"
;
static
char
fields
[
INFO_NKEY
][
INFO_FIELD_MAXLEN
]
=
{{
0
}}
;
static
char
fields
[
INFO_NKEY
][
INFO_FIELD_MAXLEN
]
=
{{
0
}}
;
#define USAGE "66-instate [ -h ] [ -
z ] [ -t tree
] [ -
l
] service"
#define USAGE "66-instate [ -h ] [ -
v verbosity
] [ -
z
] service"
static
inline
void
info_help
(
void
)
static
inline
void
info_help
(
void
)
{
{
...
@@ -49,7 +50,6 @@ static inline void info_help (void)
...
@@ -49,7 +50,6 @@ static inline void info_help (void)
" -h: print this help
\n
"
" -h: print this help
\n
"
" -z: use color
\n
"
" -z: use color
\n
"
" -t: only search service at the specified tree
\n
"
" -t: only search service at the specified tree
\n
"
" -l: prints information of the associated logger if exist
\n
"
;
;
log_info
(
USAGE
,
"
\n
"
,
help
)
;
log_info
(
USAGE
,
"
\n
"
,
help
)
;
...
@@ -86,27 +86,27 @@ static void info_display_int(char const *field,unsigned int id)
...
@@ -86,27 +86,27 @@ static void info_display_int(char const *field,unsigned int id)
int
main
(
int
argc
,
char
const
*
const
*
argv
)
int
main
(
int
argc
,
char
const
*
const
*
argv
)
{
{
int
found
=
0
;
int
found
=
0
;
uint8_t
logger
=
0
;
resolve_service_t
res
=
RESOLVE_SERVICE_ZERO
;
resolve_service_t
res
=
RESOLVE_SERVICE_ZERO
;
resolve_wrapper_t_ref
wres
=
resolve_set_struct
(
DATA_SERVICE
,
&
res
)
;
resolve_wrapper_t_ref
wres
=
resolve_set_struct
(
DATA_SERVICE
,
&
res
)
;
stralloc
satree
=
STRALLOC_ZERO
;
char
base
[
SS_MAX_PATH
+
1
]
;
stralloc
src
=
STRALLOC_ZERO
;
stralloc
tmp
=
STRALLOC_ZERO
;
ss_state_t
sta
=
STATE_ZERO
;
ss_state_t
sta
=
STATE_ZERO
;
char
const
*
tname
=
0
;
char
const
*
svname
=
0
;
char
const
*
svname
=
0
;
char
const
*
ste
=
0
;
char
const
*
ste
=
0
;
char
atree
[
SS_MAX_TREENAME
+
1
]
;
log_color
=
&
log_color_disable
;
log_color
=
&
log_color_disable
;
char
buf
[
MAXOPTS
][
INFO_FIELD_MAXLEN
]
=
{
char
buf
[
MAXOPTS
][
INFO_FIELD_MAXLEN
]
=
{
"Reload"
,
"toinit"
,
"Init"
,
"toreload"
,
"Unsupervise"
,
"torestart"
,
"State"
,
"tounsupervise"
,
"Pid"
,
"isdownfile"
,
"Name"
,
"isearlier"
,
"Real_logger_name"
}
;
"isenabled"
,
"isparsed"
,
"issupervised"
,
"isup"
}
;
PROG
=
"66-instate"
;
PROG
=
"66-instate"
;
{
{
...
@@ -114,16 +114,35 @@ int main(int argc, char const *const *argv)
...
@@ -114,16 +114,35 @@ int main(int argc, char const *const *argv)
for
(;;)
for
(;;)
{
{
int
opt
=
getopt_args
(
argc
,
argv
,
">hz
l
t:"
,
&
l
)
;
int
opt
=
getopt_args
(
argc
,
argv
,
">h
v:
zt:"
,
&
l
)
;
if
(
opt
==
-
1
)
break
;
if
(
opt
==
-
1
)
break
;
if
(
opt
==
-
2
)
log_die
(
LOG_EXIT_USER
,
"options must be set first"
)
;
if
(
opt
==
-
2
)
log_die
(
LOG_EXIT_USER
,
"options must be set first"
)
;
switch
(
opt
)
switch
(
opt
)
{
{
case
'h'
:
info_help
();
return
0
;
case
'h'
:
case
'z'
:
log_color
=
!
isatty
(
1
)
?
&
log_color_disable
:
&
log_color_enable
;
break
;
case
't'
:
tname
=
l
.
arg
;
break
;
info_help
();
case
'l'
:
logger
=
1
;
break
;
return
0
;
default
:
log_usage
(
USAGE
)
;
case
'v'
:
if
(
!
uint0_scan
(
l
.
arg
,
&
VERBOSITY
))
log_usage
(
USAGE
)
;
break
;
case
'z'
:
log_color
=
!
isatty
(
1
)
?
&
log_color_disable
:
&
log_color_enable
;
break
;
case
't'
:
log_1_warn
(
"deprecated option -t -- ignore it"
)
;
break
;
default
:
log_usage
(
USAGE
)
;
}
}
}
}
argc
-=
l
.
ind
;
argv
+=
l
.
ind
;
argc
-=
l
.
ind
;
argv
+=
l
.
ind
;
...
@@ -132,55 +151,33 @@ int main(int argc, char const *const *argv)
...
@@ -132,55 +151,33 @@ int main(int argc, char const *const *argv)
if
(
!
argc
)
log_usage
(
USAGE
)
;
if
(
!
argc
)
log_usage
(
USAGE
)
;
svname
=
*
argv
;
svname
=
*
argv
;
found
=
service_intree
(
&
src
,
svname
,
tname
)
;
if
(
!
set_ownersysdir_stack
(
base
,
getuid
()))
if
(
found
==
-
1
)
log_dieu
(
LOG_EXIT_SYS
,
"resolve tree source of sv: "
,
svname
)
;
log_dieu
(
LOG_EXIT_SYS
,
"set owner directory"
)
;
else
if
(
!
found
)
{
log_info
(
"no tree exist yet"
)
;
goto
freed
;
}
else
if
(
found
>
2
)
{
log_die
(
LOG_EXIT_SYS
,
svname
,
" is set on different tree -- please use -t options"
)
;
}
else
if
(
found
==
1
)
log_die
(
LOG_EXIT_SYS
,
"unknown service: "
,
svname
)
;
if
(
!
resolve_read
(
wres
,
src
.
s
,
svname
))
log_dieusys
(
111
,
"read resolve file of: "
,
src
.
s
,
"/.resolve/"
,
svname
)
;
found
=
service_is_g
(
atree
,
svname
,
STATE_FLAGS_ISPARSED
)
;
if
(
found
==
-
1
)
log_dieusys
(
LOG_EXIT_SYS
,
"get information of service: "
,
svname
,
" -- please a bug report"
)
;
else
if
(
!
found
)
log_die
(
LOG_EXIT_USER
,
"unknown service: "
,
svname
)
;
info_field_align
(
buf
,
fields
,
field_suffix
,
MAXOPTS
)
;
info_field_align
(
buf
,
fields
,
field_suffix
,
MAXOPTS
)
;
ste
=
res
.
sa
.
s
+
res
.
state
;
if
(
!
state_check
(
base
,
svname
))
log_diesys
(
111
,
"unitialized service: "
,
svname
)
;
if
(
!
state_read
(
&
sta
,
base
,
svname
))
log_dieusys
(
111
,
"read state file of: "
,
ste
,
"/"
,
svname
)
;
if
(
!
state_check
(
ste
,
svname
))
log_diesys
(
111
,
"unitialized service: "
,
svname
)
;
if
(
!
state_read
(
&
sta
,
ste
,
svname
))
log_dieusys
(
111
,
"read state file of: "
,
ste
,
"/"
,
svname
)
;
info_display_string
(
fields
[
5
],
svname
)
;
info_display_int
(
fields
[
0
],
sta
.
toinit
)
;
info_display_int
(
fields
[
0
],
sta
.
reload
)
;
info_display_int
(
fields
[
1
],
sta
.
toreload
)
;
info_display_int
(
fields
[
1
],
sta
.
init
)
;
info_display_int
(
fields
[
2
],
sta
.
torestart
)
;
info_display_int
(
fields
[
2
],
sta
.
unsupervise
)
;
info_display_int
(
fields
[
3
],
sta
.
tounsupervise
)
;
info_display_int
(
fields
[
3
],
sta
.
state
)
;
info_display_int
(
fields
[
4
],
sta
.
isdownfile
)
;
info_display_int
(
fields
[
4
],
sta
.
pid
)
;
info_display_int
(
fields
[
5
],
sta
.
isearlier
)
;
info_display_int
(
fields
[
6
],
sta
.
isenabled
)
;
info_display_int
(
fields
[
7
],
sta
.
isparsed
)
;
info_display_int
(
fields
[
8
],
sta
.
issupervised
)
;
info_display_int
(
fields
[
9
],
sta
.
isup
)
;
if
(
res
.
logger
&&
logger
)
{
svname
=
res
.
sa
.
s
+
res
.
logger
;
if
(
!
state_check
(
ste
,
svname
))
log_dieusys
(
111
,
"unitialized: "
,
svname
)
;
if
(
!
state_read
(
&
sta
,
ste
,
svname
))
log_dieusys
(
111
,
"read state file of: "
,
ste
,
"/"
,
svname
)
;
if
(
buffer_putsflush
(
buffer_1
,
"
\n
"
)
==
-
1
)
log_dieusys
(
LOG_EXIT_SYS
,
"write to stdout"
)
;
info_display_string
(
fields
[
6
],
res
.
sa
.
s
+
res
.
logreal
)
;
info_display_int
(
fields
[
0
],
sta
.
reload
)
;
info_display_int
(
fields
[
1
],
sta
.
init
)
;
info_display_int
(
fields
[
2
],
sta
.
unsupervise
)
;
info_display_int
(
fields
[
3
],
sta
.
state
)
;
info_display_int
(
fields
[
4
],
sta
.
pid
)
;
}
freed:
resolve_free
(
wres
)
;
resolve_free
(
wres
)
;
stralloc_free
(
&
satree
)
;
stralloc_free
(
&
src
)
;
stralloc_free
(
&
tmp
)
;
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment