Linking to an opened inode w/o links left: how?

J

Jan Stap

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
 
J

Joona I Palaste

Jan Stap said:
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.
 
M

Marcus Lessard

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"
 
J

Joona I Palaste

Marcus Lessard said:
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 ([email protected]) ------------- 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
 
M

Mark Gordon

On Mon, 10 Nov 2003 12:46:39 -0500

Please don't top post. I've fixed it and if you want to know why do a
google search. We've already been through all the arguments.
"Joona I Palaste"

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?

No. The various Unix derivative are written in C + lots of extensions +
assembler. It is not possible to write a complete operating system
entirely in C.

The C language and standard library are defined by K&R1 (for
pre-standard) and the ANSI & ISO standards (ANSI predates ISO slightly)
for anything since 1989.

Here we only discuss C, not the *nix API or any other API or extensions.
 
T

Thomas Matthews

Marcus said:
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

By your logic, any program written in C is a subset of the C language.
If I write a program to drive a vending machine using the C language,
then the vending machine must be a subset of the C language.
Nope, wrong.

If I use a tool to build a house, then the house is a subset of
the tool. {Replace tool with hammer, drill, ruler, etc.}
Hmm, doesn't make sense either.

The _standard_ C language is all that is described by the ANSI/ISO
standard. Nothing more. Languages are tools used to create
programs.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
M

Marcus Lessard

Fair enough.

"Thomas Matthews" > The _standard_ C language is all that is described by
the ANSI/ISO
 
M

Marcus Lessard

Not a C question but since you said it would you mind explaining it?

ejd

"Joona I Palaste"

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

Joona I Palaste

Marcus Lessard said:
Not a C question but since you said it would you mind explaining it?

You mean the bit about not top-posting? Sure.
It has to do with how you write your reply to the post you are quoting.
In bottom-posting, the quoted article goes first, the reply goes next.
In top-posting, the reply goes first, the quoted article goes next.

Example of bottom-posting:
-----------------------------------------------------------------------
Foo said:
Is this true?
Yes.
-----------------------------------------------------------------------


Example of top-posting:
-----------------------------------------------------------------------
Yes.
Foo said:
Is this true?
 
M

Marcus Lessard

Joona I Palaste said:
You mean the bit about not top-posting? Sure.
It has to do with how you write your reply to the post you are quoting.
In bottom-posting, the quoted article goes first, the reply goes next.
In top-posting, the reply goes first, the quoted article goes next.

Ahh. I wondered if there was a preference on that. Thanks.

ML
 
C

Chris Torek

The reasons why top-posting is bad have been explained here several
times in the last couple of days. Read the newsgroup a little more to
find them.

I have an example I came up with, but I like this one (apparently
written by Clifton Sharp; see
<http://groups.google.com/[email protected]>)
even better:

"I'll see you at Linda's wedding."
"Well, see ya soon."
"Congratulations!"
"Ten thousand a year."
"How much?"
"Got a really big raise this time."
"Sorry to hear it. How's the job?"
"She's not feeling well. Flu, I think."
"Same as ever. How's yours?"
"How's your wife?"
"They painted her purple. They should call her the Prune Fart now."
"Good. Did you hear what Martin and Sheila did to the Sea Breeze?"
"Good, and you?"
"Bill! How the heck are you?"

One's goal in writing in a newsgroup is -- or at least should be,
I believe -- communicating with others, and carefully-edited quotes
interspersed with replies should help one achieve that.
 
J

Joona I Palaste

I have an example I came up with, but I like this one (apparently
written by Clifton Sharp; see
<http://groups.google.com/[email protected]>)
even better:
"Got a really big raise this time."
"Sorry to hear it. How's the job?"

Sorry to hear someone's got a big raise? Isn't that carrying envy a
bit too far?
"How's your wife?"
"They painted her purple. They should call her the Prune Fart
now."

Painted his wife purple? Why? For her to pass as a Cataxxan?

(Yes, I know what it really means. I was just having fun.)
 
M

Marcus Lessard

"Chris Torek"
One's goal in writing in a newsgroup is -- or at least should be,
I believe -- communicating with others, and carefully-edited quotes
interspersed with replies should help one achieve that.
--

Us "top-posters" are not insane or stupid...we think that we are saving you
the trouble of scrolling down to the new material. I honestly wouldn't have
imagined that it was a big deal, but when in Rome post as the Romans do.

ML
 
J

Joona I Palaste

Marcus Lessard said:
"Chris Torek"
Us "top-posters" are not insane or stupid...we think that we are saving you
the trouble of scrolling down to the new material. I honestly wouldn't have
imagined that it was a big deal, but when in Rome post as the Romans do.

If you find it tiresome to scroll though the quoted material, there is
too much quoted material. Bottom-posting goes hand-in-hand with
selective snipping.
 
A

Alan Balmer

"Chris Torek"

Us "top-posters" are not insane or stupid...we think that we are saving you
the trouble of scrolling down to the new material. I honestly wouldn't have
imagined that it was a big deal, but when in Rome post as the Romans do.

ML
Scrolling down to try to figure out what you're replying to is not an
improvement.
 
J

Joona I Palaste

Alan Balmer said:
Scrolling down to try to figure out what you're replying to is not an
improvement.

Indeed, I have seen top-posted articles where the reply starts with
something like "But in that case..." while there are several points in
the original article, not related to each other. "In *which* case?" I
have to ask myself. Of course it was obvious to the responder when he
read the original article but I can't read the responder's mind.
 
E

E. Robert Tisdale

Marcus said:
Us "top-posters" are not insane or stupid.
We think that
we are saving you the trouble of scrolling down to the new material.
I honestly wouldn't have imagined that it was a big deal,
but when in Rome post as the Romans do.

The point is that
we don't want you to quote the article to which you are responding.
Instead, snip out everything that is irrelevant to your response.
Don't complain about misspelled words, poor grammar, punctuation
or capitalization. Quietly fix it if it bothers you.
Paraphrase as necessary to best represent *your* understanding
of what was said in the article to which you are responding.
Subscribers can consult the archives of previous messages
if they feel that you have misrepresented what was actually said.
If the article to which you are responding makes multiple points,
try to isolate each point and insert your response immediately
after each point.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top