OSX 从服务启动时代码签名无效异常

OSX Code Signature Invalid Exception when launched from Service on

MyApp 是一个带有 Files & Folders 服务功能的 sonboxed 应用程序。当我正常启动时,应用程序工作正常,但当它被服务调用时,它会使 Finder 几秒钟没有响应然后崩溃

控制台日志给出以下崩溃

Process:               MyApp [4453]
Path:                  /Users/USER/Library/Developer/Xcode/Archives/2015-02-02/MyApp 02-02-2015 6.02 pm.xcarchive/Products/Applications/MyApp.app/Contents/MacOS/MyApp
Identifier:            com.Company.MyApp
Version:               ???
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           MyApp [4453]
User ID:               501

Date/Time:             2015-02-05 11:06:20.391 +0500
OS Version:            Mac OS X 10.10.2 (14C109)
Report Version:        11
Anonymous UUID:        2B8F252E-AA04-6181-CCE8-379AB367F5EE


Time Awake Since Boot: 3600 seconds

Crashed Thread:        0

Exception Type:        EXC_CRASH (Code Signature Invalid)
Exception Codes:       0x0000000000000000, 0x0000000000000000

kernel messages:

VM Regions Near 0x7fff799630a8 (cr2):
    __LINKEDIT             00007fff63e95000-00007fff63ea9000 [   80K] r--/rwx SM=COW  /usr/lib/dyld
--> Submap                 00007fff70000000-00007fff80000000 [256.0M] r--/rwx SM=PRV  process-only VM submap
    unused shlib __DATA    00007fff775f9000-00007fff79b9c000 [ 37.6M] rw-/rw- SM=COW  system shared lib __DATA not used by this process

Thread 0 Crashed:
0   dyld                            0x00007fff63e26000 _dyld_start + 0

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x000000000000000d  rbx: 0x0000000000000000  rcx: 0x0000000000000000  rdx: 0x0000000000000000
  rdi: 0x0000000000000000  rsi: 0x0000000000000000  rbp: 0x0000000000000000  rsp: 0x00007fff586a1aa8
   r8: 0x0000000000000000   r9: 0x0000000000000000  r10: 0x0000000000000000  r11: 0x0000000000000000
  r12: 0x0000000000000000  r13: 0x0000000000000000  r14: 0x0000000000000000  r15: 0x0000000000000000
  rip: 0x00007fff63e26000  rfl: 0x0000000000000201  cr2: 0x00007fff799630a8

Logical CPU:     0
Error Code:      0x020000f4
Trap Number:     133


Binary Images:
    0x7fff63e25000 -     0x7fff63e5b837  dyld (???) <65DCCB06-339C-3E25-9702-600A28291D0E> /usr/lib/dyld

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 5435
    thread_create: 0
    thread_set_state: 93

VM Region Summary:
ReadOnly portion of Libraries: Total=300K resident=300K(100%) swapped_out_or_unallocated=0K(0%)
Writable regions: Total=8416K written=0K(0%) resident=12K(0%) swapped_out=0K(0%) unallocated=8404K(100%)

REGION TYPE                      VIRTUAL
===========                      =======
STACK GUARD                        56.0M
Stack                              8192K
VM_ALLOCATE                           8K
__DATA                              228K
__LINKEDIT                           80K
__TEXT                              220K
mapped file                         872K
shared memory                         4K
===========                      =======
TOTAL                              65.4M

这清楚地表明它存在一些代码签名问题

Exception Type: EXC_CRASH (Code Signature Invalid)

下一个自然步骤应该是检查它的签名所以我使用了 spctl 并且它 returns

$ sudo spctl --assess --verbose=4 /Applications/MyApp.app
/Applications/MyApp.app: accepted
source=Developer ID

我不知道这里缺少什么。

更新


我在我的机器上创建了一个新帐户和 运行 应用程序,但没有得到任何代码签名 error/exception。

所以这与用户帐户的状态有关,或者可能是 OSX 的错误。

我怀疑您的服务正在启动您的应用程序的未签名副本,该副本位于您的开发目录中。

您的第一次崩溃表明路径是:

/Users/USER/Library/Developer/Xcode/Archives/2015-02-02/MyApp 02-02-2015 6.02 pm.xcarchive/Products/Applications/MyApp.app/Contents/MacOS/MyApp

您发布的 spctl 命令检查了以下签名:

/Applications/MyApp.app.  

可能是当您以开发者帐户登录时,该服务从您的 Xcode/Archive 目录中获取未签名的应用程序并失败。在 /Applications 中手动启动已安装的版本,或对该版本进行 spctl 检查,都会成功。当使用不同的用户帐户时,该服务可能会在 /Applications 中找到该版本。