This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git
The following commit(s) were added to refs/heads/master by this push:
new f361cf1 Fix jsvc compilation warnings
f361cf1 is described below
commit f361cf1513db5af8d79bc7ab80723ee9a5436328
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Dec 1 08:25:14 2025 +0000
Fix jsvc compilation warnings
---
src/changes/changes.xml | 13 ++++----
src/native/unix/native/jsvc-unix.c | 61 ++++++++++++++++++++++++++++++--------
2 files changed, 57 insertions(+), 17 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9232030..772eaa3 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -40,16 +40,19 @@
<title>Apache Commons Daemon Release Notes</title>
</properties>
<body>
+ <release version="1.5.1" date="TBD" description="Bug fix release">
+ <action type="fix" dev="markt">jsvc. Fix compilation warnings.</action>
+ </release>
<release version="1.5.0" date="2025-11-26" description="This is a
maintenance release. Java 8 or later is required.">
<!-- FIX -->
<action type="fix" dev="ggregory" due-to="Gary Gregory">Remove -nouses
directive from maven-bundle-plugin. OSGi package imports now state 'uses'
definitions for package imports, this doesn't affect JPMS (from
org.apache.commons:commons-parent:80).</action>
<action type="fix" dev="michaelo">Document --enable-preview</action>
<action type="fix" dev="michaelo">Fix first appearance of
--enable-native-access</action>
- <action type="fix" issue="DAEMON-398" dev="jfclere">Fix redirection
issues on some OS versions by using recommended method to redirect stdout and
stderr</action>
- <action type="fix" issue="DAEMON-439" dev="markt">Fix updating of
startup mode to 'Automatic (delayed)' being incorrectly processed as an update
to 'Manual'</action>
- <action type="fix" issue="DAEMON-468" dev="ggregory"
due-to="Jean-Frederic Clere, Mark Thomas, Sebb, Gary Gregory">Fix timeout
handling in procrun #238.</action>
- <action type="fix" issue="DAEMON-472" dev="markt">Replace RTF version of
license header with plain text version of full license in about box for Procrun
monitor application.</action>
- <action type="fix" issue="DAEMON-475" dev="markt">Service should be
marked as stopped if the service worker crashes.</action>
+ <action type="fix" issue="DAEMON-398" dev="jfclere">Procrun. Fix
redirection issues on some OS versions by using recommended method to redirect
stdout and stderr</action>
+ <action type="fix" issue="DAEMON-439" dev="markt">Procrun. Fix updating
of startup mode to 'Automatic (delayed)' being incorrectly processed as an
update to 'Manual'</action>
+ <action type="fix" issue="DAEMON-468" dev="ggregory"
due-to="Jean-Frederic Clere, Mark Thomas, Sebb, Gary Gregory">Procrun. Fix
timeout handling #238.</action>
+ <action type="fix" issue="DAEMON-472" dev="markt">Procrun. Replace RTF
version of license header with plain text version of full license in about box
for monitor application.</action>
+ <action type="fix" issue="DAEMON-475" dev="markt">Procrun. Service
should be marked as stopped if the service worker crashes.</action>
<!-- ADD -->
<action type="add" dev="michaelo" issue="DAEMON-471">Add support for
--enable-native-access Java startup option in jsvc.</action>
<action type="add" dev="ggregory" due-to="Jean-Frederic Clere, Gary
Gregory, Mark Thomas">Add tests for prunsrv on Windows #260.</action>
diff --git a/src/native/unix/native/jsvc-unix.c
b/src/native/unix/native/jsvc-unix.c
index 5dfd016..a289b53 100644
--- a/src/native/unix/native/jsvc-unix.c
+++ b/src/native/unix/native/jsvc-unix.c
@@ -589,14 +589,21 @@ retry:
return -1;
}
else {
- lockf(fd, F_LOCK, 0);
+ if (lockf(fd, F_LOCK, 0)) {
+ log_error("check_pid: Failed to lock PID file [%s] with file
descriptor [%d] for reading due to [%d]",
+ args->pidf, fd, errno);
+ return -1;
+ }
i = read(fd, buff, sizeof(buff));
if (i > 0) {
buff[i] = '\0';
pid = atoi(buff);
if (kill(pid, 0) == 0) {
log_error("Still running according to PID file %s, PID is %d",
args->pidf, pid);
- lockf(fd, F_ULOCK, 0);
+ if (lockf(fd, F_ULOCK, 0)) {
+ log_error("check_pid: Failed to unlock PID file [%s] with
file descriptor [%d] after reading due to [%d]",
+ args->pidf, fd, errno);
+ }
close(fd);
return 122;
}
@@ -606,7 +613,10 @@ retry:
fprintf(pidf, "%d\n", (int)getpid());
fflush(pidf);
fclose(pidf);
- lockf(fd, F_ULOCK, 0);
+ if (lockf(fd, F_ULOCK, 0)) {
+ log_error("check_pid: Failed to unlock PID file [%s] with file
descriptor [%d] after reading due to [%d]",
+ args->pidf, fd, errno);
+ }
close(fd);
}
return 0;
@@ -625,7 +635,11 @@ static void remove_pid_file(arg_data *args, int pidn)
if (fd < 0) {
return;
}
- lockf(fd, F_LOCK, 0);
+ if (lockf(fd, F_LOCK, 0)) {
+ log_error("remove_pid_file: Failed to lock PID file [%s] with file
descriptor [%d] for reading due to [%d]",
+ args->pidf, fd, errno);
+ return;
+ }
i = read(fd, buff, sizeof(buff));
if (i > 0) {
buff[i] = '\0';
@@ -643,7 +657,10 @@ static void remove_pid_file(arg_data *args, int pidn)
("remove_pid_file: pid changed (%d->%d), not removing pid file %s",
pidn, pid, args->pidf);
}
- lockf(fd, F_ULOCK, 0);
+ if (lockf(fd, F_ULOCK, 0)) {
+ log_error("remove_pid_file: Failed to unlock PID file [%s] with file
descriptor [%d] after reading due to [%d]",
+ args->pidf, fd, errno);
+ }
close(fd);
}
@@ -663,9 +680,16 @@ static int get_pidf(arg_data *args, bool quiet)
/* something has gone wrong the JVM has stopped */
return -1;
}
- lockf(fd, F_LOCK, 0);
+ if (lockf(fd, F_LOCK, 0)) {
+ log_error("get_pidf: Failed to lock PID file [%s] with file descriptor
[%d] for reading due to [%d]",
+ args->pidf, fd, errno);
+ return -1;
+ }
i = read(fd, buff, sizeof(buff));
- lockf(fd, F_ULOCK, 0);
+ if (lockf(fd, F_ULOCK, 0)) {
+ log_error("get_pidf: Failed to unlock PID file [%s] with file
descriptor [%d] after reading due to [%d]",
+ args->pidf, fd, errno);
+ }
close(fd);
if (i > 0) {
buff[i] = '\0';
@@ -759,9 +783,16 @@ static int wait_child(arg_data *args, int pid)
/* something has gone wrong the JVM has stopped */
return 1;
}
- lockf(fd, F_LOCK, 0);
+ if (lockf(fd, F_LOCK, 0)) {
+ log_error("wait_child: Failed to lock PID file [%s] with file
descriptor [%d] for reading due to [%d]",
+ args->pidf, fd, errno);
+ return 1;
+ }
i = read(fd, buff, sizeof(buff));
- lockf(fd, F_ULOCK, 0);
+ if (lockf(fd, F_ULOCK, 0)) {
+ log_error("wait_child: Failed to unlock PID file [%s] with file
descriptor [%d] after reading due to [%d]",
+ args->pidf, fd, errno);
+ }
close(fd);
if (i > 0) {
buff[i] = '\0';
@@ -1061,7 +1092,9 @@ static void set_output(char *outfile, char *errfile, bool
redirectstdin, char *p
int fork_needed = 0;
if (redirectstdin == true) {
- freopen("/dev/null", "r", stdin);
+ if (freopen("/dev/null", "r", stdin) == NULL) {
+ log_error("Failed to redirect stdin to /dev/null due to [%d]",
errno);
+ }
}
log_debug("redirecting stdout to %s and stderr to %s", outfile, errfile);
@@ -1072,7 +1105,9 @@ static void set_output(char *outfile, char *errfile, bool
redirectstdin, char *p
if (strcmp(outfile, "&1") == 0 && strcmp(errfile, "&2") == 0)
return;
if (strcmp(outfile, "SYSLOG") == 0) {
- freopen("/dev/null", "a", stdout);
+ if (freopen("/dev/null", "a", stdout) == NULL) {
+ log_error("Failed to redirect stdout to /dev/null due to [%d]",
errno);
+ }
/* Send stdout to syslog through a logger process */
if (pipe(out_pipe) == -1) {
log_error("cannot create stdout pipe: %s", strerror(errno));
@@ -1090,7 +1125,9 @@ static void set_output(char *outfile, char *errfile, bool
redirectstdin, char *p
}
if (strcmp(errfile, "SYSLOG") == 0) {
- freopen("/dev/null", "a", stderr);
+ if (freopen("/dev/null", "a", stderr) == NULL) {
+ log_error("Failed to redirect stderr to /dev/null due to [%d]",
errno);
+ }
/* Send stderr to syslog through a logger process */
if (pipe(err_pipe) == -1) {
log_error("cannot create stderr pipe: %s", strerror(errno));