1
2 /*
3 *
4 * Copyright (c) 2003 The Regents of the University of California. All
5 * rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * - Neither the name of the University nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 */
31
32 #include <netdb.h>
33 #include <libmisc/misc.h>
34 #include <libmisc/elog.h>
35 #include <libmisc/misc_network.h>
36 #include <libmisc/queue.h>
37 #include <emrun/emrun.h>
38 #include <fusd.h>
39
40 #define __GNU_SOURCE
41 #include <getopt.h>
42
43
44 void usage(char *name)
45 {
46 fprintf(stderr,
47 "%s: %s <fusd URL>\n"
48 "Connects to the remote host and instantiates a local stub device\n"
49 "URL syntax: fusd://hostname/path[=local-device]\n"
50 " --remap: remap the stub device into the main device tree\n"
51 , name, name);
52 exit(1);
53 }
54
55
56 static void fnc_shutdown(void *data)
57 {
58 fusdd_client_context_t *fnc = (fusdd_client_context_t*)data;
59 elog(LOG_NOTICE, "fusdnet_client (connected to '%s') shutting down...",
60 fusdd_proxy_get_url(fnc));
61 fusdd_proxy_destroy(fnc);
62 exit(0);
63 }
64
65
66 int main(int argc, char **argv)
67 {
68 fusdd_client_context_t *fnc = NULL;
69
70 /* generic init */
71 misc_init(&argc, argv, CVSTAG);
72
73 int remap = misc_parse_out_switch(&argc, argv, "remap", 0);
74
75 while (1) {
76 int c;
77 int option_index = 0;
78 static struct option long_options[] = {
79 {"help", 0, 0, 'h'},
80 {0, 0, 0, 0}
81 };
82
83 c = getopt_long (argc, argv, "h",
84 long_options, &option_index);
85 if (c == -1)
86 break;
87
88 switch (c) {
89 default:
90 case '?':
91 case 'h':
92 usage(argv[0]);
93 break;
94 }
95 }
96
97 /* grab the url arg */
98 char *url = argv[optind];
99 char *host = NULL;
100 char *remote = NULL;
101 char *local = NULL;
102
103
104 if (url == NULL)
105 usage(argv[0]);
106
107 if (fusdd_parse_url(&host, &remote, &local, url) < 0) {
108 elog(LOG_CRIT, "Invalid URL syntax: %s", url);
109 exit(1);
110 }
111
112 /* if remap, copy over */
113 if (remap) {
114 if (local) free(local);
115 local = strdup(remote);
116 }
117
118 /* prepend /dev to local if needed */
119 if (local && strncmp("/dev/", local, 5)) {
120 char tmp[256];
121 sprintf(tmp, "/dev/%s", local);
122 if (local) free(local);
123 local = strdup(tmp);
124 }
125
126 /* try to connect */
127 if (fusdd_proxy_connect(host, remote, local ? sim_path(local) : NULL, &fnc) < 0) {
128 elog(LOG_CRIT, "Failed to connect to %s: %m", url);
129 exit(1);
130 }
131
132 /* connect to emrun */
133 emrun_opts_t emrun_opts = {
134 shutdown: fnc_shutdown, /* this function implements our shutdown handler */
135 data: fnc /* this pointer will be passed to our shutdown handler */
136 };
137 emrun_init(&emrun_opts);
138
139 /* event loop */
140 g_main();
141 elog(LOG_ERR,"Irregular termination!\n");
142 return 1;
143 }
144
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.