Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
System Manager
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
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
system
System Manager
Commits
6459edcb
Commit
6459edcb
authored
5 months ago
by
Vivek Dutta
Browse files
Options
Downloads
Patches
Plain Diff
Added validator for reset_reason file
parent
3a14fde2
Branches
Branches containing commit
No related tags found
1 merge request
!14
Added validator for reset_reason file
Pipeline
#186980
passed
5 months ago
Stage: static_code_analysis
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/reboots.c
+34
-8
34 additions, 8 deletions
src/reboots.c
with
34 additions
and
8 deletions
src/reboots.c
+
34
−
8
View file @
6459edcb
...
@@ -20,9 +20,9 @@
...
@@ -20,9 +20,9 @@
#include
<unistd.h>
#include
<unistd.h>
#define REBOOT_LOCK_FILE "/tmp/bbf_reboot_handler.lock" // Lock file indicating that the boot action has already been executed
#define REBOOT_LOCK_FILE "/tmp/bbf_reboot_handler.lock" // Lock file indicating that the boot action has already been executed
#define RESET_REASON_PATH "/
tmp
/reset_reason" // Path to the file containing the reason for the most recent boot/reset
#define RESET_REASON_PATH "/
var
/reset_reason" // Path to the file containing the reason for the most recent boot/reset
#define REBOOT_MAX_RETRIES 1
0
// Maximum number of retries for checking if RESET_REASON_PATH has been generated
#define REBOOT_MAX_RETRIES 1
5
// Maximum number of retries for checking if RESET_REASON_PATH has been generated
#define REBOOT_RETRY_DELAY
2
// Delay in seconds between retries when checking for the existence of RESET_REASON_PATH
#define REBOOT_RETRY_DELAY
3
// Delay in seconds between retries when checking for the existence of RESET_REASON_PATH
#define REBOOT_MAX_ENTRIES 32 // Maximum number of reboot entries to display in Device.DeviceInfo.Reboots.Reboot.{i}
#define REBOOT_MAX_ENTRIES 32 // Maximum number of reboot entries to display in Device.DeviceInfo.Reboots.Reboot.{i}
static
int
g_retry_count
=
0
;
static
int
g_retry_count
=
0
;
...
@@ -59,6 +59,7 @@ static void get_boot_option_value(const char *option_name, char *buffer, size_t
...
@@ -59,6 +59,7 @@ static void get_boot_option_value(const char *option_name, char *buffer, size_t
while
(
fgets
(
line
,
sizeof
(
line
),
file
))
{
while
(
fgets
(
line
,
sizeof
(
line
),
file
))
{
remove_new_line
(
line
);
remove_new_line
(
line
);
strip_lead_trail_whitespace
(
line
);
if
(
strstr
(
line
,
option_name
))
{
if
(
strstr
(
line
,
option_name
))
{
char
*
p
=
strchr
(
line
,
':'
);
char
*
p
=
strchr
(
line
,
':'
);
...
@@ -195,7 +196,7 @@ static void create_reboot_section(const char *trigger, const char *reason)
...
@@ -195,7 +196,7 @@ static void create_reboot_section(const char *trigger, const char *reason)
static
void
sysmngr_register_boot_action
(
void
)
static
void
sysmngr_register_boot_action
(
void
)
{
{
char
trigger
[
16
]
=
{
0
},
reason
[
16
]
=
{
0
},
max_entries
[
16
]
=
{
0
};
char
trigger
[
32
]
=
{
0
},
reason
[
32
]
=
{
0
},
max_entries
[
16
]
=
{
0
};
// Check if boot action was already executed
// Check if boot action was already executed
if
(
file_exists
(
REBOOT_LOCK_FILE
))
{
if
(
file_exists
(
REBOOT_LOCK_FILE
))
{
...
@@ -206,6 +207,7 @@ static void sysmngr_register_boot_action(void)
...
@@ -206,6 +207,7 @@ static void sysmngr_register_boot_action(void)
get_boot_option_value
(
"triggered"
,
trigger
,
sizeof
(
trigger
));
get_boot_option_value
(
"triggered"
,
trigger
,
sizeof
(
trigger
));
get_boot_option_value
(
"reason"
,
reason
,
sizeof
(
reason
));
get_boot_option_value
(
"reason"
,
reason
,
sizeof
(
reason
));
BBF_DEBUG
(
"RESET triggered[%s], reason[%s] ..."
,
trigger
,
reason
);
if
(
strcmp
(
trigger
,
"defaultreset"
)
==
0
)
{
if
(
strcmp
(
trigger
,
"defaultreset"
)
==
0
)
{
reset_option_counter
(
"boot_count"
,
"1"
);
reset_option_counter
(
"boot_count"
,
"1"
);
reset_option_counter
(
"curr_version_boot_count"
,
"0"
);
reset_option_counter
(
"curr_version_boot_count"
,
"0"
);
...
@@ -236,6 +238,25 @@ static void sysmngr_register_boot_action(void)
...
@@ -236,6 +238,25 @@ static void sysmngr_register_boot_action(void)
create_empty_file
(
REBOOT_LOCK_FILE
);
create_empty_file
(
REBOOT_LOCK_FILE
);
}
}
bool
check_valid_reset_reason_file
(
void
)
{
bool
ret
=
false
;
char
reason
[
32
]
=
{
0
};
if
(
file_exists
(
RESET_REASON_PATH
)
==
false
)
{
return
ret
;
}
get_boot_option_value
(
"reason"
,
reason
,
sizeof
(
reason
));
// able to read the reason
if
(
strlen
(
reason
)
!=
0
)
{
ret
=
true
;
}
return
ret
;
}
static
void
reboot_check_timer
(
struct
uloop_timeout
*
timeout
)
static
void
reboot_check_timer
(
struct
uloop_timeout
*
timeout
)
{
{
sysmngr_reboots_init
();
sysmngr_reboots_init
();
...
@@ -248,8 +269,13 @@ static struct uloop_timeout reboot_timer = { .cb = reboot_check_timer };
...
@@ -248,8 +269,13 @@ static struct uloop_timeout reboot_timer = { .cb = reboot_check_timer };
**************************************************************/
**************************************************************/
void
sysmngr_reboots_init
(
void
)
void
sysmngr_reboots_init
(
void
)
{
{
if
(
file_exists
(
RESET_REASON_PATH
))
{
if
(
file_exists
(
REBOOT_LOCK_FILE
))
{
BBF_INFO
(
"Reset reason file '%s' found. Proceeding to register boot action"
,
RESET_REASON_PATH
);
BBF_INFO
(
"Boot action already completed previously. Skipping registration."
);
return
;
}
if
(
check_valid_reset_reason_file
()
==
true
)
{
BBF_INFO
(
"Valid reset reason file '%s' found. Proceeding to register boot action"
,
RESET_REASON_PATH
);
sysmngr_register_boot_action
();
sysmngr_register_boot_action
();
return
;
return
;
}
}
...
@@ -258,10 +284,10 @@ void sysmngr_reboots_init(void)
...
@@ -258,10 +284,10 @@ void sysmngr_reboots_init(void)
g_retry_count
++
;
g_retry_count
++
;
uloop_timeout_set
(
&
reboot_timer
,
REBOOT_RETRY_DELAY
*
1000
);
uloop_timeout_set
(
&
reboot_timer
,
REBOOT_RETRY_DELAY
*
1000
);
BBF_WARNING
(
"Attempt %d/%d: Reset reason file '%s' not found. Retrying in %d second(s)..."
,
BBF_WARNING
(
"
##
Attempt %d/%d: Reset reason file '%s' not found. Retrying in %d second(s)..."
,
g_retry_count
,
REBOOT_MAX_RETRIES
,
RESET_REASON_PATH
,
REBOOT_RETRY_DELAY
);
g_retry_count
,
REBOOT_MAX_RETRIES
,
RESET_REASON_PATH
,
REBOOT_RETRY_DELAY
);
}
else
{
}
else
{
BBF_
ERR
(
"Max retries reached (%d).
R
eset reason file '%s' not found. Proceeding with boot action registration"
,
BBF_
WARNING
(
"Max retries reached (%d).
A valid r
eset reason file '%s' not found. Proceeding with boot action registration"
,
REBOOT_MAX_RETRIES
,
RESET_REASON_PATH
);
REBOOT_MAX_RETRIES
,
RESET_REASON_PATH
);
sysmngr_register_boot_action
();
sysmngr_register_boot_action
();
}
}
...
...
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