Add note about reboot before 'make upgrade' step.
[dragonfly.git] / usr.sbin / installer / libdfui / system.c
blobff5a2d22936d8c0d017e2c04deb1f3e9a6cba0c6
1 /*
2 * system.c
3 * System definitions and capabilities.
4 * $Id: system.c,v 1.5 2004/11/14 02:45:51 cpressey Exp $
5 */
7 #include <sys/param.h>
8 #include <sys/sysctl.h>
10 #include <err.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <sysexits.h>
15 #include "dfui.h"
16 #include "system.h"
18 char *
19 ostype(void)
21 int mib[2];
22 size_t len;
23 char *p;
25 mib[0] = CTL_KERN;
26 mib[1] = KERN_OSTYPE;
27 sysctl(mib, 2, NULL, &len, NULL, 0);
28 p = malloc(len);
29 sysctl(mib, 2, p, &len, NULL, 0);
30 return p;
33 int
34 has_npipe(void)
36 #ifdef HAS_NPIPE
37 return 1;
38 #else
39 return 0;
40 #endif
43 int
44 has_tcp(void)
46 #ifdef HAS_TCP
47 return 1;
48 #else
49 return 0;
50 #endif
54 * Get transport from transport name.
56 * return(0) if transport is not supported.
57 * retirn(-1) if transport unknown.
59 int
60 get_transport(const char *transport_name)
62 if (strcmp(transport_name, "npipe") == 0) {
63 if (has_npipe())
64 return DFUI_TRANSPORT_NPIPE;
65 return(0);
66 } else if (strcmp(transport_name, "tcp") == 0) {
67 if (has_tcp())
68 return DFUI_TRANSPORT_TCP;
69 return(0);
71 return(-1);
75 * Get transport upon user request
77 * Print appropriate error message to stderr
78 * and exit if transport not supported or unknown.
80 int
81 user_get_transport(const char *transport_name)
83 int transport;
85 transport = get_transport(transport_name);
87 if (transport == 0) {
88 errx(EX_UNAVAILABLE, "Transport is not supported: ``%s''.\n",
89 transport_name);
90 } else if (transport < 0) {
91 errx(EX_CONFIG, "Wrong transport name: ``%s''.\n",
92 transport_name);
95 return(transport);