Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
openrc-settingsd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
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
postmarketOS
openrc-settingsd
Commits
9804451c
Verified
Commit
9804451c
authored
6 months ago
by
Nathaniel Russell
Committed by
Newbyte
5 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Implement Slackware specific information for rc.ntpd (MR 13)
Closes
#5
parent
1ff05f4f
No related branches found
No related tags found
1 merge request
!13
Implement Slackware specific information for rc.ntpd
Pipeline
#208336
passed
5 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/timedated.c
+70
-24
70 additions, 24 deletions
src/timedated.c
with
70 additions
and
24 deletions
src/timedated.c
+
70
−
24
View file @
9804451c
...
...
@@ -36,6 +36,10 @@
#include
<rc.h>
#endif
#if TIME_STYLE_SLACKWARE
#include
<sys/stat.h>
#endif
#include
"copypaste/hwclock.h"
#include
"timedated.h"
#include
"timedate1-generated.h"
...
...
@@ -186,26 +190,6 @@ set_timezone (const gchar *identifier,
return
TRUE
;
}
#if TIME_STYLE_SLACKWARE
// Function to check if the NTP service is running
bool
ntp_is_running
()
{
FILE
*
fp
=
popen
(
"pgrep ntpd"
,
"r"
);
// Check if the ntpd process is running
if
(
fp
==
NULL
)
{
perror
(
"popen"
);
return
false
;
// Assume NTP is not running if an error occurs
}
char
buf
[
128
];
if
(
fgets
(
buf
,
sizeof
(
buf
),
fp
)
!=
NULL
)
{
pclose
(
fp
);
return
true
;
// NTP process found, so it is running
}
pclose
(
fp
);
return
false
;
// NTP process not found, so it is not running
}
#endif
/* Return the ntp rc service we will use; return value should NOT be freed */
static
const
gchar
*
ntp_service
()
...
...
@@ -233,11 +217,22 @@ ntp_service ()
return
service
;
#elif TIME_STYLE_SLACKWARE
// Check if NTP service is already running
// Add your logic here to check if the NTP program is running
if
(
ntp_is_running
())
{
return
"ntpd"
;
// Assuming "ntp" is the default service name when NTP is running
const
char
*
rc_ntpd
=
"/etc/rc.d/rc.ntpd"
;
const
char
*
ntpd_conf
=
"/etc/ntp.conf"
;
// Assuming this is the path for NTP configuration
struct
stat
st_ntpd
,
st_ntpd_conf
;
if
(
stat
(
rc_ntpd
,
&
st_ntpd
)
==
0
&&
(
st_ntpd
.
st_mode
&
S_IFMT
)
==
S_IFREG
&&
stat
(
ntpd_conf
,
&
st_ntpd_conf
)
==
0
&&
(
st_ntpd_conf
.
st_mode
&
S_IFMT
)
==
S_IFREG
)
{
if
((
st_ntpd
.
st_mode
&
(
S_IRWXU
|
S_IRWXG
|
S_IRWXO
))
==
0755
)
{
g_debug
(
"Starting ntpd: rc.ntpd has appropriate permissions (0755)."
);
return
"ntpd"
;
}
else
if
((
st_ntpd
.
st_mode
&
(
S_IRWXU
|
S_IRWXG
|
S_IRWXO
))
==
0644
)
{
g_debug
(
"Unable to start ntpd: rc.ntpd has insufficient permissions (0644)."
);
return
NULL
;
}
}
g_warning
(
"Unable to start ntpd: rc.ntpd is not a regular file or does not exist."
);
return
NULL
;
#else
return
NULL
;
...
...
@@ -260,6 +255,31 @@ service_started (const gchar *service,
state
=
rc_service_state
(
service
);
return
state
==
RC_SERVICE_STARTED
||
state
==
RC_SERVICE_STARTING
||
state
==
RC_SERVICE_INACTIVE
;
#elif TIME_STYLE_SLACKWARE
const
char
*
rc_ntpd
=
"/etc/rc.d/rc.ntpd"
;
struct
stat
st
;
// Check the file status
if
(
stat
(
rc_ntpd
,
&
st
)
==
0
)
{
// Check if it's a regular file and permissions are 755
if
((
st
.
st_mode
&
S_IFMT
)
==
S_IFREG
&&
(
st
.
st_mode
&
(
S_IRWXU
|
S_IRWXG
|
S_IRWXO
))
==
0755
)
{
// Check the NTP daemon status
int
ret
=
system
(
"/etc/rc.d/rc.ntpd status"
);
if
(
ret
==
0
)
{
return
TRUE
;
// NTP daemon is running
}
else
{
// Attempt to start the NTP daemon if not running
gchar
*
cmd
=
g_strconcat
(
"/etc/rc.d/rc.ntpd start"
,
NULL
);
ret
=
system
(
cmd
);
g_free
(
cmd
);
return
(
ret
==
0
);
// Return TRUE if start command succeeds
}
}
else
{
g_debug
(
"Unable to start ntpd: rc.ntpd has insufficient permissions (not 755)."
);
}
}
return
FALSE
;
#else
return
FALSE
;
#endif
...
...
@@ -313,6 +333,18 @@ service_disable (const gchar *service,
if
(
service_script
!=
NULL
)
free
(
service_script
);
return
ret
;
#elif TIME_STYLE_SLACKWARE
int
stop_ret
=
system
(
"/etc/rc.d/rc.ntpd stop"
);
if
(
stop_ret
!=
0
)
{
g_set_error
(
error
,
G_IO_ERROR
,
G_IO_ERROR_FAILED
,
"Failed to stop NTP service with /etc/rc.d/rc.ntpd."
);
return
FALSE
;
}
else
{
use_ntp
=
FALSE
;
if
(
timedate1
!=
NULL
)
{
openrc_settingsd_timedated_timedate1_set_ntp
(
timedate1
,
use_ntp
);
}
return
TRUE
;
}
#else
return
FALSE
;
#endif
...
...
@@ -366,6 +398,20 @@ service_enable (const gchar *service,
if
(
service_script
!=
NULL
)
free
(
service_script
);
return
ret
;
#elif TIME_STYLE_SLACKWARE
int
ret
=
system
(
"/etc/rc.d/rc.ntpd start"
);
if
(
ret
==
0
)
{
use_ntp
=
TRUE
;
}
else
{
g_set_error
(
error
,
G_IO_ERROR
,
G_IO_ERROR_FAILED
,
"Failed to start NTP service with /etc/rc.d/rc.ntpd."
);
return
FALSE
;
}
if
(
timedate1
!=
NULL
)
{
openrc_settingsd_timedated_timedate1_set_ntp
(
timedate1
,
use_ntp
);
}
return
TRUE
;
#else
return
FALSE
;
#endif
...
...
This diff is collapsed.
Click to expand it.
Newbyte
@Newbyte
mentioned in issue
#5 (closed)
·
5 months ago
mentioned in issue
#5 (closed)
mentioned in issue #5
Toggle commit list
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