链接到打开的inode w / o链接左:怎么样? [英] Linking to an opened inode w/o links left: how?

查看:74
本文介绍了链接到打开的inode w / o链接左:怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在为现有程序编写C语言包装器。包装器

维护一个运行文件,该文件是为程序的一次调用而创建的,并且为另一个调用而被删除。我做出最后一个动作的想法

傻瓜式是这样的:


- 通过stat()保存运行文件状态

- 打开运行文件进行阅读

- unlink()它

- 对要启动的程序执行execv()

- 如果execv()失败,恢复由stat()

保存的inode的链接并关闭运行文件

- 否则,运行文件在完成时被删除该程序

开始


但是,link()只允许通过引用另一个链接添加链接

给定的inode,而不是inode本身。还有另外一种方法,或者

我应该忘记这个方案,只需用fork()来启动

程序吗?


谢谢,


Jan Stap

解决方案

Jan Stap< js ****** *@stap.mdcc.cx>潦草地写道:


我在C中为现有程序编写一个包装器。包装器
维护一个运行文件,该文件是为程序的一次调用而创建的,并且被另一个文件删除。我做出最后一个动作的想法是傻瓜式的:
- 通过stat()保存运行文件状态


不是标准的C函数。

- 打开运行文件进行阅读
- unlink()它


不是标准的C函数。

- 对要启动的程序执行execv() - 如果execv()失败,则恢复由stat()保存的inode的链接


这些都不是是一个标准的C函数。

并关闭运行文件
- 否则,程序完成后删除运行文件
启动
但是,link()只允许通过引用给定inode的另一个链接而不是inode本身来添加链接。还有另外一种方法,或者我应该忘记这个方案,只需用fork()来启动
程序吗?




link( )和fork()不是标准的C函数。


为了清楚所有,comp.unix.programmer是一个更好的地方问

about这个。


-

/ - Joona Palaste(pa*****@cc.helsinki.fi)------- ------芬兰-------- \

\-- http://www.helsinki.fi/~palaste ---------------------规则! -------- /

这不是最胖的生存,而是适者生存。

- Ludvig von Drake


我想这是错的,而不是我的事,但不是* nix写的

C因此所有那些东西是C的子集?

ML


" Joona I Palaste"


我正在用C编写现有程序的包装器。包装器
维护一个运行文件,该文件是为程序的一次调用而创建的,并且被另一个文件删除。我做出最后一个动作的想法是傻瓜式的:


- 通过stat()


不是标准的C函数。

- 打开运行文件进行阅读
- unlink()它



不是标准的C函数。

- 对要启动的程序执行execv()
- 如果execv()失败,则恢复到inode的链接由stat()保存



这些都不是标准的C函数。

并关闭运行文件
- 否则,程序完成后删除运行文件
启动


但是,link()只允许通过引用另一个链接添加链接
到给定的inode,而不是inode本身。还有另一种方法,或者我应该忘记这个方案,只需使用fork()来启动
程序吗?



link()和fork( )不是标准的C函数。

为了清楚起来,comp.unix.programmer是一个更好的地方询问这个。

-
/ - Joona Palaste(pa*****@cc.helsinki.fi)-------------芬兰-------- \
\ - http://www.helsinki.fi/~palaste ---------------------规则! -------- /
这不是最胖的生存,而是适者生存。
- Ludvig von Drake



Marcus Lessard< sp **** @ spam.com>潦草地写道:

我猜这是错的,而不是我的事,但是不是用N / C编写的,所以那些东西都是C的子集? / blockquote>


Unix *是用C语写的,是的。但是这并没有神奇地制作所有这些C. b $ ba的子集。我使用的网络浏览器,Mozilla,也是用C语言写的,

但是你不要看到我提问如何配置HTTP标头

Mozilla正在这里发送,是吗?

如果你的意思是Unix定义的C API是其子集C,

这也错了。因为它是C的一个子集,所以必须在所有具有C实现的平台上工作。这显然是假的。


PS。请不要顶尖。谢谢。


-

/ - Joona Palaste(pa*****@cc.helsinki.fi)------- ------芬兰-------- \

\-- http://www.helsinki.fi/~palaste ---------------------规则! -------- /

当一个男人对一个女人说脏话时,那就是性骚扰。当一个女人对男人说脏话时,那是'每分钟14.99美元+本地电话费!'

- Ruben Stiller


Hi,

I am writing a wrapper in C for an existing program. The wrapper
maintains a run file that is created for one invocation of the program
and is removed for another. My idea of making the last action
fool-proof is like this:

- save the run file status via stat()
- open the run file for reading
- unlink() it
- do an execv() on the program to be started
- if the execv() fails, restore the link to the inode saved by stat()
and close the run file
- otherwise, the run file is deleted upon completion of the program
started

However, link() only allows adding a link by referring to another link
to a given inode, not to the inode itself. Is there another way, or
should I forget about this scheme and just use a fork() to start the
program?

Thanks,

Jan Stap

解决方案

Jan Stap <js*******@stap.mdcc.cx> scribbled the following:

Hi, I am writing a wrapper in C for an existing program. The wrapper
maintains a run file that is created for one invocation of the program
and is removed for another. My idea of making the last action
fool-proof is like this: - save the run file status via stat()
Not a standard C function.
- open the run file for reading
- unlink() it
Not a standard C function.
- do an execv() on the program to be started
- if the execv() fails, restore the link to the inode saved by stat()
Neither of these is a standard C function.
and close the run file
- otherwise, the run file is deleted upon completion of the program
started However, link() only allows adding a link by referring to another link
to a given inode, not to the inode itself. Is there another way, or
should I forget about this scheme and just use a fork() to start the
program?



link() and fork() are not standard C functions.

Just to be clear and all, comp.unix.programmer is a better place to ask
about this.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It''s not survival of the fattest, it''s survival of the fittest."
- Ludvig von Drake


I guess this is both wrong, and not my business, but wasn''t *nix written in
C and therefore all that stuff is a subset of C?

ML

"Joona I Palaste"

Hi,


I am writing a wrapper in C for an existing program. The wrapper
maintains a run file that is created for one invocation of the program
and is removed for another. My idea of making the last action
fool-proof is like this:


- save the run file status via stat()



Not a standard C function.

- open the run file for reading
- unlink() it



Not a standard C function.

- do an execv() on the program to be started
- if the execv() fails, restore the link to the inode saved by stat()



Neither of these is a standard C function.

and close the run file
- otherwise, the run file is deleted upon completion of the program
started


However, link() only allows adding a link by referring to another link
to a given inode, not to the inode itself. Is there another way, or
should I forget about this scheme and just use a fork() to start the
program?



link() and fork() are not standard C functions.

Just to be clear and all, comp.unix.programmer is a better place to ask
about this.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It''s not survival of the fattest, it''s survival of the fittest."
- Ludvig von Drake



Marcus Lessard <sp****@spam.com> scribbled the following:

I guess this is both wrong, and not my business, but wasn''t *nix written in
C and therefore all that stuff is a subset of C?



Unix *was* written in C, yes. But this doesn''t magically make all this
a subset of C. The web browser I use, Mozilla, was also written in C,
but you don''t see me asking questions how to configure the HTTP headers
that Mozilla is sending here, do you?
If you are meaning that the C API that Unix defines is a subset of C,
that is also wrong. For it to be a subset of C it would have to work on
all platforms that have a C implementation. This is provably false.

PS. Please don''t top-post. Thanks.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"When a man talks dirty to a woman, that''s sexual harassment. When a woman talks
dirty to a man, that''s 14.99 per minute + local telephone charges!"
- Ruben Stiller


这篇关于链接到打开的inode w / o链接左:怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆