Skip to content

Commit e012efe

Browse files
committed
feat(supervisor/posix): hide unused functionality from help
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
1 parent ac8b458 commit e012efe

1 file changed

Lines changed: 22 additions & 44 deletions

File tree

  • src/samples/supervisor/posix/server

src/samples/supervisor/posix/server/ocred.c

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ static int usage(const char *argv0)
6363
fprintf(stderr, " -H LISTEN_ADDR Specifies a socket to listen on\n");
6464
fprintf(stderr, " -P PID_FILE Use a PID file (default: " DEFAULT_PID_FILE ")\n");
6565
fprintf(stderr, " -h Display this help message\n");
66-
fprintf(stderr, "\nOption '-H' can be supplied multiple times and take the format:\n");
67-
fprintf(stderr, " fd://SOCKET_PATH UNIX domain socket path\n");
68-
fprintf(stderr, " tcp://HOST:PORT TCP socket path\n");
69-
fprintf(stderr, " fd:// Socket activation mode\n");
66+
fprintf(stderr, "\nOption '-H' can currently be supplied a single time and takes the format:\n");
67+
fprintf(stderr, " SOCKET_PATH UNIX domain socket path\n");
68+
// fprintf(stderr, "\nOption '-H' can be supplied multiple times and take the format:\n");
69+
// fprintf(stderr, " fd://SOCKET_PATH UNIX domain socket path\n");
70+
// fprintf(stderr, " tcp://HOST:PORT TCP socket path\n");
71+
// fprintf(stderr, " fd:// Socket activation mode\n");
7072
return -1;
7173
}
7274

@@ -159,46 +161,17 @@ int main(int argc, char *argv[])
159161
ctrl_path = SOCK_PATH;
160162
}
161163

162-
// if (!workdir) {
163-
// fprintf(stderr, "Using default working directory\n");
164-
// }
165-
166-
// /* Read current PID file */
167-
// int pidfile = open(pid_file, O_RDONLY);
168-
// if (pidfile >= 0) {
169-
// fprintf(stderr, "PID file '%s' already exists. Will check it\n", pid_file);
170-
// char pids[16];
171-
// if (read(pidfile, pids, sizeof(pids)) != sizeof(pids)) {
172-
// fprintf(stderr, "Failed to read PID file '%s'\n", pid_file);
173-
// close(pidfile);
174-
// return -1;
175-
// }
176-
177-
// int pid = atoi(pids);
178-
179-
// if (pid >= 0) {
180-
// fprintf(stderr, "Checking PID %d\n", pid);
181-
// if (waitpid(pid, NULL, WNOHANG) == pid) {
182-
// fprintf(stderr, "Process %d is running\n", pid);
183-
// fprintf(stderr, "Process %d is not running\n", pid);
184-
// } else {
185-
// }
186-
// }
187-
// }
188-
189-
// close(pidfile);
190-
191-
// int rc = cleanup_socket(SOCK_PATH);
192-
// if (rc < 0) {
193-
// fprintf(stderr, "Failed to cleanup socket file\n");
194-
// return 1;
195-
// }
164+
if (ocre_pid_file_manage(pid_file)) {
165+
fprintf(stderr, "Failed to manage PID file '%s'\n", pid_file);
166+
exit(1);
167+
};
196168

197169
int rc = ocre_initialize(NULL);
198170
if (rc < 0) {
199171
fprintf(stderr, "Failed to initialize runtimes\n");
200172
return 1;
201173
}
174+
202175
ctx = ocre_create_context(workdir);
203176
if (!ctx) {
204177
fprintf(stderr, "Failed to create ocre context\n");
@@ -244,7 +217,7 @@ int main(int argc, char *argv[])
244217
exit(1);
245218
}
246219

247-
printf("Ocre daemon started, listening on %s\n", SOCK_PATH);
220+
fprintf(stderr, "Ocre daemon started, listening on %s\n", SOCK_PATH);
248221

249222
for (;;) {
250223

@@ -254,22 +227,27 @@ int main(int argc, char *argv[])
254227
}
255228

256229
int n;
257-
printf("Waiting for a connection...\n");
230+
fprintf(stderr, "Waiting for a connection...\n");
258231
socklen_t slen = sizeof(remote);
259232
if ((s2 = accept(s, (struct sockaddr *)&remote, &slen)) == -1) {
260233
perror("accept");
261234
continue;
262235
}
263236

264-
printf("Connected.\n");
237+
fprintf(stderr, "Connected.\n");
238+
239+
/* TODO: poll on multiple listeners */
265240

266241
// do {
242+
//
243+
/* TODO: handle partial reads */
244+
267245
n = recv(s2, rx_buf, sizeof(rx_buf), 0);
268246
if (n <= 0) {
269247
if (n < 0)
270248
perror("recv");
271249
else
272-
printf("Client disconnected\n");
250+
fprintf(stderr, "Client disconnected\n");
273251
continue;
274252
}
275253

@@ -281,7 +259,7 @@ int main(int argc, char *argv[])
281259
}
282260

283261
if (response_len < 0) {
284-
printf("Failed to process request\n");
262+
fprintf(stderr, "Failed to process request\n");
285263
continue;
286264
}
287265

@@ -291,7 +269,7 @@ int main(int argc, char *argv[])
291269
break;
292270
}
293271

294-
printf("Response sent (%d bytes)\n", response_len);
272+
fprintf(stderr, "Response sent (%d bytes)\n", response_len);
295273
}
296274
// } while (1);
297275

0 commit comments

Comments
 (0)