最近一直在研究Glusterfs3.3.1,当因需在代码中加入system(cmd)调用时,编译器提示error:attempt to use poisoned ”system",即试图使用有毒的system调用,首先我检查了一遍代码,其实就是一个system调用。排除了代码编写错误。然后我突然想起了system调用需要慎用的,调用system的进程在调用system未返回时可能会阻塞而且会忽略某几种信号。我接下来在网上查了查资料,确实system调用时可能会有诸多问题。
我在Glusterfs的源码文件./libglusterfs/src/compat.h也找到了这句话:#pragma GCC poison system popen,所以,当我再代码中加入system,popen等调用时,编译器就会报错,禁止编译。
问题又来了.我是自己编码实现类system的功能还是Glusterfs另有解决的办法的?显然,Glusterfs的研发团队足够的聪明,我们想的他们都替我们想好了,哈哈。在libglusterfs/src/下有run.h,实现了类system调用的接口runcmd等,且 使用非常灵活。run.h接口声明如下:
/*
Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
This file is part of GlusterFS.
This file is licensed to you under your choice of the GNU Lesser
General Public License, version 3 or any later version (LGPLv3 or
later), or the GNU General Public License, version 2 (GPLv2), in all
cases as published by the Free Software Foundation.