Ejemplo n.º 1
0
static gint socket_fd_open_inet(gushort port)
{
	SOCKET sock;
	struct sockaddr_in addr;
	gchar val;

	sock = socket(AF_INET, SOCK_STREAM, 0);
	if (G_UNLIKELY(! SOCKET_IS_VALID(sock)))
	{
		log_error("Failed to create IPC socket", -1);
		return -1;
	}

	val = 1;
	if (setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, &val, sizeof(val)) < 0)
	{
		log_error("Failed to set IPC socket exclusive option", -1);
		socket_fd_close(sock);
		return -1;
	}

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(port);
	addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

	if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
	{
		gint saved_errno = WSAGetLastError();
		gchar* message = g_strdup_printf("Failed to bind IPC socket (127.0.0.1:%d)", port);
		log_error(message, saved_errno);
		g_free(message);
		socket_fd_close(sock);
		return -1;
	}

	if (listen(sock, 1) < 0)
	{
		gint saved_errno = WSAGetLastError();
		gchar* message = g_strdup_printf("Failed to listen on IPC socket (127.0.0.1:%d)", port);
		log_error(message, saved_errno);
		g_free(message);
		socket_fd_close(sock);
		return -1;
	}

	return sock;
}
Ejemplo n.º 2
0
static gint socket_fd_connect_inet(gushort port)
{
	SOCKET sock;
	struct sockaddr_in addr;

	sock = socket(AF_INET, SOCK_STREAM, 0);
	if (G_UNLIKELY(! SOCKET_IS_VALID(sock)))
	{
		log_error("Failed to create IPC socket", -1);
		return -1;
	}

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(port);
	addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
	{
		gint saved_errno = WSAGetLastError();
		gchar* message = g_strdup_printf("Failed to connect to IPC socket (127.0.0.1:%d)", port);
		log_error(message, saved_errno);
		g_free(message);
		socket_fd_close(sock);
		return -1;
	}

	return sock;
}
Ejemplo n.º 3
0
gboolean socket_lock_input_cb(GIOChannel *source, GIOCondition condition, gpointer data)
{
    gint fd, sock;
    gchar buf[4096];
    gchar *buf_to_free;
    struct sockaddr_in caddr;
    guint caddr_len;
    GtkWidget *window = data;
    caddr_len = sizeof(caddr);

    fd = g_io_channel_unix_get_fd(source);
    sock = accept(fd, (struct sockaddr *)&caddr, &caddr_len);
    // first get the command
    if (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && strncmp(buf, "open", 4) == 0)
    {
        while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
        {
            g_strstrip(buf); // remove \n char
            buf_to_free = g_strdup (buf);
            if (g_file_test(buf, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
                xa_open_archive (NULL,buf_to_free);
        }
        gtk_window_deiconify (GTK_WINDOW(window));
    }
    socket_fd_close(sock);
    return TRUE;
}
Ejemplo n.º 4
0
static gint socket_fd_connect_inet(gushort port)
{
	SOCKET sock;
	struct sockaddr_in addr;

	sock = socket(AF_INET, SOCK_STREAM, 0);
	if (G_UNLIKELY(! SOCKET_IS_VALID(sock)))
	{
		geany_debug("fd_connect_inet(): socket() failed: %d\n", WSAGetLastError());
		return -1;
	}

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(port);
	addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

	if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
	{
		socket_fd_close(sock);
		return -1;
	}

	return sock;
}
Ejemplo n.º 5
0
static gint socket_fd_open_inet(gushort port)
{
	SOCKET sock;
	struct sockaddr_in addr;
	gchar val;

	sock = socket(AF_INET, SOCK_STREAM, 0);
	if (G_UNLIKELY(! SOCKET_IS_VALID(sock)))
	{
		geany_debug("fd_open_inet(): socket() failed: %d\n", WSAGetLastError());
		return -1;
	}

	val = 1;
	if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0)
	{
		perror("setsockopt");
		socket_fd_close(sock);
		return -1;
	}

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(port);
	addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

	if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
	{
		perror("bind");
		socket_fd_close(sock);
		return -1;
	}

	if (listen(sock, 1) < 0)
	{
		perror("listen");
		socket_fd_close(sock);
		return -1;
	}

	return sock;
}
Ejemplo n.º 6
0
static gint socket_fd_open_unix(const gchar *path)
{
    gint sock;
    struct sockaddr_un addr;
    gint val;

    sock = socket(PF_UNIX, SOCK_STREAM, 0);

    if (sock < 0)
    {
        perror("sock_open_unix(): socket");
        return -1;
    }

    val = 1;
    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0)
    {
        perror("setsockopt");
        socket_fd_close(sock);
        return -1;
    }

    memset(&addr, 0, sizeof(addr));
    addr.sun_family = AF_UNIX;
    strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);

    if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
    {
        perror("bind");
        socket_fd_close(sock);
        return -1;
    }

    if (listen(sock, 1) < 0)
    {
        perror("listen");
        socket_fd_close(sock);
        return -1;
    }

    return sock;
}
Ejemplo n.º 7
0
Archivo: eyed.c Proyecto: texane/eyed
void eyed_loop(unsigned short port)
{
  cio_err_t err;
  socket_fd_t fd;
  struct eyed_server server;

  server.cam_dev = NULL;

  if (cio_dispatcher_init(&server.disp) != CIO_ERR_SUCCESS)
    return ;

  if (cam_open_dev(&server.cam_dev, 0) != CAM_ERR_SUCCESS)
    goto on_error;

  fd = create_tcp_server(port);

  if (socket_fd_is_invalid(fd))
    goto on_error;

  err = cio_handle_init(&server.handle,
			fd,
			NULL,
			on_server_accept,
			NULL,
			on_server_close,
			&server);

  if (cio_err_is_failure(err))
    goto on_error;

  /* no longer belongs to us
   */

  socket_fd_reset(fd);

  err = cio_dispatcher_add_handle(&server.disp, &server.handle);
  if (cio_err_is_failure(err))
    goto on_error;

  while (!cio_dispatcher_is_done(&server.disp))
    cio_dispatcher_dispatch(&server.disp, (void*)&server);

 on_error:

  if (!socket_fd_is_invalid(fd))
    socket_fd_close(fd);

  if (server.cam_dev != NULL)
    cam_close_dev(server.cam_dev);

  cio_dispatcher_release(&server.disp);
}
Ejemplo n.º 8
0
static gint socket_fd_connect_unix(const gchar *path)
{
    gint sock;
    struct sockaddr_un addr;

    sock = socket(PF_UNIX, SOCK_STREAM, 0);
    if (sock < 0)
    {
        perror("fd_connect_unix(): socket");
        return -1;
    }

    memset(&addr, 0, sizeof(addr));
    addr.sun_family = AF_UNIX;
    strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);

    if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
    {
        socket_fd_close(sock);
        return -1;
    }
    return sock;
}
Ejemplo n.º 9
0
Archivo: eyed.c Proyecto: texane/eyed
static socket_fd_t create_tcp_server(unsigned short port)
{
  static const int enabled = 1;

  socket_fd_t fd;
  struct sockaddr_in addr;

  socket_fd_reset(fd);

  memset(&addr, 0, sizeof(struct sockaddr_in));

  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = INADDR_ANY;
  addr.sin_port = htons(port);

  fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (socket_fd_is_invalid(fd))
    {
      DEBUG_ERROR("socket");
      return fd;
    }

  if (bind(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)))
    {
      DEBUG_ERROR("bind()\n");

      socket_fd_close(fd);
      socket_fd_reset(fd);
      return fd;
    }

  listen(fd, 5);

  setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enabled, sizeof(enabled));

  return fd;
}
Ejemplo n.º 10
0
/* (Unix domain) socket support; taken from Geany */
gint socket_init(gint argc, gchar **argv)
{
    gint sock;

    if (socket_info.file_name == NULL)
        socket_info.file_name = g_strconcat ("/tmp/xarchiver_",g_get_user_name(),"_socket",NULL);

    sock = socket_fd_connect_unix(socket_info.file_name);
    if (sock < 0)
    {
        unlink(socket_info.file_name);
        return socket_fd_open_unix(socket_info.file_name);
    }
    // remote command mode, here we have another running instance and want to use it
    if (argc > 1)
    {
        gint i;
        gchar *filename;

        socket_fd_write_all(sock, "open\n", 5);

        for(i = 1; i < argc && argv[i] != NULL; i++)
        {
            filename = argv[i];

            if (filename != NULL)
            {
                socket_fd_write_all(sock, filename, strlen(filename));
                socket_fd_write_all(sock, "\n", 1);
            }
        }
        socket_fd_write_all(sock, ".\n", 2);
    }
    socket_fd_close(sock);
    return -1;
}
Ejemplo n.º 11
0
gboolean socket_lock_input_cb(GIOChannel *source, GIOCondition condition, gpointer data)
{
	gint fd, sock;
	gchar buf[BUFFER_LENGTH];
	gchar *command = NULL;
	struct sockaddr_in caddr;
	socklen_t caddr_len = sizeof(caddr);
	GtkWidget *window = data;
	gboolean popup = FALSE;

	fd = g_io_channel_unix_get_fd(source);
	sock = accept(fd, (struct sockaddr *)&caddr, &caddr_len);

	/* first get the command */
	while (socket_fd_gets(sock, buf, sizeof(buf)) != -1)
	{
		command = g_strdup(buf);
		geany_debug("Received IPC command from remote instance: %s", g_strstrip(command));
		g_free(command);
		if (strncmp(buf, "open", 4) == 0)
		{
			cl_options.readonly = strncmp(buf+4, "ro", 2) == 0; /* open in readonly? */
			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
			{
				gsize buf_len = strlen(buf);

				/* remove trailing newline */
				if (buf_len > 0 && buf[buf_len - 1] == '\n')
					buf[buf_len - 1] = '\0';

				handle_input_filename(buf);
			}
			popup = TRUE;
		}
		else if (strncmp(buf, "doclist", 7) == 0)
		{
			gchar *doc_list = build_document_list();
			if (!EMPTY(doc_list))
				socket_fd_write_all(sock, doc_list, strlen(doc_list));
			/* send ETX (end-of-text) so reader knows to stop reading */
			socket_fd_write_all(sock, "\3", 1);
			g_free(doc_list);
		}
		else if (strncmp(buf, "line", 4) == 0)
		{
			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
			{
				g_strstrip(buf); /* remove \n char */
				/* on any error we get 0 which should be safe enough as fallback */
				cl_options.goto_line = atoi(buf);
			}
		}
		else if (strncmp(buf, "column", 6) == 0)
		{
			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
			{
				g_strstrip(buf); /* remove \n char */
				/* on any error we get 0 which should be safe enough as fallback */
				cl_options.goto_column = atoi(buf);
			}
		}
#ifdef G_OS_WIN32
		else if (strncmp(buf, "window", 6) == 0)
		{
#	if GTK_CHECK_VERSION(3, 0, 0)
			HWND hwnd = (HWND) gdk_win32_window_get_handle(gtk_widget_get_window(window));
#	else
			HWND hwnd = (HWND) gdk_win32_drawable_get_handle(
				GDK_DRAWABLE(gtk_widget_get_window(window)));
#	endif
			socket_fd_write(sock, (gchar *)&hwnd, sizeof(hwnd));
		}
#endif
	}

	if (popup)
	{
#ifdef GDK_WINDOWING_X11
		GdkWindow *x11_window = gtk_widget_get_window(window);

		/* Set the proper interaction time on the window. This seems necessary to make
		 * gtk_window_present() really bring the main window into the foreground on some
		 * window managers like Gnome's metacity.
		 * Code taken from Gedit. */
#	if GTK_CHECK_VERSION(3, 0, 0)
		if (GDK_IS_X11_WINDOW(x11_window))
#	endif
		{
			gdk_x11_window_set_user_time(x11_window, gdk_x11_get_server_time(x11_window));
		}
#endif
		gtk_window_present(GTK_WINDOW(window));
#ifdef G_OS_WIN32
		gdk_window_show(gtk_widget_get_window(window));
#endif
	}

	socket_fd_close(sock);

	return TRUE;
}
Ejemplo n.º 12
0
static gint socket_fd_open_unix(const gchar *path)
{
	gint sock;
	struct sockaddr_un addr;
	gint val;
	gchar *real_path;

	sock = socket(PF_UNIX, SOCK_STREAM, 0);
	if (sock < 0)
	{
		log_error("Failed to create IPC socket", errno);
		return -1;
	}

	val = 1;
	if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0)
	{
		log_error("Failed to set IPC socket option", errno);
		socket_fd_close(sock);
		return -1;
	}

	/* fix for #1888561:
	 * in case the configuration directory is located on a network file system or any other
	 * file system which doesn't support sockets, we just link the socket there and create the
	 * real socket in the system's tmp directory assuming it supports sockets */
	real_path = g_strdup_printf("%s%cgeany_socket.%08x",
		g_get_tmp_dir(), G_DIR_SEPARATOR, g_random_int());

	if (utils_is_file_writable(real_path) != 0)
	{	/* if real_path is not writable for us, fall back to ~/.config/geany/geany_socket_*_* */
		/* instead of creating a symlink and print a warning */
		g_warning("Socket %s could not be written, using %s as fallback.", real_path, path);
		SETPTR(real_path, g_strdup(path));
	}
	/* create a symlink in e.g. ~/.config/geany/geany_socket_hostname__0 to /tmp/geany_socket.499602d2 */
	else if (symlink(real_path, path) != 0)
	{
		gint saved_errno = errno;
		gchar* message = g_strdup_printf(
			"Failed to create IPC socket symlink %s -> %s)",
			real_path,
			path);
		log_error(message, saved_errno);
		g_free(message);
		socket_fd_close(sock);
		return -1;
	}

	memset(&addr, 0, sizeof(addr));
	addr.sun_family = AF_UNIX;
	strncpy(addr.sun_path, real_path, sizeof(addr.sun_path) - 1);

	if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
	{
		gint saved_errno = errno;
		gchar* message = g_strdup_printf("Failed to bind IPC socket (%s)", real_path);
		log_error(message, saved_errno);
		g_free(message);
		socket_fd_close(sock);
		return -1;
	}

	if (listen(sock, 1) < 0)
	{
		gint saved_errno = errno;
		gchar* message = g_strdup_printf("Failed to listen on IPC socket (%s)", real_path);
		log_error(message, saved_errno);
		g_free(message);
		socket_fd_close(sock);
		return -1;
	}

	g_chmod(real_path, 0600);

	g_free(real_path);

	return sock;
}
Ejemplo n.º 13
0
/* (Unix domain) socket support to replace the old FIFO code
 * (taken from Sylpheed, thanks)
 * Returns the created socket, -1 if an error occurred or -2 if another socket exists and files
 * were sent to it. */
gint socket_init(gint argc, gchar **argv)
{
	gint sock;
#ifdef G_OS_WIN32
	HANDLE hmutex;
	HWND hwnd;
	socket_init_win32();
	hmutex = CreateMutexA(NULL, FALSE, "Geany");
	if (! hmutex)
	{
		geany_debug("cannot create Mutex\n");
		return -1;
	}
	if (GetLastError() != ERROR_ALREADY_EXISTS)
	{
		/* To support multiple instances with different configuration directories (as we do on
		 * non-Windows systems) we would need to use different port number s but it might be
		 * difficult to get a port number which is unique for a configuration directory (path)
		 * and which is unused. This port number has to be guessed by the first and new instance
		 * and the only data is the configuration directory path.
		 * For now we use one port number, that is we support only one instance at all. */
		sock = socket_fd_open_inet(REMOTE_CMD_PORT);
		if (sock < 0)
			return -1;
		return sock;
	}

	sock = socket_fd_connect_inet(REMOTE_CMD_PORT);
	if (sock < 0)
		return -1;
#else
	gchar *display_name = NULL;
	const gchar *hostname = g_get_host_name();
	GdkDisplay *display = gdk_display_get_default();
	gchar *p;

	/* On OS X with quartz backend gdk_display_get_name() returns hostname
	 * using [NSHost currentHost] (it could return more or less whatever string
	 * as display name is a X11 specific thing). This call can lead to network
	 * query and block for several seconds so better skip it. */
#ifndef GDK_WINDOWING_QUARTZ
	if (display != NULL)
		display_name = g_strdup(gdk_display_get_name(display));
#endif

	if (display_name == NULL)
		display_name = g_strdup("NODISPLAY");

	/* these lines are taken from dcopc.c in kdelibs */
	if ((p = strrchr(display_name, '.')) > strrchr(display_name, ':') && p != NULL)
		*p = '\0';
	/* remove characters that may not be acceptable in a filename */
	for (p = display_name; *p; p++)
	{
		if (*p == ':' || *p == '/')
			*p = '_';
	}

	if (socket_info.file_name == NULL)
		socket_info.file_name = g_strdup_printf("%s%cgeany_socket_%s_%s",
			app->configdir, G_DIR_SEPARATOR, hostname, display_name);

	g_free(display_name);

	/* check whether the real user id is the same as this of the socket file */
	check_socket_permissions();

	sock = socket_fd_connect_unix(socket_info.file_name);
	if (sock < 0)
	{
		remove_socket_link_full(); /* deletes the socket file and the symlink */
		return socket_fd_open_unix(socket_info.file_name);
	}
#endif

	/* remote command mode, here we have another running instance and want to use it */

	/* now we send the command line args */
	if (argc > 1)
	{
#ifdef G_OS_WIN32
		/* first we send a request to retrieve the window handle and focus the window */
		socket_fd_write_all(sock, "window\n", 7);
		if (socket_fd_read(sock, (gchar *)&hwnd, sizeof(hwnd)) == sizeof(hwnd))
			SetForegroundWindow(hwnd);
#endif

		send_open_command(sock, argc, argv);
	}

	if (cl_options.list_documents)
	{
		socket_get_document_list(sock);
	}

	socket_fd_close(sock);
	return -2;
}
Ejemplo n.º 14
0
gboolean socket_lock_input_cb(GIOChannel *source, GIOCondition condition, gpointer data)
{
	gint fd, sock;
	gchar buf[BUFFER_LENGTH];
	struct sockaddr_in caddr;
	socklen_t caddr_len = sizeof(caddr);
	GtkWidget *window = data;
	gboolean popup = FALSE;

	fd = g_io_channel_unix_get_fd(source);
	sock = accept(fd, (struct sockaddr *)&caddr, &caddr_len);

	/* first get the command */
	while (socket_fd_gets(sock, buf, sizeof(buf)) != -1)
	{
		if (strncmp(buf, "open", 4) == 0)
		{
			cl_options.readonly = strncmp(buf+4, "ro", 2) == 0; /* open in readonly? */
			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
			{
				handle_input_filename(g_strstrip(buf));
			}
			popup = TRUE;
		}
		else if (strncmp(buf, "doclist", 7) == 0)
		{
			gchar *doc_list = build_document_list();
			if (NZV(doc_list))
				socket_fd_write_all(sock, doc_list, strlen(doc_list));
			else
				/* send ETX (end-of-text) in case we have no open files, we must send anything
				 * otherwise the client would hang on reading */
				socket_fd_write_all(sock, "\3", 1);
			g_free(doc_list);
		}
		else if (strncmp(buf, "line", 4) == 0)
		{
			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
			{
				g_strstrip(buf); /* remove \n char */
				/* on any error we get 0 which should be safe enough as fallback */
				cl_options.goto_line = atoi(buf);
			}
		}
		else if (strncmp(buf, "column", 6) == 0)
		{
			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
			{
				g_strstrip(buf); /* remove \n char */
				/* on any error we get 0 which should be safe enough as fallback */
				cl_options.goto_column = atoi(buf);
			}
		}
#ifdef G_OS_WIN32
		else if (strncmp(buf, "window", 6) == 0)
		{
			HWND hwnd = (HWND) gdk_win32_drawable_get_handle(
				GDK_DRAWABLE(gtk_widget_get_window(window)));
			socket_fd_write(sock, (gchar *)&hwnd, sizeof(hwnd));
		}
#endif
	}

	if (popup)
	{
#ifdef GDK_WINDOWING_X11
		/* Set the proper interaction time on the window. This seems necessary to make
		 * gtk_window_present() really bring the main window into the foreground on some
		 * window managers like Gnome's metacity.
		 * Code taken from Gedit. */
		gdk_x11_window_set_user_time(gtk_widget_get_window(window),
			gdk_x11_get_server_time(gtk_widget_get_window(window)));
#endif
		gtk_window_present(GTK_WINDOW(window));
#ifdef G_OS_WIN32
		gdk_window_show(gtk_widget_get_window(window));
#endif
	}

	socket_fd_close(sock);

	return TRUE;
}
Ejemplo n.º 15
0
/* (Unix domain) socket support to replace the old FIFO code
 * (taken from Sylpheed, thanks)
 * Returns the created socket, -1 if an error occurred or -2 if another socket exists and files
 * were sent to it. */
gint socket_init(gint argc, gchar **argv)
{
	gint sock;
#ifdef G_OS_WIN32
	HANDLE hmutex;
	HWND hwnd;
	socket_init_win32();
	hmutex = CreateMutexA(NULL, FALSE, "Geany");
	if (! hmutex)
	{
		geany_debug("cannot create Mutex\n");
		return -1;
	}
	if (GetLastError() != ERROR_ALREADY_EXISTS)
	{
		/* To support multiple instances with different configuration directories (as we do on
		 * non-Windows systems) we would need to use different port number s but it might be
		 * difficult to get a port number which is unique for a configuration directory (path)
		 * and which is unused. This port number has to be guessed by the first and new instance
		 * and the only data is the configuration directory path.
		 * For now we use one port number, that is we support only one instance at all. */
		sock = socket_fd_open_inet(REMOTE_CMD_PORT);
		if (sock < 0)
			return 0;
		return sock;
	}

	sock = socket_fd_connect_inet(REMOTE_CMD_PORT);
	if (sock < 0)
		return -1;
#else
	gchar *display_name = gdk_get_display();
	gchar *hostname = utils_get_hostname();
	gchar *p;

	if (display_name == NULL)
		display_name = g_strdup("NODISPLAY");

	/* these lines are taken from dcopc.c in kdelibs */
	if ((p = strrchr(display_name, '.')) > strrchr(display_name, ':') && p != NULL)
		*p = '\0';
	while ((p = strchr(display_name, ':')) != NULL)
		*p = '_';

	if (socket_info.file_name == NULL)
		socket_info.file_name = g_strdup_printf("%s%cgeany_socket_%s_%s",
			app->configdir, G_DIR_SEPARATOR, hostname, display_name);

	g_free(display_name);
	g_free(hostname);

	/* check whether the real user id is the same as this of the socket file */
	check_socket_permissions();

	sock = socket_fd_connect_unix(socket_info.file_name);
	if (sock < 0)
	{
		remove_socket_link_full(); /* deletes the socket file and the symlink */
		return socket_fd_open_unix(socket_info.file_name);
	}
#endif

	/* remote command mode, here we have another running instance and want to use it */

#ifdef G_OS_WIN32
	/* first we send a request to retrieve the window handle and focus the window */
	socket_fd_write_all(sock, "window\n", 7);
	if (socket_fd_read(sock, (gchar *)&hwnd, sizeof(hwnd)) == sizeof(hwnd))
		SetForegroundWindow(hwnd);
#endif
	/* now we send the command line args */
	if (argc > 1)
	{
		send_open_command(sock, argc, argv);
	}

	if (cl_options.list_documents)
	{
		socket_get_document_list(sock);
	}

	socket_fd_close(sock);
	return -2;
}
Ejemplo n.º 16
0
Archivo: eyed.c Proyecto: texane/eyed
static void close_tcp_socket(socket_fd_t fd)
{
  shutdown(fd, SHUT_RDWR);
  socket_fd_close(fd);
  socket_fd_reset(fd);
}