大网数据广告活动
服务器运维问答

Running FlexLM License Server in a Docker Container

· 52CE 我爱测

I'm trying to run a FlexLM license server inside a docker container. I've done this before without any problems. But now I have a vendor (Synopsys) daemon (snpslmd) which doesn't seem to play nice with Docker. The daemon complain…

问题原文

原帖链接 · gogators · CC BY-SA 4.0

I'm trying to run a FlexLM license server inside a docker container. I've done this before without any problems. But now I have a vendor (Synopsys) daemon (snpslmd) which doesn't seem to play nice with Docker. The daemon complains about not being able to open its lock file: /var/tmp/locksnpslmd, but /var/tmp exists and is writable.

Here is the strace from the vendor daemon in the Docker container:

munmap(0x7fa322830000, 167936)          = 0
setsid()                                = 64
openat(AT_FDCWD, "/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
getdents(3, /* 22 entries */, 32768)    = 568
getdents(3, /* 0 entries */, 32768)     = 0
close(3)                                = 0
write(1, "17:35:24 (snpslmd) Cannot open d"..., 4817:35:24 (snpslmd) Cannot open daemon lock file
) = 48
write(1, "17:35:24 (snpslmd) EXITING DUE T"..., 5817:35:24 (snpslmd) EXITING DUE TO SIGNAL 41 Exit reason 9
) = 58
exit_group(41)                          = ?
+++ exited with 41 +++**

And Here's the same strace segment from the vendor daemon running normally outside of a container:

munmap(0x7f25da4db000, 4096)            = 0
setsid()                                = 15808
openat(AT_FDCWD, "/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
getdents(3, /* 23 entries */, 32768)    = 584
getdents(3, /* 0 entries */, 32768)     = 0
close(3)                                = 0
open("/var/tmp/locksnpslmd", O_RDWR|O_CREAT, 0666) = 3
fcntl(3, F_SETLK, {l_type=F_WRLCK, l_whence=SEEK_CUR, l_start=0, l_len=0}) = 0
stat("/var/tmp/locksnpslmd", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0

Any ideas?

社区高分解答

原帖链接 · dmitrodem · CC BY-SA 4.0

It happens because getdents() returns differend inode numbers for "." and ".." subdirectories of "/". It can be fixed using LD_PRELOAD hack for snpslmd

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <dlfcn.h>
#include <string.h>

static int is_root = 0;
static int d_ino = -1;

static DIR *(*orig_opendir)(const char *name);
static int (*orig_closedir)(DIR *dirp);
static struct dirent *(*orig_readdir)(DIR *dirp);

DIR *opendir(const char *name) {
  if (strcmp(name, "/") == 0) {
    is_root = 1;
  }

  return orig_opendir(name);
}


int closedir(DIR *dirp) {
  is_root = 0;
  return orig_closedir(dirp);
}

struct dirent *readdir(DIR *dirp) {
  struct dirent *r = orig_readdir(dirp);
  if (is_root && r) {
    if (strcmp(r->d_name, ".") == 0) {
      r->d_ino = d_ino;
    } else if (strcmp(r->d_name, "..") == 0) {
      r->d_ino = d_ino;
    }
  }
  return r;
}

static __attribute__((constructor)) void init_methods() {
  orig_opendir = dlsym(RTLD_NEXT, "opendir");
  orig_closedir = dlsym(RTLD_NEXT, "closedir");
  orig_readdir = dlsym(RTLD_NEXT, "readdir");
  DIR *d = orig_opendir("/");
  struct dirent *e = orig_readdir(d);
  while (e) {
    if (strcmp(e->d_name, ".") == 0) {
      d_ino = e->d_ino;
      break;
    }
    e = orig_readdir(d);
  }
  orig_closedir(d);
  if (d_ino == -1) {
    puts("Failed to determine root directory inode number");
    exit(EXIT_FAILURE);
  }
}

Compile it using

gcc -ldl -shared -fPIC snpslmd-hack.c -o snpslmd-hack.so

Use wrapper script instead of original snpslmd:

#!/bin/sh
export LD_PRELOAD=snpslmd-hack.so
exec /usr/bin/snpslmd_bin "$@"

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-07-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。