static int hexMode = HEXMODE;
-static const char trbcmd_version[] = "$Revision: 2.53 $";
+static const char trbcmd_version[] = "$Revision: 2.54 $";
#define BACKLOG 10
static uint16_t tcp_port = 55555;
static void atexit0(void)
{
- if (tcp_debug == 1) {
- fprintf(stderr, "%d: exit called\n", myPid);
- }
shutdown(myFd, SHUT_RDWR);
- if (close(myFd) == -1) perror("close");
+ if (close(myFd) == -1) perror("atexit0 close");
}
static void sigHandler(int sig)
" to port %d [OK]\n\n",
tcp_port);
}
-
+
+ if (init_ports() == -1) exit(EXIT_FAILURE);
+
/* Enter an infinite loop to accept clients */
while (1) {
socklen_t sin_size = sizeof(struct sockaddr_in);
fprintf(stderr, "accept() OK...\n");
}
if ((myPid = fork()) == -1) { /* Error fork, Mother exit, no child */
- perror(argv[0]);
+ perror("Error fork");
exit(EXIT_FAILURE);
}
if (myPid > 0) {
- /* Mother process: continue accepting connections */
+ /* Mother process: close myFd and continue accepting connections */
+ if (close(myFd) == -1) {
+ perror("Error close fd");
+ exit(EXIT_FAILURE);
+ }
continue;
} else {
/* Child process */
stdout = clientout;
stderr = clientout;
- if (init_ports() == -1) exit(EXIT_FAILURE);
-
while (1) {
msgLen = recv(myFd, (void *)command, 256, 0);
if (msgLen == -1) {