Skip to content

Commit f362e89

Browse files
alexdupremichael-o
authored andcommitted
jsvc: Fix regression around invalid lockf(3) semantics
lock(3) mandates that the passed file descriptor must be in O_RDWR or O_WRONLY mode. This was caused by f361cf1. Downstream bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=291822
1 parent 27035d3 commit f362e89

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/changes/changes.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
<title>Apache Commons Daemon Release Notes</title>
4141
</properties>
4242
<body>
43+
<release version="1.5.2" date="TBD" description="Bug fix release">
44+
<!-- FIX -->
45+
<action type="fix" dev="michaelo">jsvc. Fix regression around invalid lockf(3) semantics.</action>
46+
<!-- ADD -->
47+
<!-- UPDATE -->
48+
</release>
4349
<release version="1.5.1" date="2025-12-16" description="Bug fix release">
4450
<!-- FIX -->
4551
<action type="fix" dev="markt">jsvc. Fix compilation warnings.</action>

src/native/unix/native/jsvc-unix.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ static int mkdir2(const char *name, int perms)
566566
static int check_pid(arg_data *args)
567567
{
568568
int fd;
569-
FILE *pidf;
570569
char buff[80];
571570
pid_t pidn = getpid();
572571
int i, pid;
@@ -608,11 +607,11 @@ static int check_pid(arg_data *args)
608607
return 122;
609608
}
610609
}
611-
lseek(fd, SEEK_SET, 0);
612-
pidf = fdopen(fd, "r+");
613-
fprintf(pidf, "%d\n", (int)getpid());
614-
fflush(pidf);
615-
fclose(pidf);
610+
i = snprintf(buff, sizeof(buff), "%d\n", (int)getpid());
611+
lseek(fd, 0, SEEK_SET);
612+
ftruncate(fd, 0);
613+
write(fd, buff, i);
614+
fsync(fd);
616615
if (lockf(fd, F_ULOCK, 0)) {
617616
log_error("check_pid: Failed to unlock PID file [%s] with file descriptor [%d] after reading due to [%d]",
618617
args->pidf, fd, errno);
@@ -673,7 +672,7 @@ static int get_pidf(arg_data *args, bool quiet)
673672
int i;
674673
char buff[80];
675674

676-
fd = open(args->pidf, O_RDONLY, 0);
675+
fd = open(args->pidf, O_RDWR, 0);
677676
if (!quiet)
678677
log_debug("get_pidf: %d in %s", fd, args->pidf);
679678
if (fd < 0) {
@@ -778,7 +777,7 @@ static int wait_child(arg_data *args, int pid)
778777
}
779778

780779
/* check if the pid file process exists */
781-
fd = open(args->pidf, O_RDONLY);
780+
fd = open(args->pidf, O_RDWR);
782781
if (fd < 0 && havejvm) {
783782
/* something has gone wrong the JVM has stopped */
784783
return 1;

0 commit comments

Comments
 (0)