1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
backport 2/2 from https://gitlab.xiph.org/xiph/vorbis-tools/-/merge_requests/27.patch
From cfc497a442f51fb4885e132deaf2e0ba067bd280 Mon Sep 17 00:00:00 2001
From: "Timothy B. Terriberry" <tterribe@xiph.org>
Date: Tue, 24 Jun 2025 09:38:56 -0700
Subject: [PATCH 2/2] ogg123: Handle EOF/error in remote interface
Previously, if there was an error or EOF reading commands for the
remote interface, the reader would loop infinitely trying to read
another command that will never come.
Instead, treat error or EOF as a Quit command.
We manually send an error message / log, instead of using the
existing error path, because we still want the main thread to
process the Quit.
--- a/ogg123/remote.c
+++ b/ogg123/remote.c
@@ -139,6 +139,7 @@ static void * remotethread(void * arg) {
buf[MAXBUF]=0;
while(!done) {
+ char *ret;
/* Read a line */
buf[0] = 0;
send_log("Waiting for input: ...");
@@ -149,77 +150,86 @@ static void * remotethread(void * arg) {
select (1, &fd, NULL, NULL, NULL);
#endif
- fgets(buf, MAXBUF, stdin);
- buf[strcspn(buf, "\n")] = 0;
+ ret = fgets(buf, MAXBUF, stdin);
/* Lock on */
pthread_mutex_lock (&main_lock);
- send_log("Input: %s", buf);
- error = 0;
-
- if (!strncasecmp(buf,"l",1)) {
- /* prepare to load */
- if ((b=strchr(buf,' ')) != NULL) {
- /* Prepare to load a new song */
- strcpy((char*)arg, b+1);
+ if (ret != NULL) {
+ buf[strcspn(buf, "\n")] = 0;
+ send_log("Input: %s", buf);
+ error = 0;
+
+ if (!strncasecmp(buf,"l",1)) {
+ /* prepare to load */
+ if ((b=strchr(buf,' ')) != NULL) {
+ /* Prepare to load a new song */
+ strcpy((char*)arg, b+1);
+ setstatus(NEXT);
+ }
+ else {
+ /* Invalid load command */
+ error = 1;
+ }
+ }
+ else
+ if (!strncasecmp(buf,"p",1)) {
+ /* Prepare to (un)pause */
+ invertpause();
+ }
+ else
+ if (!strncasecmp(buf,"j",1)) {
+ /* Prepare to seek */
+ if ((b=strchr(buf,' ')) != NULL) {
+ set_seek_opt(&options, b+1);
+ }
+ ignore = 1;
+ }
+ else
+ if (!strncasecmp(buf,"s",1)) {
+ /* Prepare to stop */
+ setstatus(STOP);
+ }
+ else
+ if (!strncasecmp(buf,"r",1)) {
+ /* Prepare to reload */
setstatus(NEXT);
- }
+ }
+ else
+ if (!strncasecmp(buf,"h",1)) {
+ /* Send help */
+ send_msg("H +----------------------------------------------------+");
+ send_msg("H | Ogg123 remote interface |");
+ send_msg("H |----------------------------------------------------|");
+ send_msg("H | Load <file> - load a file and starts playing |");
+ send_msg("H | Pause - pause or unpause playing |");
+ send_msg("H | Jump [+|-]<f> - jump <f> seconds forth or back |");
+ send_msg("H | Stop - stop playing |");
+ send_msg("H | Reload - reload last song |");
+ send_msg("H | Quit - quit ogg123 |");
+ send_msg("H |----------------------------------------------------|");
+ send_msg("H | refer to README.remote for documentation |");
+ send_msg("H +----------------------------------------------------+");
+ ignore = 1;
+ }
+ else
+ if (!strncasecmp(buf,"q",1)) {
+ /* Prepare to quit */
+ setstatus(QUIT);
+ done = 1;
+ }
else {
- /* Invalid load command */
+ /* Unknown input received */
error = 1;
}
}
- else
- if (!strncasecmp(buf,"p",1)) {
- /* Prepare to (un)pause */
- invertpause();
- }
- else
- if (!strncasecmp(buf,"j",1)) {
- /* Prepare to seek */
- if ((b=strchr(buf,' ')) != NULL) {
- set_seek_opt(&options, b+1);
- }
- ignore = 1;
- }
- else
- if (!strncasecmp(buf,"s",1)) {
- /* Prepare to stop */
- setstatus(STOP);
- }
- else
- if (!strncasecmp(buf,"r",1)) {
- /* Prepare to reload */
- setstatus(NEXT);
- }
- else
- if (!strncasecmp(buf,"h",1)) {
- /* Send help */
- send_msg("H +----------------------------------------------------+");
- send_msg("H | Ogg123 remote interface |");
- send_msg("H |----------------------------------------------------|");
- send_msg("H | Load <file> - load a file and starts playing |");
- send_msg("H | Pause - pause or unpause playing |");
- send_msg("H | Jump [+|-]<f> - jump <f> seconds forth or back |");
- send_msg("H | Stop - stop playing |");
- send_msg("H | Reload - reload last song |");
- send_msg("H | Quit - quit ogg123 |");
- send_msg("H |----------------------------------------------------|");
- send_msg("H | refer to README.remote for documentation |");
- send_msg("H +----------------------------------------------------+");
- ignore = 1;
- }
- else
- if (!strncasecmp(buf,"q",1)) {
- /* Prepare to quit */
+ else {
+ send_err("E EOF or error reading commands");
+ send_log("EOF or error reading commands");
+ /* Treat EOF or error as a quit command. */
setstatus(QUIT);
done = 1;
}
- else {
- /* Unknown input received */
- error = 1;
- }
if (ignore) {
/* Unlock */
|