Skip to content

Commit e5aac67

Browse files
committed
Fixes
- fix opening the pipes - fix build for amd cpu's
1 parent 57c0ea8 commit e5aac67

File tree

2 files changed

+81
-12
lines changed

2 files changed

+81
-12
lines changed

.github/workflows/build.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,32 @@ jobs:
3838
if [ "${{ matrix.os-arch }}" = "aarch64" ]; then
3939
export CC=aarch64-linux-gnu-gcc
4040
export CXX=aarch64-linux-gnu-g++
41+
# Ensure standard libraries are statically linked
42+
export LDFLAGS="-static-libgcc -static-libstdc++"
4143
else
4244
export CC=x86_64-linux-gnu-gcc
4345
export CXX=x86_64-linux-gnu-g++
44-
export CFLAGS="-march=x86-64"
45-
export CXXFLAGS="-march=x86-64"
46+
# Use baseline x86-64 with generic tuning for maximum compatibility
47+
# -static-libgcc -static-libstdc++ ensure stdlib is statically linked
48+
export CFLAGS="-march=x86-64 -mtune=generic"
49+
export CXXFLAGS="-march=x86-64 -mtune=generic"
50+
export LDFLAGS="-static-libgcc -static-libstdc++"
4651
fi
4752
make HOST=linux PLATFORM=${{ matrix.os-arch }} STATIC=1 -j$(nproc)
4853
chmod +x bin/cliraop-linux-${{ matrix.os-arch }}
4954
cp bin/cliraop-linux-${{ matrix.os-arch }} release/
5055
56+
- name: Verify binary
57+
run: |
58+
echo "Binary info:"
59+
file bin/cliraop-linux-${{ matrix.os-arch }}
60+
echo ""
61+
echo "Dynamic dependencies:"
62+
ldd bin/cliraop-linux-${{ matrix.os-arch }} || echo "Static binary (no dependencies)"
63+
echo ""
64+
echo "Size:"
65+
ls -lh bin/cliraop-linux-${{ matrix.os-arch }}
66+
5167
- name: Upload artifacts
5268
uses: actions/upload-artifact@v4
5369
with:

src/cliraop.c

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,19 @@ static void close_platform()
148148
/*----------------------------------------------------------------------------*/
149149
static void *CmdPipeReaderThread(void *args)
150150
{
151-
cmdPipeFd = open(cmdPipeName, O_RDONLY);
151+
// Open with O_NONBLOCK to avoid blocking if no writer is present
152+
cmdPipeFd = open(cmdPipeName, O_RDONLY | O_NONBLOCK);
153+
if (cmdPipeFd == -1)
154+
{
155+
LOG_ERROR("Failed to open command pipe: %s", cmdPipeName);
156+
return NULL;
157+
}
158+
159+
// Set back to blocking mode after opening
160+
int file_flags = fcntl(cmdPipeFd, F_GETFL);
161+
fcntl(cmdPipeFd, F_SETFL, file_flags & ~O_NONBLOCK);
162+
LOG_INFO("Command pipe opened successfully");
163+
152164
struct
153165
{
154166
char *title;
@@ -164,7 +176,9 @@ static void *CmdPipeReaderThread(void *args)
164176
if (!glMainRunning)
165177
break;
166178

167-
if (read(cmdPipeFd, cmdPipeBuf, 512) > 0)
179+
ssize_t bytes_read = read(cmdPipeFd, cmdPipeBuf, 512);
180+
181+
if (bytes_read > 0)
168182
{
169183
// read lines
170184
char *save_ptr1, *save_ptr2;
@@ -296,8 +310,30 @@ static void *CmdPipeReaderThread(void *args)
296310
// clear cmdPipeBuf
297311
memset(cmdPipeBuf, 0, sizeof cmdPipeBuf);
298312
}
313+
else if (bytes_read == 0)
314+
{
315+
// EOF - writer closed the pipe, reopen to wait for next writer
316+
LOG_DEBUG("Command pipe writer disconnected, waiting for reconnection...");
317+
close(cmdPipeFd);
318+
319+
// Reopen with O_NONBLOCK to avoid blocking
320+
cmdPipeFd = open(cmdPipeName, O_RDONLY | O_NONBLOCK);
321+
if (cmdPipeFd == -1)
322+
{
323+
LOG_ERROR("Failed to reopen command pipe: %s", cmdPipeName);
324+
break;
325+
}
326+
327+
// Set back to blocking mode for reads
328+
int file_flags = fcntl(cmdPipeFd, F_GETFL);
329+
fcntl(cmdPipeFd, F_SETFL, file_flags & ~O_NONBLOCK);
330+
331+
// Small delay before trying to read again
332+
usleep(100 * 1000); // 100ms
333+
}
299334
else
300335
{
336+
// Error on read, sleep and retry
301337
usleep(250 * 1000);
302338
}
303339
}
@@ -670,15 +706,13 @@ int main(int argc, char *argv[])
670706

671707
buf = malloc(DEFAULT_FRAMES_PER_CHUNK * 4);
672708
uint32_t KeepAlive = 0;
709+
bool got_eof = false;
673710

674711
// keep reading audio from stdin until exit/EOF
675-
while (n || raopcl_is_playing(raopcl))
712+
while (status != STOPPED && (!got_eof || raopcl_is_playing(raopcl)))
676713
{
677714
uint64_t playtime, now;
678715

679-
if (status == STOPPED)
680-
break;
681-
682716
now = raopcl_get_ntp(NULL);
683717

684718
// execute every second
@@ -701,11 +735,30 @@ int main(int argc, char *argv[])
701735
{
702736
n = read(infile, buf, DEFAULT_FRAMES_PER_CHUNK * 4);
703737

704-
if (!n)
738+
if (n < 0)
705739
{
706-
// EOF or no writer on FIFO yet - sleep to avoid busy-waiting
707-
usleep(10000); // 10ms
708-
continue;
740+
// Error on read
741+
LOG_ERROR("Error reading from audio source");
742+
break;
743+
}
744+
else if (n == 0)
745+
{
746+
// EOF or no writer on FIFO yet
747+
// Check if this is a regular file (true EOF) or FIFO (no writer yet)
748+
struct stat st;
749+
if (fstat(infile, &st) == 0 && S_ISFIFO(st.st_mode))
750+
{
751+
// It's a FIFO - no writer yet, keep waiting
752+
usleep(10000); // 10ms
753+
continue;
754+
}
755+
else
756+
{
757+
// Regular file EOF - mark as done and drain the buffer
758+
LOG_INFO("End of audio file reached, draining buffer...");
759+
got_eof = true;
760+
continue;
761+
}
709762
}
710763

711764
raopcl_send_chunk(raopcl, buf, n / 4, &playtime);

0 commit comments

Comments
 (0)