3

可以让 Openoffice 通过 unix 域套接字接受 UNO 连接:

$soffice -headless -invisible -nocrashreport -nodefault -nologo -nofirststartwizard -norestore -conversionmode -accept='pipe,name=marcin_OOffice;urp;StarOffice.ComponentContext'

netstat 显示域套接字是在/tmp/OSL_PIPE_1001_marcin_OOffice. 很好,但是因为我将在共享主机上运行它,所以我希望将套接字放在其他地方,例如在我的家庭驱动器中。但是,将完整的文件路径(相对或绝对)作为name参数传递会导致不会创建套接字。

有没有办法可以影响创建套接字的位置,例如使用环境变量?

编辑:设置TMPTMPDIR环境变量不会影响这种行为。我在linux上运行这个。

4

2 回答 2

4

由于似乎没有一种“官方”的方式来控制创建套接字的位置,因此您可以通过编写自己的共享对象(插入connect()并重写AF_FILE/tmp 中的任何地址)来走“大锤破解”之路:

#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/socket.h>
#include <assert.h>
#include <linux/un.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>

int connect(int sockfd, const struct sockaddr *addr,
            socklen_t addrlen) 
{
  static int (*real_connect)(int, const struct sockaddr *, socklen_t) = NULL;
  if (!real_connect)
    real_connect = dlsym(RTLD_NEXT, "connect");

  if (addr->sa_family == AF_FILE) {
    // mutate sockaddr
    assert(addrlen >= sizeof(struct sockaddr_un));
    const struct sockaddr_un u = { AF_UNIX, "/foo/bar/path" };
    // but only if it is in /tmp
    if (!strncmp(((const struct sockaddr_un*)addr)->sun_path, "/tmp", 4)) {
      return real_connect(sockfd, (const struct sockaddr*)&u, sizeof u);
    }
  }
  return real_connect(sockfd, addr, addrlen);
}

编译:

gcc -Wall -Wextra test.c -ldl -shared -o interpose.so -fPIC

然后运行为:

LD_PRELOAD=./interpose.so soffice -headless -invisible -nocrashreport -nodefault -nologo -nofirststartwizard -norestore -conversionmode -accept='pipe,name=marcin_OOffice;urp;StarOffice.ComponentContext'

这似乎可以通过读取 strace 输出来工作(但我不知道如何实际使用套接字来证明它确实有效)。

于 2013-12-19T15:15:23.913 回答
-1

You should interpose between bind() (same signature as connect) as this is where the socket is created, then for the clients interpose between connect().

于 2015-03-05T06:55:07.377 回答