|
|
Jump to this file's LXR Page |
|
|
File: [CENS] / emstar / fusd / fusdd / fusdd_client_main.c
(download)
/
(as text)
Revision: 1.3, Sat Feb 19 00:22:05 2005 UTC (4 years, 9 months ago) by mlukac Branch: MAIN CVS Tags: rdd_alpha_version_1, pregeonet, acoustic-05-18-06, PRE_TOSNIC_FIX, PRE_64BIT, MOTENIC_PRE_BUGFIX_20050415, LAURA_CALIBRATION_EXPERIMENTS, HEAD, ESS_RELEASE_3_5, ESS_RELEASE_3_4, ESS_RELEASE_3_3, ESS_RELEASE_3_2, ESS_RELEASE_3_1, ESS_RELEASE_3_0, ESS_RELEASE_2_0, ESS_CONNECTIVITY, ESS_CENTROUTE_TESTING, ESS2-CMS-V1_5_pretest, ESS2-CMS-V1_4cMergeSympathy_2, ESS2-CMS-V1_4c, ESS2-CMS-V1_4b, ESS2-CMS-V1_4a, ESS2-CMS-V1_3, ESS2-CMS-V1_2, ESS2-CMS-V1_1, ESS2-CMS-V1_0, EMSTAR_RELEASE_2_5, EMSTAR_RELEASE_2_1_BRANCH, EMSTAR_RELEASE_2_1, CYCLOPS_RELEASE_CANDIDATE_2_0, CYCLOPS_PRERELEASE_STABLE, CENTROUTE_EMSTAR_SOCKETS, BG_1_0, BANGLADESH_ARSENIC_1_2, BANGLADESH_ARSENIC_1_1, AMARSS_JR_DEPLOYMENT_6_05_07 Changes since 1.2: +4 -0 lines added check to get rid of segfault |
/*
*
* Copyright (c) 2003 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <netdb.h>
#include <libmisc/misc.h>
#include <libmisc/elog.h>
#include <libmisc/misc_network.h>
#include <libmisc/queue.h>
#include <emrun/emrun.h>
#include <fusd.h>
#define __GNU_SOURCE
#include <getopt.h>
void usage(char *name)
{
fprintf(stderr,
"%s: %s <fusd URL>\n"
"Connects to the remote host and instantiates a local stub device\n"
"URL syntax: fusd://hostname/path[=local-device]\n"
" --remap: remap the stub device into the main device tree\n"
, name, name);
exit(1);
}
static void fnc_shutdown(void *data)
{
fusdd_client_context_t *fnc = (fusdd_client_context_t*)data;
elog(LOG_NOTICE, "fusdnet_client (connected to '%s') shutting down...",
fusdd_proxy_get_url(fnc));
fusdd_proxy_destroy(fnc);
exit(0);
}
int main(int argc, char **argv)
{
fusdd_client_context_t *fnc = NULL;
/* generic init */
misc_init(&argc, argv, CVSTAG);
int remap = misc_parse_out_switch(&argc, argv, "remap", 0);
while (1) {
int c;
int option_index = 0;
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{0, 0, 0, 0}
};
c = getopt_long (argc, argv, "h",
long_options, &option_index);
if (c == -1)
break;
switch (c) {
default:
case '?':
case 'h':
usage(argv[0]);
break;
}
}
/* grab the url arg */
char *url = argv[optind];
char *host = NULL;
char *remote = NULL;
char *local = NULL;
if (url == NULL)
usage(argv[0]);
if (fusdd_parse_url(&host, &remote, &local, url) < 0) {
elog(LOG_CRIT, "Invalid URL syntax: %s", url);
exit(1);
}
/* if remap, copy over */
if (remap) {
if (local) free(local);
local = strdup(remote);
}
/* prepend /dev to local if needed */
if (local && strncmp("/dev/", local, 5)) {
char tmp[256];
sprintf(tmp, "/dev/%s", local);
if (local) free(local);
local = strdup(tmp);
}
/* try to connect */
if (fusdd_proxy_connect(host, remote, local ? sim_path(local) : NULL, &fnc) < 0) {
elog(LOG_CRIT, "Failed to connect to %s: %m", url);
exit(1);
}
/* connect to emrun */
emrun_opts_t emrun_opts = {
shutdown: fnc_shutdown, /* this function implements our shutdown handler */
data: fnc /* this pointer will be passed to our shutdown handler */
};
emrun_init(&emrun_opts);
/* event loop */
g_main();
elog(LOG_ERR,"Irregular termination!\n");
return 1;
}
| CENS CVS Mailing List |
Powered by ViewCVS 0.9.2 |