Exemple #1
0
void user_daemon_t::run(int argc, char *argv[])
{
	co_module_t modules[1];
	co_rc_t rc;

	handle_parameters(argc, argv);
	
	prepare_for_loop();

	modules[0] = (co_module_t)(get_base_module() + param_index);

	rc = co_user_monitor_open(reactor, monitor_receive,
				  param_instance, modules, 
				  sizeof(modules)/sizeof(co_module_t),
				  &monitor_handle);
	if (!CO_OK(rc)) {
		log("cannot connect to monitor\n");
		return;
	}

	user_daemon = this;

	while (1) {
		co_rc_t rc;
		rc = co_reactor_select(reactor, 10);
		if (!CO_OK(rc))
			break;
	}
}
Exemple #2
0
int main(int argc, char **argv) {
  handle_parameters(argc, argv);
  int new_argc = argc + consumed_args;
  claims::common::Logging claims_logging(argv[0]);
  testing::InitGoogleTest(&(new_argc), argv + consumed_args);
  return RUN_ALL_TESTS();
}
Exemple #3
0
/* main entry point */
int main(int argc, char *argv[])
{
  int ret;

  /* init the default settings */
  struct settings_t settings;
  settings.gpio_base  = 55;
  settings.gpio_count = MAX_GPIO_COUNT;
  settings.loop       = 0;
  settings.poll       = 0;
  settings.poll_timeout = -1;

  print_info();
  
  /* parse the cmdline arguments */
  handle_parameters(argc, argv, &settings);

  /* initialize the gpio file names */
  init_gpio_filenames(settings.gpio_base, settings.gpio_count, settings.gpio_filenames);

  /* read the gpios */
  read_gpios(settings.gpio_count, settings.gpio_states, settings.gpio_filenames);

  /* print the states of the gpios */
  printf("initial values:\n");
  print_gpios(settings.gpio_base, settings.gpio_count, settings.gpio_states);
  printf("\n");

  /* keep reading gpios cpu intensive in a tight loop */
  if (settings.loop)
    enter_read_gpios_loop(settings.gpio_base, settings.gpio_count, settings.gpio_states, settings.gpio_filenames);

  /* poll the gpios once */
  if (settings.poll)
  {
    init_gpio_edges(settings.gpio_base, settings.gpio_count, settings.gpio_edge_filenames);
    if (read_edges(settings.gpio_count, settings.gpio_edge_values, settings.gpio_edge_filenames))
      if (validate_edges(settings.gpio_base, settings.gpio_count, settings.gpio_edge_values))
        enter_poll_gpios(settings.gpio_base, settings.gpio_count, settings.poll_timeout, settings.gpio_states, settings.gpio_filenames);
  }
}
int main(int argc, char** argv)
{
  int result = 0;
  RapiConnection* connection = NULL;
  HRESULT hr;
  char *shortcut, *target;
  WCHAR* wide_shortcut = NULL;
  WCHAR* wide_target = NULL;
  WCHAR *tmp, *tmp_quote;
  int tmpsize;

  if (!handle_parameters(argc, argv, &shortcut, &target))
    goto exit;

  if ((connection = rapi_connection_from_path(devpath)) == NULL)
  {
    fprintf(stderr, "%s: Could not find configuration at path '%s'\n", 
            argv[0],
            devpath?devpath:"(Default)");
    goto exit;
  }
  rapi_connection_select(connection);
  hr = CeRapiInit();

  if (FAILED(hr))
  {
    fprintf(stderr, "%s: Unable to initialize RAPI: %s\n", 
            argv[0],
        synce_strerror(hr));
    result = 1;
    goto exit;
  }


  convert_to_backward_slashes(shortcut);
  wide_shortcut = wstr_from_current(shortcut);
  wide_shortcut = adjust_remote_path(wide_shortcut, true);

  convert_to_backward_slashes(target);
  wide_target = wstr_from_current(target);
  wide_target = adjust_remote_path(wide_target, true);
  /* Wrap target in quotes.  This is required for paths with spaces (for some reason) */
  tmp_quote = wstr_from_current("\"");
  tmpsize = (wstrlen(wide_target) + 3) * sizeof(WCHAR);
  tmp = malloc(tmpsize);
  if (!tmp)
    goto exit;
  wstrcpy(tmp,tmp_quote);
  if (!wstr_append(tmp,wide_target,tmpsize))
    goto exit;
  if (!wstr_append(tmp,tmp_quote,tmpsize))
    goto exit;
  wstr_free_string(wide_target);
  wstr_free_string(tmp_quote);
  wide_target = tmp;
  
  BOOL res = CeSHCreateShortcut(wide_shortcut, wide_target);
  if (!res)
  {
    fprintf(stderr, "%s: Unable to create shortcut to '%s' at '%s': %s\n",
            argv[0],target,shortcut,
        synce_strerror(hr));
    result = 1;
    goto exit;
  }

 exit:
  wstr_free_string(wide_shortcut);
  wstr_free_string(wide_target);
  
  if (shortcut)
    free(shortcut);
  
  if (target)
    free(target);

  CeRapiUninit();
  rapi_connection_destroy(connection);
  
  return result;
}
int main(int argc, char** argv)
{
	int result = 1;
	FILE* file = NULL;
	char* vevent = NULL;
	long file_size = 0;
	uint8_t* buffer = NULL;
	size_t buffer_size = 0;
	RRA_Timezone tzi;
	RRA_Timezone* p_tzi = NULL;
        char *source = NULL, *dest = NULL, *tzfile = NULL;
        char *codepage = NULL;
        uint32_t flags = 0;

	if (!handle_parameters(argc, argv, &source, &dest, &tzfile, &codepage, &flags))
		goto exit;

	if (!codepage)
		codepage = "CP1252";

	file = fopen(source, "r");
	if (!file)
	{
		fprintf(stderr, "Unable to open file '%s'\n", source);
		goto exit;
	}

	/* find out file size */
	fseek(file, 0, SEEK_END);
	file_size = ftell(file);
	fseek(file, 0, SEEK_SET);

	vevent = (char*)malloc(file_size + 1);
	if (fread(vevent, file_size, 1, file) != 1)
	{
		fprintf(stderr, "Unable to read data from file '%s'\n", source);
		goto exit;
	}

	vevent[file_size] = '\0';
	fclose(file);
	file = NULL;

	if (tzfile)
	{
		file = fopen(tzfile, "r");
		if (file)
		{
			size_t bytes_read = fread(&tzi, 1, sizeof(RRA_Timezone), file);
			if (sizeof(RRA_Timezone) == bytes_read)
			{
				p_tzi = &tzi;
			}
			else
			{
				fprintf(stderr, "%s: Only read %i bytes from time zone information file '%s': %s\n", 
					argv[0], (int) bytes_read, tzfile, strerror(errno));
				goto exit;
			}

			fclose(file);
		}
		else
		{
			fprintf(stderr, "%s: Unable to open time zone information file '%s': %s\n", 
				argv[0], tzfile, strerror(errno));
			goto exit;
		}
	}

	if (!rra_appointment_from_vevent(
			vevent,
			NULL,
			&buffer,
			&buffer_size,
			flags,
			p_tzi,
			codepage))
	{
		fprintf(stderr, "Failed to create data\n");
		goto exit;
	}
	
	file = fopen(dest, "w");
	if (!file)
	{
		fprintf(stderr, "Unable to open file '%s'\n", dest);
		goto exit;
	}

	if (fwrite(buffer, buffer_size, 1, file) != 1)
	{
		fprintf(stderr, "Unable to write data to file '%s'\n", dest);
		goto exit;
	}

	result = 0;

exit:
	if (file)
		fclose(file);
	
	if (buffer)
		free(buffer);	

	if (vevent)
		free(vevent);
	
	return result;
}
Exemple #6
0
static co_rc_t coserial_main(int argc, char *argv[])
{
	co_rc_t rc;
	co_module_t module;
	HANDLE out_handle, in_handle;
	int select_time;

	rc = handle_parameters(&g_daemon_parameters, argc, argv);
	if (!CO_OK(rc))
		return rc;

	rc = co_reactor_create(&g_reactor);
	if (!CO_OK(rc))
		return rc;
	
	co_debug("connecting to monitor");

	module = CO_MODULE_SERIAL0 + g_daemon_parameters.index;
	rc = co_user_monitor_open(g_reactor, monitor_receive,
				  g_daemon_parameters.instance,
				  &module, 1,
				  &g_monitor_handle);
	if (!CO_OK(rc))
		return rc;

	if (g_daemon_parameters.filename_specified == PTRUE) {
		char name [strlen(g_daemon_parameters.filename) + 4+1];
		DCB dcb;
		COMMTIMEOUTS commtimeouts = {
			1,	/* ReadIntervalTimeout */
			0,	/* ReadTotalTimeoutMultiplier */
			0,	/* ReadTotalTimeoutConstant */
			0,	/* WriteTotalTimeoutMultiplier */
			0 };	/* WriteTotalTimeoutConstant */

		if (g_daemon_parameters.filename[0] != '\\') {
			/* short windows name */
			if (strncasecmp(g_daemon_parameters.filename, "COM", 3) != 0)
				co_terminal_print("warning: host serial device '%s' is not a COM port\n",
						    g_daemon_parameters.filename);
			snprintf(name, sizeof(name), "\\\\.\\%s", g_daemon_parameters.filename);
		} else {
			/* windows full name device */
			strncpy(name, g_daemon_parameters.filename, sizeof(name));
		}

		co_debug("open device '%s'", name);
		out_handle = \
		in_handle = CreateFile (name,
				GENERIC_READ | GENERIC_WRITE, 0, NULL,
				OPEN_EXISTING,
				FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
		if (in_handle == INVALID_HANDLE_VALUE) {
			co_terminal_print_last_error(g_daemon_parameters.filename);
			return CO_RC(ERROR);
		}

		if (g_daemon_parameters.mode_specified == PTRUE) {
			co_debug("set mode: %s", g_daemon_parameters.mode);

			if (!GetCommState(in_handle, &dcb)) {
				co_terminal_print_last_error("GetCommState");
				return CO_RC(ERROR);
			}
		
			/* Set defaults. user can overwrite ot */
			dcb.fOutxCtsFlow = FALSE; /* Disable Handshake */
			dcb.fDtrControl = DTR_CONTROL_ENABLE;
			dcb.fRtsControl = RTS_CONTROL_ENABLE;

			if (!BuildCommDCB(g_daemon_parameters.mode, &dcb)) {
				/*co_terminal_print_last_error("colinux-serial-daemon: BuildCommDCB");*/
				co_terminal_print("colinux-serial-daemon: error in mode parameter '%s'\n",
							g_daemon_parameters.mode);
				return CO_RC(ERROR);
			}

			if (!SetCommState(in_handle, &dcb)) {
				co_terminal_print_last_error("SetCommState");
				return CO_RC(ERROR);
			}
		} else {
			if (!EscapeCommFunction(in_handle, SETDTR)) {
				co_terminal_print_last_error("Warning EscapeCommFunction DTR");
				/* return CO_RC(ERROR); */
			}

			if (!EscapeCommFunction(in_handle, SETRTS)) {
				co_terminal_print_last_error("Warning EscapeCommFunction RTS");
				/* return CO_RC(ERROR); */
			}
		}

		if (!SetCommTimeouts(in_handle, &commtimeouts)) {
			co_terminal_print_last_error("SetCommTimeouts");
			return CO_RC(ERROR);
		}

		if (!SetupComm(in_handle, 2048, 2048)) {
			co_terminal_print_last_error("SetupComm");
			return CO_RC(ERROR);
		}

		select_time = -1;
	} else {
		co_debug("std input/output");
		out_handle = GetStdHandle(STD_OUTPUT_HANDLE);
		in_handle  = GetStdHandle(STD_INPUT_HANDLE);
		select_time = 100;
	}

	co_debug("connected");

	rc = co_winnt_reactor_packet_user_create(g_reactor, 
						 out_handle, in_handle,
						 std_receive, &g_reactor_handle);
	if (!CO_OK(rc))
		return rc;

	co_terminal_print("colinux-serial-daemon: running\n");

	while (CO_OK(rc)) {
		rc = co_reactor_select(g_reactor, select_time);
		if (CO_RC_GET_CODE(rc) == CO_RC_BROKEN_PIPE)
			return CO_RC(OK); /* Normal, if linux shut down */

		if (!g_daemon_parameters.filename_specified)
			if ( _kbhit() )
				send_userinput();
	}

	return -1;
}
Exemple #7
0
int main(int argc, char** argv)
{
	int result = 1;
	FILE* file = NULL;
	uint8_t* indata = NULL;
	long file_size = 0;
	uint8_t* buffer = NULL;
	size_t buffer_size = 0;
	char *source = NULL, *dest = NULL;
	DWORD ftype;
	char *filepath = NULL;
	struct stat statinfo;

	if (!handle_parameters(argc, argv, &filepath, &source, &dest))
		goto exit;

	if (stat(source, &statinfo) == -1) {
		fprintf(stderr, "Unable to stat file '%s': %sstrerror(errno)\n", source, strerror(errno));
		goto exit;
	}
	if (S_ISDIR(statinfo.st_mode)) {
		ftype = RRA_FILE_TYPE_DIRECTORY;
	} else {
		ftype = RRA_FILE_TYPE_FILE;
		file = fopen(source, "r");
		if (!file) {
			fprintf(stderr, "Unable to open file '%s'\n", source);
			goto exit;
		}

		/* find out file size */
		fseek(file, 0, SEEK_END);
		file_size = ftell(file);
		fseek(file, 0, SEEK_SET);

		indata = (uint8_t*)malloc(file_size);
		if (fread(indata, file_size, 1, file) != 1) {
			fprintf(stderr, "Unable to read data from file '%s'\n", source);
			goto exit;
		}

		fclose(file);
		file = NULL;
	}

	if (!filepath)
		filepath = source;

	if (!rra_file_pack(
			ftype,
			filepath,
			indata,
			file_size,
			&buffer,
			&buffer_size))
	{
		fprintf(stderr, "Failed to create data\n");
		goto exit;
	}
	
	file = fopen(dest, "w");
	if (!file)
	{
		fprintf(stderr, "Unable to open file '%s'\n", dest);
		goto exit;
	}

	if (fwrite(buffer, buffer_size, 1, file) != 1)
	{
		fprintf(stderr, "Unable to write data to file '%s'\n", dest);
		goto exit;
	}

	result = 0;

exit:
	if (file)
		fclose(file);
	
	if (buffer)
		free(buffer);	

	if (indata)
		free(indata);
	
	return result;
}
Exemple #8
0
int main(int argc, char **argv) {
  handle_parameters(argc, argv);
  int new_argc = argc + consumed_args;
  testing::InitGoogleTest(&(new_argc), argv + consumed_args);
  return RUN_ALL_TESTS();
}
int main(int argc, char** argv)
{
	int result = 1;
        RapiConnection* connection = NULL;
	char* source = NULL;
	char* dest = NULL;
	HRESULT hr;
	time_t start;
	time_t duration;
	size_t bytes_copied = 0;
	
	if (!handle_parameters(argc, argv, &source, &dest))
		goto exit;

        if ((connection = rapi_connection_from_path(devpath)) == NULL)
        {
          fprintf(stderr, "%s: Could not find configuration at path '%s'\n", 
                  argv[0],
                  devpath?devpath:"(Default)");
          goto exit;
        }
        rapi_connection_select(connection);
	hr = CeRapiInit();

	if (FAILED(hr))
	{
		fprintf(stderr, "%s: Unable to initialize RAPI: %s\n", 
				argv[0],
				synce_strerror(hr));
		goto exit;
	}

	if (!dest)
	{
		char* p;

		if (is_remote_file(source))
		{

			for (p = source + strlen(source); p != source; p--)
			{
				if (*p == '/' || *p == '\\')
				{
					dest = strdup(p+1);
					break;
				}
			}

			if (!dest || '\0' == dest[0])
			{
				fprintf(stderr, "%s: Unable to extract destination filename from source path '%s'\n",
						argv[0], source);
				goto exit;
			}
		}
		else
		{
			WCHAR mydocuments[MAX_PATH];
			char* mydocuments_ascii = NULL;
			p = strrchr(source, '/');

			if (p)
				p++;
			else
				p = source;

			if ('\0' == *p)
			{
				fprintf(stderr, "%s: Unable to extract destination filename from source path '%s'\n",
						argv[0], source);
				goto exit;
			}

			if (!CeGetSpecialFolderPath(CSIDL_PERSONAL, sizeof(mydocuments), mydocuments))
			{
				fprintf(stderr, "%s: Unable to get the \"My Documents\" path.\n",
						argv[0]);
				goto exit;
			}

			dest = calloc(1, 1 + wstr_strlen(mydocuments) + 1 + strlen(p) + 1);
			
			mydocuments_ascii = wstr_to_current(mydocuments);
			
			strcat(dest, ":");
			strcat(dest, mydocuments_ascii);
			strcat(dest, "\\");
			strcat(dest, p);
			
			wstr_free_string(mydocuments_ascii);
		}
	}

	if (0 == strcmp(source, dest))
	{
		fprintf(stderr, "You don't want to copy a file to itself.\n");
		goto exit;
	}

	if (is_remote_file(source) && is_remote_file(dest))
	{
		/*
		 * Both are remote; use CeCopyFile()
		 */
		if (!remote_copy(source, dest))
			goto exit;
	}
	else
	{
		start = time(NULL);

			/*
		 * At least one is local, Use the AnyFile functions
		 */
		if (!anyfile_copy(source, dest, argv[0], &bytes_copied))
			goto exit;

		duration = time(NULL) - start;

		if (0 == duration)
			printf("File copy took less than one second!\n");
		else
			printf("File copy of %i bytes took %li minutes and %li seconds, that's %li bytes/s.\n",
					bytes_copied, duration / 60, duration % 60, bytes_copied / duration);

	}

	result = 0;

exit:
	if (source)
		free(source);

	if (dest)
		free(dest);

	CeRapiUninit();
	return result;
}
Exemple #10
0
int main(int argc, char** argv){
	handle_parameters(argc,argv);
	Config::getInstance();
	handle_parameters(argc,argv);
	Config::getInstance()->print_configure();
#ifndef DEBUG_MODE
	bool master;
#ifndef AUTU_MASTER
	printf("If Master, please print 1!\n");
	int master=0;
	scanf("%d",&master);
#else
	master=Config::master;
#endif
	std::string actor;
	if(master)
		actor="master";
	else
		actor="slave";

#ifndef FORK
	if(master){
		Environment::getInstance(master);
//		create_poc_data_four_partitions();
//		create_poc_data_one_partitions();
//		print_welcome();
//		ExecuteLogicalQueryPlan();
		while(true)
			sleep(1);
	}
	else {
		Environment::getInstance(master);
		while(true)
			sleep(1);
	}
#else
		int pid=fork();
		if(pid!=0){
			printf("Daemon process id is %d\n",pid);
			sleep(1);
			return 0;
		}
		Config::getInstance();
		printf("Creating %s daemon...\n",actor.c_str());
		Environment::getInstance(master);
		printf("The %s daemon is successfully created.!\n",actor.c_str());
		printf("Logs are redirected to %s\n",Config::logfile.c_str());
		FILE *file;
		if((file=freopen(Config::logfile.c_str(),"a",stdout))==NULL){
			printf("output redirection fails!\n");
		}
		freopen(Config::logfile.c_str(),"a",stderr);

		fflush(stdout);
		fclose(stdout);
		//redirect back to console
		freopen("/dev/tty","a",stdout);
		printf("The Slave daemon is successfully created!\n");
		//redirect again to the log file.
		if((file=freopen(Config::logfile.c_str(),"a",stdout))==NULL){
			printf("output redirection fails!\n");
		}
		freopen(Config::logfile.c_str(),"a",stderr);
		while(true)
			sleep(1);
#endif
#else
	maina(argc, argv);
	return 0;
#endif
}
Exemple #11
0
int main(int argc, char** argv)
{
  int result = 0;
  IRAPIDesktop *desktop = NULL;
  IRAPIEnumDevices *enumdev = NULL;
  IRAPIDevice *device = NULL;
  IRAPISession *session = NULL;
  RAPI_DEVICEINFO devinfo;
  HRESULT hr;
  char* dev_name = NULL;

  if (!handle_parameters(argc, argv, &dev_name))
    goto exit;

  if (FAILED(hr = IRAPIDesktop_Get(&desktop)))
  {
    fprintf(stderr, "%s: failed to initialise RAPI: %d: %s\n", 
        argv[0], hr, synce_strerror_from_hresult(hr));
    goto exit;
  }

  if (FAILED(hr = IRAPIDesktop_EnumDevices(desktop, &enumdev)))
  {
    fprintf(stderr, "%s: failed to get connected devices: %d: %s\n", 
        argv[0], hr, synce_strerror_from_hresult(hr));
    goto exit;
  }

  while (SUCCEEDED(hr = IRAPIEnumDevices_Next(enumdev, &device)))
  {
    if (dev_name == NULL)
      break;

    if (FAILED(IRAPIDevice_GetDeviceInfo(device, &devinfo)))
    {
      fprintf(stderr, "%s: failure to get device info\n", argv[0]);
      goto exit;
    }
    if (strcmp(dev_name, devinfo.bstrName) == 0)
      break;
  }

  if (FAILED(hr))
  {
    fprintf(stderr, "%s: Could not find device '%s': %08x: %s\n", 
        argv[0],
        dev_name?dev_name:"(Default)", hr, synce_strerror_from_hresult(hr));
    device = NULL;
    goto exit;
  }

  IRAPIDevice_AddRef(device);
  IRAPIEnumDevices_Release(enumdev);
  enumdev = NULL;

  if (FAILED(hr = IRAPIDevice_CreateSession(device, &session)))
  {
    fprintf(stderr, "%s: Could not create a session to device: %08x: %s\n", 
        argv[0], hr, synce_strerror_from_hresult(hr));
    goto exit;
  }

  if (FAILED(hr = IRAPISession_CeRapiInit(session)))
  {
    fprintf(stderr, "%s: Unable to initialize connection to device: %08x: %s\n", 
        argv[0], hr, synce_strerror_from_hresult(hr));
    goto exit;
  }

  if (!IRAPISession_CeSyncTimeToPc(session))
  {
    fprintf(stderr,"%s: CeSyncTimeToPc failed\n",argv[0]);
    result = 2;
    goto exit;
  }

 exit:
  if (session)
  {
    IRAPISession_CeRapiUninit(session);
    IRAPISession_Release(session);
  }

  if (device) IRAPIDevice_Release(device);
  if (enumdev) IRAPIEnumDevices_Release(enumdev);
  if (desktop) IRAPIDesktop_Release(desktop);

  return result;
}
int main(int argc, char** argv)
{
	int result = 1;
	FILE* file = NULL;
	char* vcard = NULL;
	long file_size = 0;
	uint8_t* buffer = NULL;
	size_t buffer_size = 0;
	char *source = NULL, *dest = NULL;
	char *codepage = NULL;
	uint32_t flags = 0;

	if (!handle_parameters(argc, argv, &source, &dest, &codepage, &flags))
		goto exit;

	if (!codepage)
		codepage = "CP1252";

	file = fopen(source, "r");
	if (!file)
	{
		fprintf(stderr, "Unable to open file '%s'\n", source);
		goto exit;
	}

	/* find out file size */
	fseek(file, 0, SEEK_END);
	file_size = ftell(file);
	fseek(file, 0, SEEK_SET);

	vcard = (char*)malloc(file_size + 1);
	if (fread(vcard, file_size, 1, file) != 1)
	{
		fprintf(stderr, "Unable to read data from file '%s'\n", source);
		goto exit;
	}

	vcard[file_size] = '\0';
	fclose(file);
	file = NULL;

	if (!rra_contact_from_vcard(
			vcard,
			NULL,
			&buffer,
			&buffer_size,
			RRA_CONTACT_NEW | flags,
			codepage))
	{
		fprintf(stderr, "Failed to create data\n");
		goto exit;
	}
	
	file = fopen(dest, "w");
	if (!file)
	{
		fprintf(stderr, "Unable to open file '%s'\n", dest);
		goto exit;
	}

	if (fwrite(buffer, buffer_size, 1, file) != 1)
	{
		fprintf(stderr, "Unable to write data to file '%s'\n", dest);
		goto exit;
	}

	result = 0;

exit:
	if (file)
		fclose(file);
	
	if (buffer)
		free(buffer);	

	if (vcard)
		free(vcard);
	
	return result;
}
int main(int argc, char** argv)
{
	int result = 1;
        RapiConnection* connection = NULL;
	char* program = NULL;
	char* parameters = NULL;
	HRESULT hr;
	WCHAR* wide_program = NULL;
	WCHAR* wide_parameters = NULL;
	PROCESS_INFORMATION info;

	if (!handle_parameters(argc, argv, &program, &parameters))
		goto exit;

        if ((connection = rapi_connection_from_path(devpath)) == NULL)
        {
          fprintf(stderr, "%s: Could not find configuration at path '%s'\n", 
                  argv[0],
                  devpath?devpath:"(Default)");
          goto exit;
        }
        rapi_connection_select(connection);
	hr = CeRapiInit();

	if (FAILED(hr))
	{
		fprintf(stderr, "%s: Unable to initialize RAPI: %s\n", 
				argv[0],
				synce_strerror(hr));
		goto exit;
	}

	convert_to_backward_slashes(program);
	wide_program = wstr_from_current(program);
	if (parameters)
		wide_parameters = wstr_from_current(parameters);

	memset(&info, 0, sizeof(info));
	
	if (!CeCreateProcess(
				wide_program,
				wide_parameters,
				NULL,
				NULL,
				false,
				0,
				NULL,
				NULL,
				NULL,
				&info
				))
	{
		fprintf(stderr, "%s: Failed to execute '%s': %s\n", 
				argv[0],
				program,
				synce_strerror(CeGetLastError()));
		goto exit;
	}

	CeCloseHandle(info.hProcess);
	CeCloseHandle(info.hThread);

	result = 0;

exit:
	wstr_free_string(wide_program);
	wstr_free_string(wide_parameters);

	if (program)
		free(program);

	if (parameters)
		free(parameters);

	CeRapiUninit();
	return result;
}
Exemple #14
0
static int
conet_ndis_main(int argc, char *argv[])
{
	co_rc_t rc;
	start_parameters_t start_parameters;
	co_module_t modules[] = {CO_MODULE_CONET0, };
	co_monitor_ioctl_conet_bind_adapter_t ioctl;
	int a0,a1,a2,a3,a4,a5;

	rc = handle_parameters(&start_parameters, argc, argv);
	if (!CO_OK(rc))
		return -1;

	if (start_parameters.show_help) {
		co_net_syntax();
		return 0;
	}

	daemon_parameters = &start_parameters;

	rc = conet_init();
	if (!CO_OK(rc)) {
		co_terminal_print("conet-ndis-daemon: Error initializing ndis-bridge (rc %x)\n", (int)rc);
		return -1;
	}

	rc = co_reactor_create(&g_reactor);
	if (!CO_OK(rc))
		return -1;

	modules[0] += start_parameters.index;
	rc = co_user_monitor_open(g_reactor, monitor_receive,
				  start_parameters.instance, modules,
				  sizeof(modules)/sizeof(co_module_t),
				  &g_monitor_handle);
	if (!CO_OK(rc))
		return -1;

	/* send ioctl to monitor bind conet protocol to adapter */
	ioctl.conet_proto = CO_CONET_BRIDGE;
	ioctl.conet_unit = start_parameters.index;
	ioctl.promisc_mode = start_parameters.promisc;
	sscanf(start_parameters.mac_address, "%2x:%2x:%2x:%2x:%2x:%2x",
			&a0, &a1, &a2, &a3, &a4, &a5);
	ioctl.mac_address[0] = a0;
	ioctl.mac_address[1] = a1;
	ioctl.mac_address[2] = a2;
	ioctl.mac_address[3] = a3;
	ioctl.mac_address[4] = a4;
	ioctl.mac_address[5] = a5;
	strcpy(ioctl.netcfg_id, netcfg_id);

	co_user_monitor_conet_bind_adapter(g_monitor_handle, &ioctl);

	while (1) {
		rc = co_reactor_select(g_reactor, -1);
		if (!CO_OK(rc))
			break;
	}

	co_user_monitor_close(g_monitor_handle);
	co_reactor_destroy(g_reactor);

	return 0;
}
int main(int argc, char** argv)
{
	int result = 1;
        RapiConnection* connection = NULL;
	char* source = NULL;
	char* dest = NULL;
	HRESULT hr;
	WCHAR* wide_source = NULL;
	WCHAR* wide_dest = NULL;
	
	if (!handle_parameters(argc, argv, &source, &dest))
		goto exit;

        if ((connection = rapi_connection_from_path(devpath)) == NULL)
        {
          fprintf(stderr, "%s: Could not find configuration at path '%s'\n", 
                  argv[0],
                  devpath?devpath:"(Default)");
          goto exit;
        }
        rapi_connection_select(connection);
	hr = CeRapiInit();

	if (FAILED(hr))
	{
		fprintf(stderr, "%s: Unable to initialize RAPI: %s\n", 
				argv[0],
				synce_strerror(hr));
		goto exit;
	}

	convert_to_backward_slashes(source);
	wide_source = wstr_from_current(source);
	wide_source = adjust_remote_path(wide_source, true);

	convert_to_backward_slashes(dest);
	wide_dest   = wstr_from_current(dest);
	wide_dest   = adjust_remote_path(wide_dest, true);

	if (!CeMoveFile(wide_source, wide_dest))
	{
		fprintf(stderr, "%s: Cannot move '%s' to '%s': %s\n", 
				argv[0],
				source,
				dest,
				synce_strerror(CeGetLastError()));
		goto exit;
	}

	result = 0;

exit:
	wstr_free_string(wide_source);
	wstr_free_string(wide_dest);

	if (source)
		free(source);

	if (dest)
		free(dest);

	CeRapiUninit();
	return result;
}