Exemplo n.º 1
0
int main(int argc, char **argv)
{
	int fd;
        char *port = "/dev/can1";	// use "1" to "4" for steinhoff
        int opt;
	int status;
	db_id_t *pdb_id_list = NULL;
	db_clt_typ *pclt;              /* Database client pointer */
	char hostname[MAXHOSTNAMELEN+1];
	char *domain = DEFAULT_SERVICE; 
	int xport = COMM_OS_XPORT;	
	int count = 0;
	
        while ((opt = getopt(argc, argv, "p:")) != -1) {
                switch (opt) {
                case 'p':
                        port = strdup(optarg);
                        break;
                default:
                        printf("Usage: %s -p <port>\n", argv[0]);
                        exit(1);
                }
        }

	fd = can_open(port, O_RDONLY);

	if (fd == -1)
		exit(EXIT_FAILURE);	// error message printed by can_open 

	printf("program %s, device name %s, fd: %d\n", argv[0], port, fd);
	fflush(stdout);

	pdb_id_list = get_db_id_list();
	get_local_name(hostname, MAXHOSTNAMELEN);

	// Log in to the data server and create variables for all VAA messages
	if ((pclt = db_list_init( argv[0], hostname, domain, xport, 
			pdb_id_list, num_vaa_msg_ids, NULL, 0)) == NULL) {
		printf("Database initialization error in %s.\n", argv[0]);
		exit(EXIT_FAILURE);
	}
	
        if(setjmp(exit_env) != 0) {
		printf("Successfully wrote %d messages to data server\n",
				count);
		if (fd != -1)
			status = can_close(&fd);
		if (status != -1)			
			exit(EXIT_SUCCESS);
		else
			exit(EXIT_FAILURE);	// can_close prints error info
        } else
		sig_ign(sig_list, sig_hand);

	for(;;) {
		int retval;
		retval = rcv_g(pclt, fd, (void *) &vaa_msg[0]);
		count += retval;
	}
}
Exemplo n.º 2
0
/**
 * Out these "environment variables" in a file. It may be nicer
 * to use normal environment variables, but there's no nice way
 * to share those values across processes. 
 *
 * @param label The environment label
 * @param value The environment value
 * @param dir The directory to store the environment data
 */
void output_env(char *label, char *value, char *dir) 
{
    MPI_File f;
    char *file_name;
    char local_host[32];

    // Create a unique file name. 
    get_local_name(local_host, sizeof(local_host));
    file_name = (char*)malloc(strlen(dir) + strlen(local_host) + 2);
    sprintf(file_name, "%s/%s", dir, local_host);

    // Try opening the file.
    if(MPI_File_open(MPI_COMM_SELF, file_name,
    		     MPI_MODE_CREATE | MPI_MODE_RDWR | MPI_MODE_APPEND, 
		     MPI_INFO_NULL, &f) == MPI_SUCCESS) {
	char line[128];
    	MPI_Status ws;

	// We need to add the newline to each line. 
	sprintf(line, "%s=%s\n", label, value);
    	MPI_File_write(f, line, strlen(line), MPI_CHAR, &ws);
    }
    else {
      printf("failed opening %s\n", file_name);
    }

    MPI_File_close(&f); // Close the file
}
Exemplo n.º 3
0
const char *get_tcp_info(int peerfd)
{
	static char info[100] = {0};

	SAI localaddr = get_local_name(peerfd);
	SAI peeraddr = get_peer_addr(peerfd);
	snprintf(info, sizeof info, "%s:%d->%s:%d",
		get_addr_ip(&localaddr),
		get_addr_port(&localaddr),
		get_addr_ip(&peeraddr),
		get_addr_port(&peeraddr));

	return info;
}
Exemplo n.º 4
0
/* HELO command processing */
static int
helo_cmd(thread_t * thread)
{
	smtp_t *smtp = THREAD_ARG(thread);
	char *buffer;

	buffer = (char *) MALLOC(SMTP_BUFFER_MAX);
	snprintf(buffer, SMTP_BUFFER_MAX, SMTP_HELO_CMD, get_local_name());
	if (send(thread->u.fd, buffer, strlen(buffer), 0) == -1)
		smtp->stage = ERROR;
	FREE(buffer);

	return 0;
}
Exemplo n.º 5
0
/**
 * Launch an external program.
 *
 * @param cmd The command to run
 */
void launch(char* cmd)
{
  char name[50];

  // Get the local host name. 
  get_local_name(name, sizeof(name));  

  // Create an output redirect file specific to this node. 
  char output[1024];
  sprintf(output, "%s > %s.out 2> %s.err", cmd, name, name);
  printf("%s cmd: %s\n", name, output);

  // Run the command. 
  system(output);
}
Exemplo n.º 6
0
/**
 * Collect all the host names from the MPI cluster. 
 *
 * @param nprocs Number of machines
 * @return Buffer of all the host names.
 */
char* collect_global_hosts(int nprocs)
{
  char* global_hosts = create_global_hosts(nprocs);

  // Get the local machine names. 
  char local_host[32];
  get_local_name(local_host, sizeof(local_host));

  // Use MPI Gather to get this information from all machines. 
  MPI_Gather(local_host, sizeof(local_host), MPI_CHAR,
	     global_hosts, sizeof(local_host), MPI_CHAR,
	     0, MPI_COMM_WORLD);

  return global_hosts;
}
Exemplo n.º 7
0
int
main(int argc, char **argv)
{
	Buffer b;
	Options options;
#define NUM_KEYTYPES 3
	Key *keys[NUM_KEYTYPES], *key = NULL;
	struct passwd *pw;
	int key_fd[NUM_KEYTYPES], i, found, version = 2, fd;
	u_char *signature, *data;
	char *host;
	u_int slen, dlen;
	u_int32_t rnd[256];

	/* Ensure that stdin and stdout are connected */
	if ((fd = open(_PATH_DEVNULL, O_RDWR)) < 2)
		exit(1);
	/* Leave /dev/null fd iff it is attached to stderr */
	if (fd > 2)
		close(fd);

	i = 0;
	key_fd[i++] = open(_PATH_HOST_DSA_KEY_FILE, O_RDONLY);
	key_fd[i++] = open(_PATH_HOST_ECDSA_KEY_FILE, O_RDONLY);
	key_fd[i++] = open(_PATH_HOST_RSA_KEY_FILE, O_RDONLY);

	original_real_uid = getuid();	/* XXX readconf.c needs this */
	if ((pw = getpwuid(original_real_uid)) == NULL)
		fatal("getpwuid failed");
	pw = pwcopy(pw);

	permanently_set_uid(pw);

#ifdef DEBUG_SSH_KEYSIGN
	log_init("ssh-keysign", SYSLOG_LEVEL_DEBUG3, SYSLOG_FACILITY_AUTH, 0);
#endif

	/* verify that ssh-keysign is enabled by the admin */
	initialize_options(&options);
	(void)read_config_file(_PATH_HOST_CONFIG_FILE, "", &options, 0);
	fill_default_options(&options);
	if (options.enable_ssh_keysign != 1)
		fatal("ssh-keysign not enabled in %s",
		    _PATH_HOST_CONFIG_FILE);

	for (i = found = 0; i < NUM_KEYTYPES; i++) {
		if (key_fd[i] != -1)
			found = 1;
	}
	if (found == 0)
		fatal("could not open any host key");

	OpenSSL_add_all_algorithms();
	for (i = 0; i < 256; i++)
		rnd[i] = arc4random();
	RAND_seed(rnd, sizeof(rnd));

	found = 0;
	for (i = 0; i < NUM_KEYTYPES; i++) {
		keys[i] = NULL;
		if (key_fd[i] == -1)
			continue;
		keys[i] = key_load_private_pem(key_fd[i], KEY_UNSPEC,
		    NULL, NULL);
		close(key_fd[i]);
		if (keys[i] != NULL)
			found = 1;
	}
	if (!found)
		fatal("no hostkey found");

	buffer_init(&b);
	if (ssh_msg_recv(STDIN_FILENO, &b) < 0)
		fatal("ssh_msg_recv failed");
	if (buffer_get_char(&b) != version)
		fatal("bad version");
	fd = buffer_get_int(&b);
	if ((fd == STDIN_FILENO) || (fd == STDOUT_FILENO))
		fatal("bad fd");
	if ((host = get_local_name(fd)) == NULL)
		fatal("cannot get local name for fd");

	data = buffer_get_string(&b, &dlen);
	if (valid_request(pw, host, &key, data, dlen) < 0)
		fatal("not a valid request");
	xfree(host);

	found = 0;
	for (i = 0; i < NUM_KEYTYPES; i++) {
		if (keys[i] != NULL &&
		    key_equal_public(key, keys[i])) {
			found = 1;
			break;
		}
	}
	if (!found)
		fatal("no matching hostkey found");

	if (key_sign(keys[i], &signature, &slen, data, dlen) != 0)
		fatal("key_sign failed");
	xfree(data);

	/* send reply */
	buffer_clear(&b);
	buffer_put_string(&b, signature, slen);
	if (ssh_msg_send(STDOUT_FILENO, version, &b) == -1)
		fatal("ssh_msg_send failed");

	return (0);
}
Exemplo n.º 8
0
/**
 * Main function. 
 */
int main (int argc, char *argv[])
{
  char name[50];
  char* ips[15];
  char* labels[15];
  int num;
  int rank,nprocs,nid;
  MPI_Status status;
  cargs_t *arg;

  // Parse all the arguments. 
  cargs_t* *cargs = parse_args(argc, argv);

  // Initialize the MPI libs. 
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);

  // Does the user need help? 
  if( (arg = contains_arg(cargs, "help") ) != NULL ) {
    print_help();
  }

  // Do we need to generate local information?
  if( (arg = contains_arg(cargs, "local") ) != NULL ) {
    // Get local information.
    get_local_name(name, sizeof(name));
    export_host(name);
    num = get_local_addresses(rank, ips, labels);

    // Output local information. 
    export_local_addresses(ips, labels, num);

    // Where to put the information? 
    char *dir = "/tmp/network";
    if(arg->value != NULL) {
      dir = strtok(arg->value, " ");
    }

    output_local_hosts(name, ips, labels, num, dir);
  }

  arg = NULL;
  if( (arg = contains_arg(cargs, "global") ) != NULL ) {
    // Do we need to generate global information? 
    char* hosts = collect_global_hosts(nprocs);

    // Where to put the information? 
    char *dir = "/tmp/hosts.txt";
    if(arg->value != NULL) {      
      dir = strtok(arg->value, " ");
    }

    output_global_hosts(rank, nprocs,
			hosts, dir);
  }

  // Do we need to export some special variables?
  // (Used to indicate leaders, etc.)
  arg = NULL;
  if( (arg = contains_arg(cargs, "export") ) != NULL ) {
    char *label;
    char *to_rank;

    // Fetch the directory where we store the environment vars. 
    cargs_t *dir_arg = NULL;
    char *export_dir = NULL;
    if( (dir_arg = contains_arg(cargs, "dir") ) != NULL ) {
      export_dir = strtok(dir_arg->value, " ");
    }
    else {
      export_dir = "/tmp/environment";
    }

    // First value is the label to export.
    // Second value is the rank of the node.  
    label = strtok(arg->value, " ");
    to_rank = strtok(NULL, " ");

    // Output the value. 
    output_env(label, to_rank, export_dir);
  }

  // Is there a command? 
  arg = NULL;
  if( (arg = contains_arg(cargs, "cmd") ) != NULL ) {
    launch(arg->value);
  }

  // Finish MPI
  MPI_Finalize();

  return 0;
}
Exemplo n.º 9
0
int main( int argc, char *argv[] )
{
    db_clt_typ *pclt = NULL;
    char hostname[MAXHOSTNAMELEN+1];
    db_data_typ db_data;
    posix_timer_typ *ptmr;
    int recv_type;
    int millisec = 5000;
    trig_info_typ trig_info;
    uint64_t ticksPerMilliSec = SYSPAGE_ENTRY(qtime)->cycles_per_sec / 1000000;
    unsigned count = 0;
    unsigned total_diff = 0;

    /* Initialize the database. */
    get_local_name(hostname, MAXHOSTNAMELEN);
    if( (pclt = database_init(argv[0], hostname, DEFAULT_SERVICE,
			      COMM_QNX6_XPORT )) == NULL )
    {
	fprintf(stderr, "Database initialization error in ids_io\n");
	veh_done( pclt );
	exit( EXIT_FAILURE );
    }

    /* Initialize the timer. */
    if ((ptmr = timer_init(millisec, DB_CHANNEL(pclt))) == NULL)
    {
	printf("timer_init failed\n");
	exit( EXIT_FAILURE );
    }
	    
    print_timer(ptmr);
    if( setjmp( exit_env ) != 0 )
    {
	printf("average timediff = %u\n", total_diff / count);
	veh_done( pclt );
	exit( EXIT_SUCCESS );
    }
    else
	sig_ign( sig_list, sig_hand );

    for( ;; )
    {
	/* Now wait for a trigger. */
	recv_type= clt_ipc_receive(pclt, &trig_info, sizeof(trig_info));

	if (recv_type == DB_TIMER)
	{
	    printf("received timer alarm\n");
	}
	else if(DB_TRIG_VAR(&trig_info) ==  200)
	{
	    fflush(stdout);
	    /* Read DB_DII_OUT_VAR and send DII control
	     * to the hardware. */
	    if( clt_read( pclt, 200, 200, &db_data ) == FALSE)
	    {
		fprintf( stderr, "clt_read( DB_DII_OUT_VAR ).\n" );
	    }

	    else
	    {
		uint64_t *incoming_time = (uint64_t*) db_data.value.user;
		uint64_t timediff = ClockCycles() - *incoming_time;
		
		timediff /= ticksPerMilliSec;
		total_diff += timediff;
		++count;
	    }
	}
		
	else
	    printf("Unknown trigger, recv_type %d\n", recv_type);
    }
}
Exemplo n.º 10
0
int
main(int argc, char **argv)
{
	struct sshbuf *b;
	Options options;
#define NUM_KEYTYPES 4
	struct sshkey *keys[NUM_KEYTYPES], *key = NULL;
	struct passwd *pw;
	int r, key_fd[NUM_KEYTYPES], i, found, version = 2, fd;
	u_char *signature, *data, rver;
	char *host, *fp;
	size_t slen, dlen;
#ifdef WITH_OPENSSL
	u_int32_t rnd[256];
#endif

	if (pledge("stdio rpath getpw dns id", NULL) != 0)
		fatal("%s: pledge: %s", __progname, strerror(errno));

	/* Ensure that stdin and stdout are connected */
	if ((fd = open(_PATH_DEVNULL, O_RDWR)) < 2)
		exit(1);
	/* Leave /dev/null fd iff it is attached to stderr */
	if (fd > 2)
		close(fd);

	i = 0;
	/* XXX This really needs to read sshd_config for the paths */
	key_fd[i++] = open(_PATH_HOST_DSA_KEY_FILE, O_RDONLY);
	key_fd[i++] = open(_PATH_HOST_ECDSA_KEY_FILE, O_RDONLY);
	key_fd[i++] = open(_PATH_HOST_ED25519_KEY_FILE, O_RDONLY);
	key_fd[i++] = open(_PATH_HOST_RSA_KEY_FILE, O_RDONLY);

	original_real_uid = getuid();	/* XXX readconf.c needs this */
	if ((pw = getpwuid(original_real_uid)) == NULL)
		fatal("getpwuid failed");
	pw = pwcopy(pw);

	permanently_set_uid(pw);

	seed_rng();

#ifdef DEBUG_SSH_KEYSIGN
	log_init("ssh-keysign", SYSLOG_LEVEL_DEBUG3, SYSLOG_FACILITY_AUTH, 0);
#endif

	/* verify that ssh-keysign is enabled by the admin */
	initialize_options(&options);
	(void)read_config_file(_PATH_HOST_CONFIG_FILE, pw, "", "", &options, 0);
	fill_default_options(&options);
	if (options.enable_ssh_keysign != 1)
		fatal("ssh-keysign not enabled in %s",
		    _PATH_HOST_CONFIG_FILE);

	for (i = found = 0; i < NUM_KEYTYPES; i++) {
		if (key_fd[i] != -1)
			found = 1;
	}
	if (found == 0)
		fatal("could not open any host key");

#ifdef WITH_OPENSSL
	OpenSSL_add_all_algorithms();
	arc4random_buf(rnd, sizeof(rnd));
	RAND_seed(rnd, sizeof(rnd));
#endif

	found = 0;
	for (i = 0; i < NUM_KEYTYPES; i++) {
		keys[i] = NULL;
		if (key_fd[i] == -1)
			continue;
		r = sshkey_load_private_type_fd(key_fd[i], KEY_UNSPEC,
		    NULL, &key, NULL);
		close(key_fd[i]);
		if (r != 0)
			debug("parse key %d: %s", i, ssh_err(r));
		else if (key != NULL) {
			keys[i] = key;
			found = 1;
		}
	}
	if (!found)
		fatal("no hostkey found");

	if (pledge("stdio dns", NULL) != 0)
		fatal("%s: pledge: %s", __progname, strerror(errno));

	if ((b = sshbuf_new()) == NULL)
		fatal("%s: sshbuf_new failed", __progname);
	if (ssh_msg_recv(STDIN_FILENO, b) < 0)
		fatal("ssh_msg_recv failed");
	if ((r = sshbuf_get_u8(b, &rver)) != 0)
		fatal("%s: buffer error: %s", __progname, ssh_err(r));
	if (rver != version)
		fatal("bad version: received %d, expected %d", rver, version);
	if ((r = sshbuf_get_u32(b, (u_int *)&fd)) != 0)
		fatal("%s: buffer error: %s", __progname, ssh_err(r));
	if (fd < 0 || fd == STDIN_FILENO || fd == STDOUT_FILENO)
		fatal("bad fd");
	if ((host = get_local_name(fd)) == NULL)
		fatal("cannot get local name for fd");

	if ((r = sshbuf_get_string(b, &data, &dlen)) != 0)
		fatal("%s: buffer error: %s", __progname, ssh_err(r));
	if (valid_request(pw, host, &key, data, dlen) < 0)
		fatal("not a valid request");
	free(host);

	found = 0;
	for (i = 0; i < NUM_KEYTYPES; i++) {
		if (keys[i] != NULL &&
		    sshkey_equal_public(key, keys[i])) {
			found = 1;
			break;
		}
	}
	if (!found) {
		if ((fp = sshkey_fingerprint(key, options.fingerprint_hash,
		    SSH_FP_DEFAULT)) == NULL)
			fatal("%s: sshkey_fingerprint failed", __progname);
		fatal("no matching hostkey found for key %s %s",
		    sshkey_type(key), fp ? fp : "");
	}

	if ((r = sshkey_sign(keys[i], &signature, &slen, data, dlen, NULL, 0))
	    != 0)
		fatal("sshkey_sign failed: %s", ssh_err(r));
	free(data);

	/* send reply */
	sshbuf_reset(b);
	if ((r = sshbuf_put_string(b, signature, slen)) != 0)
		fatal("%s: buffer error: %s", __progname, ssh_err(r));
	if (ssh_msg_send(STDOUT_FILENO, version, b) == -1)
		fatal("ssh_msg_send failed");

	return (0);
}
Exemplo n.º 11
0
int main(int argc, char *argv[])
{
	int option;
	int exitsig;
	db_clt_typ *pclt;
	char hostname[MAXHOSTNAMELEN+1];

	int interval = 50;	/// Number of milliseconds between saves 
	posix_timer_typ *ptimer;       /* Timing proxy */
	char *domain = DEFAULT_SERVICE; // usually no need to change this 
	int xport = COMM_OS_XPORT;	// set correct for OS in sys_os.h 
	int verbose = 0;
	char zero_array[200];
	int i;

	memset(zero_array, 0, sizeof(zero_array));

	/* Read and interpret any user switches. */
	while ((option = getopt(argc, argv, "i:v")) != EOF) {
		switch(option) {
	        case 'i':
			interval = atoi(optarg); 
			break;
	        case 'v':
			verbose = 1; 
			break;
	        default:
			printf("Usage: %s\n", argv[0]); 
			printf("    -d <trip directory> \n");
			printf("    -m <file time in minutes> \n");
			printf("    -l <no. lines to save to file> \n");
			printf("    -t <loop time in ms> \n");
			exit(EXIT_FAILURE);
	        }
	}

	/* Log in to the database (shared global memory).  Default to the
	 * the current host. Assumes other processes that create variables
	 * are already running, since list is NULL.
	 */
	get_local_name(hostname, MAXHOSTNAMELEN);
	if ((pclt = db_list_init(argv[0], hostname, domain, xport, 
			db_controller_list, NUM_CONTROLLER_VARS, NULL, 0)) == NULL) {
		printf("Database initialization error in %s.\n", argv[0]);
		exit(EXIT_FAILURE);
	}
	for (i = 0; i < NUM_CONTROLLER_VARS; i++){
		db_clt_write(pclt,
		db_controller_list[i].id,
		db_controller_list[i].size,
		zero_array);
	}
        
	/* Setup a timer for every 'interval' msec. */
	if ((ptimer = timer_init(interval, DB_CHANNEL(pclt) )) == NULL) {
		printf("Unable to initialize wrfiles timer\n");
		exit(EXIT_FAILURE);
	}

	if(( exitsig = setjmp(exit_env)) != 0) {
		db_list_done(pclt, db_controller_list, NUM_CONTROLLER_VARS, NULL, 0);
		exit(EXIT_SUCCESS);
	} else
		sig_ign(sig_list, sig_hand);

	for(;;) {
		TIMER_WAIT(ptimer);
	}
}
Exemplo n.º 12
0
int main(int argc, char *argv[])
{
	int status;
	
	char hostname[MAXHOSTNAMELEN];
	char *domain = DEFAULT_SERVICE;	/// on Linux sets DB q-file directory
        db_clt_typ *pclt;       /// data server client pointer
        int xport = COMM_OS_XPORT;	/// OS-agnostic designation 
	int db_num = 0;		/// must be set to non-zero for DB update.

	int verbose = 0;	/// if 1, print extra info for debugging	
	int do_timing = 0;	/// if 1, print users and sys time at end 
	struct avcs_timing timing;	
	int udp_port = 7015;	/// port for receiving heartbeat
	int option;

	path_gps_point_t hb;	/// fill in from GPS messages received
	int sd_in;		/// socket descriptor for UDP receive
	int bytes_rcvd;		/// returned from recvfrom
	struct sockaddr_in src_addr;	/// used in recvfrom call
	unsigned int socklen;

	/* Read and interpret any user switches. */
	while ((option = getopt(argc, argv, "n:vu:")) != EOF) {
		switch(option) {
		case 'n':
			db_num = atoi(optarg);
			break;
		case 'v':
			verbose = 1;	
			break;
		case 'u':
			udp_port = atoi(optarg);
			break;
		default:
			fprintf(stderr, "Usage %s: ", argv[0]); 
			fprintf(stderr, " -u  (UDP port number for input) ");
			fprintf(stderr, " -n  DB variable number ");
			fprintf(stderr, " -v  (verbose, info to stdout) ");
			fprintf(stderr, "\n");
			exit(EXIT_FAILURE);
		}
	}
	fprintf(stderr, "Receiving GPS point for DB variable %d\n", db_num);
	fprintf(stderr, "writing output to stdout\n");
	fflush(stderr);

	sd_in = udp_allow_all(udp_port);
	if (sd_in < 0) {
		printf("failure opening socket on %d\n", udp_port);
		exit(EXIT_FAILURE);
	}

	if (db_num == 0) {
		fprintf(stderr, "Must specify DB variable number to use\n");
		fprintf(stderr, "Create DB variable in another process\n");
		fflush(stderr);
		exit(EXIT_FAILURE);
	}

	get_local_name(hostname, MAXHOSTNAMELEN);
        if ((pclt = clt_login(argv[0], hostname, domain, xport)) == NULL ) {
                        printf("%s: Database initialization error\n", argv[0]);
                        exit(EXIT_FAILURE);
                
        }
	
	if (setjmp(env) != 0) {
		if(pclt)
			db_list_done(pclt, NULL, 0, NULL, 0);
		exit(EXIT_SUCCESS);
	} else
               sig_ign(sig_list, sig_hand);

	socklen = sizeof(src_addr);
	memset(&src_addr, 0, socklen);
	memset(&hb, 0, sizeof(hb));
	while (1) {
		timestamp_t ts;
		bytes_rcvd = recvfrom(sd_in, &hb, sizeof(hb), 0,
				(struct sockaddr *) &src_addr, &socklen);
		if (bytes_rcvd < 0) {
			perror("recvfrom failed\n");
			continue;
		}
		get_current_timestamp(&ts);
		path_gps_update_object_id(&src_addr.sin_addr.s_addr, &hb, 4);
		db_clt_write(pclt, db_num, sizeof(path_gps_point_t), &hb);

		if (verbose) {
			print_timestamp(stdout, &ts);
			fprintf(stdout, " 0x%08x ", src_addr.sin_addr.s_addr);
			path_gps_print_point(stdout, &hb);
			fprintf(stdout, "\n");
			fflush(stdout);
		}
	}
}
Exemplo n.º 13
0
Arquivo: main.c Projeto: OPSF/uClinux
/*
 * This is called once the connection has been negotiated.  It is used
 * for rsyncd, remote-shell, and local connections.
 */
int client_run(int f_in, int f_out, pid_t pid, int argc, char *argv[])
{
	struct file_list *flist = NULL;
	int status = 0, status2 = 0;
	char *local_name = NULL;

	cleanup_child_pid = pid;
	if (!read_batch) {
		set_nonblocking(f_in);
		set_nonblocking(f_out);
	}

	io_set_sock_fds(f_in, f_out);
	setup_protocol(f_out,f_in);

	if (protocol_version >= 23 && !read_batch)
		io_start_multiplex_in();

	/* We set our stderr file handle to blocking because ssh might have
	 * set it to non-blocking.  This can be particularly troublesome if
	 * stderr is a clone of stdout, because ssh would have set our stdout
	 * to non-blocking at the same time (which can easily cause us to lose
	 * output from our print statements).  This kluge shouldn't cause ssh
	 * any problems for how we use it.  Note also that we delayed setting
	 * this until after the above protocol setup so that we know for sure
	 * that ssh is done twiddling its file descriptors.  */
	set_blocking(STDERR_FILENO);

	if (am_sender) {
		keep_dirlinks = 0; /* Must be disabled on the sender. */
		io_start_buffering_out();
		if (!filesfrom_host)
			set_msg_fd_in(f_in);
		send_filter_list(f_out);
		if (filesfrom_host)
			filesfrom_fd = f_in;

		if (write_batch && !am_server)
			start_write_batch(f_out);
		flist = send_file_list(f_out, argc, argv);
		set_msg_fd_in(-1);
		if (verbose > 3)
			rprintf(FINFO,"file list sent\n");
		the_file_list = flist;

		io_flush(NORMAL_FLUSH);
		send_files(flist,f_out,f_in);
		io_flush(FULL_FLUSH);
		handle_stats(-1);
		if (protocol_version >= 24)
			read_final_goodbye(f_in, f_out);
		if (pid != -1) {
			if (verbose > 3)
				rprintf(FINFO,"client_run waiting on %d\n", (int) pid);
			io_flush(FULL_FLUSH);
			wait_process(pid, &status);
		}
		output_summary();
		io_flush(FULL_FLUSH);
		exit_cleanup(status);
	}

	if (need_messages_from_generator && !read_batch)
		io_start_multiplex_out();

	if (argc == 0)
		list_only |= 1;

	send_filter_list(read_batch ? -1 : f_out);

	if (filesfrom_fd >= 0) {
		io_set_filesfrom_fds(filesfrom_fd, f_out);
		filesfrom_fd = -1;
	}

	if (write_batch && !am_server)
		start_write_batch(f_in);
	flist = recv_file_list(f_in);
	the_file_list = flist;

	if (flist && flist->count > 0) {
		local_name = get_local_name(flist, argv[0]);

		status2 = do_recv(f_in, f_out, flist, local_name);
	} else {
		handle_stats(-1);
		output_summary();
	}

	if (pid != -1) {
		if (verbose > 3)
			rprintf(FINFO,"client_run2 waiting on %d\n", (int) pid);
		io_flush(FULL_FLUSH);
		wait_process(pid, &status);
	}

	return MAX(status, status2);
}
Exemplo n.º 14
0
Arquivo: main.c Projeto: OPSF/uClinux
static void do_server_recv(int f_in, int f_out, int argc,char *argv[])
{
	int status;
	struct file_list *flist;
	char *local_name = NULL;
	char *dir = NULL;
	int save_verbose = verbose;

	if (filesfrom_fd >= 0) {
		/* We can't mix messages with files-from data on the socket,
		 * so temporarily turn off verbose messages. */
		verbose = 0;
	}

	if (verbose > 2) {
		rprintf(FINFO, "server_recv(%d) starting pid=%ld\n",
			argc, (long)getpid());
	}

	if (am_daemon && lp_read_only(module_id)) {
		rprintf(FERROR,"ERROR: module is read only\n");
		exit_cleanup(RERR_SYNTAX);
		return;
	}


	if (argc > 0) {
		dir = argv[0];
		argc--;
		argv++;
		if (!am_daemon && !push_dir(dir)) {
			rsyserr(FERROR, errno, "push_dir#4 %s failed",
				full_fname(dir));
			exit_cleanup(RERR_FILESELECT);
		}
	}

	io_start_buffering_in();
	recv_filter_list(f_in);

	if (filesfrom_fd >= 0) {
		/* We need to send the files-from names to the sender at the
		 * same time that we receive the file-list from them, so we
		 * need the IO routines to automatically write out the names
		 * onto our f_out socket as we read the file-list.  This
		 * avoids both deadlock and extra delays/buffers. */
		io_set_filesfrom_fds(filesfrom_fd, f_out);
		filesfrom_fd = -1;
	}

	flist = recv_file_list(f_in);
	verbose = save_verbose;
	if (!flist) {
		rprintf(FERROR,"server_recv: recv_file_list error\n");
		exit_cleanup(RERR_FILESELECT);
	}
	the_file_list = flist;

	if (argc > 0) {
		if (strcmp(dir,".")) {
			argv[0] += strlen(dir);
			if (argv[0][0] == '/')
				argv[0]++;
		}
		local_name = get_local_name(flist,argv[0]);
	}

	status = do_recv(f_in,f_out,flist,local_name);
	exit_cleanup(status);
}