Skip to content

Commit 48e0b52

Browse files
committed
Error message if NCP environment variable isn't set.
1 parent e3651bc commit 48e0b52

File tree

8 files changed

+18
-0
lines changed

8 files changed

+18
-0
lines changed

apps/discard.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ int main (int argc, char **argv)
6363
fprintf (stderr, "NCP initialization error: %s.\n", strerror (errno));
6464
if (errno == ECONNREFUSED)
6565
fprintf (stderr, "Is the NCP server started?\n");
66+
else if (errno == EFAULT)
67+
fprintf (stderr, "Is the NCP environment variable set?\n");
6668
exit (1);
6769
}
6870

apps/echo.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ int main (int argc, char **argv)
136136
fprintf (stderr, "NCP initialization error: %s.\n", strerror (errno));
137137
if (errno == ECONNREFUSED)
138138
fprintf (stderr, "Is the NCP server started?\n");
139+
else if (errno == EFAULT)
140+
fprintf (stderr, "Is the NCP environment variable set?\n");
139141
exit (1);
140142
}
141143

apps/finger.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ int main (int argc, char **argv)
2222
fprintf (stderr, "NCP initialization error: %s.\n", strerror (errno));
2323
if (errno == ECONNREFUSED)
2424
fprintf (stderr, "Is the NCP server started?\n");
25+
else if (errno == EFAULT)
26+
fprintf (stderr, "Is the NCP environment variable set?\n");
2527
exit (1);
2628
}
2729

apps/finser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ int main (int argc, char **argv)
2020
fprintf (stderr, "NCP initialization error: %s.\n", strerror (errno));
2121
if (errno == ECONNREFUSED)
2222
fprintf (stderr, "Is the NCP server started?\n");
23+
else if (errno == EFAULT)
24+
fprintf (stderr, "Is the NCP environment variable set?\n");
2325
exit (1);
2426
}
2527

apps/gateway.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ int main (int argc, char **argv)
231231
fprintf (stderr, "NCP initialization error: %s.\n", strerror (errno));
232232
if (errno == ECONNREFUSED)
233233
fprintf (stderr, "Is the NCP server started?\n");
234+
else if (errno == EFAULT)
235+
fprintf (stderr, "Is the NCP environment variable set?\n");
234236
exit (1);
235237
}
236238

apps/ping.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ int main (int argc, char **argv)
7171
fprintf (stderr, "NCP initialization error: %s.\n", strerror (errno));
7272
if (errno == ECONNREFUSED)
7373
fprintf (stderr, "Is the NCP server started?\n");
74+
else if (errno == EFAULT)
75+
fprintf (stderr, "Is the NCP environment variable set?\n");
7476
exit (1);
7577
}
7678

apps/telnet.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ int main (int argc, char **argv)
550550
fprintf (stderr, "NCP initialization error: %s.\n", strerror (errno));
551551
if (errno == ECONNREFUSED)
552552
fprintf (stderr, "Is the NCP server started?\n");
553+
else if (errno == EFAULT)
554+
fprintf (stderr, "Is the NCP environment variable set?\n");
553555
exit (1);
554556
}
555557

src/libncp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <fcntl.h>
44
#include <stdio.h>
5+
#include <errno.h>
56
#include <stdlib.h>
67
#include <stdint.h>
78
#include <unistd.h>
@@ -52,6 +53,9 @@ int ncp_init (const char *path)
5253
server.sun_family = AF_UNIX;
5354
if (path == NULL)
5455
path = getenv ("NCP");
56+
errno = EFAULT;
57+
if (path == NULL)
58+
return -1;
5559
strncpy (server.sun_path, path, sizeof server.sun_path - 1);
5660
if (connect (fd, (struct sockaddr *) &server, sizeof server) == -1)
5761
return -1;

0 commit comments

Comments
 (0)