a issue with dup2


 
Thread Tools Search this Thread
Top Forums Programming a issue with dup2
# 1  
Old 02-04-2009
a issue with dup2

Hi,

i have in one program such a pice of code

................

static int old_stderr_handle = -1;
static int old_stdout_handle = -1;

log_handle = open(log_file_name,O_CREAT|O_RDWR,932);

old_stderr_handle = dup(STDERR_FILENO);

if (dup2(log_handle,STDERR_FILENO) < 0)
{
// print error
}

old_stdout_handle = dup(STDOUT_FILENO);

if (dup2(log_handle,STDOUT_FILENO) < 0)
{
// print error
}
.....

close ( old_stderr_handle );
close ( old_stdout_handle);

I build this program with Insure ( a tool ) after this i run it and in the log file
i found a message like

(Thread 0) **USER_ERROR**
>> if (dup2(log_handle,STDERR_FILENO) < 0)

Attempt to implicitly close Insure++ internal file descriptor 2 in dup2() ignored


**Memory corrupted. Program may crash!!**

Can somebody explain why? Smilie

thanks.

Last edited by vovan; 02-04-2009 at 10:29 AM.. Reason: some sintax errors fixed
# 2  
Old 02-05-2009
This Insure program is expressly preventing you from using dup2 to redirect stderr. Perhaps it has its own methods of redirecting logfiles that you're supposed to use instead? Why it thinks memory is corrupted, I don't know, it may be unrelated to the redirection and provoked by code below it you didn't post.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

C++ stuck with dup2 and pipe

What this code should do is: there are parent.cpp and child.cpp. Parent will send whatever is in the buffer to child and child will send back whatever received to parent. I do not know what I am doing wrong. I am confused what is missing in the parent and what else I should include into the child.... (1 Reply)
Discussion started by: ramono
1 Replies

2. Shell Programming and Scripting

Troubles with pipes, fork, and dup2

I want to execute metasploit by two pipes to communicate with it, but I have troubles with that communication. When I run my program, I get this error: "stty: standard input: Inappropriate ioctl for device" and I don't receive the metasploit promt. just select an exploit. This is my code:... (2 Replies)
Discussion started by: dano88
2 Replies

3. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

4. UNIX for Advanced & Expert Users

Dup2 - for file descriptor opened by a different process

is it possible to duplicate file descriptors(opened by a different process) with the help of dup or dup2. the two process do not share parent child relationship as well. (2 Replies)
Discussion started by: replytoshishir
2 Replies

5. Shell Programming and Scripting

Need assistance with a file issue and a terminal issue

Hello everyone, I'm in need of some assistance. I'm currently enrolled in an introductory UNIX shell programming course and, well halfway through the semester, we are receiving our first actual assignment. I've somewhat realized now that I've fallen behind, and I'm working to get caught up, but for... (1 Reply)
Discussion started by: MrMagoo22
1 Replies

6. Programming

Implementation of dup2

Hi all,I'm reading <Advanced programming in the UNIX environment>,that book asked the reader to implement a function which has same functions with dup2 without calling fcntl.Could anyone give me a tip?Any help will be appreciated.:) (8 Replies)
Discussion started by: homeboy
8 Replies

7. UNIX for Dummies Questions & Answers

ISSUE and ISSUE.NET files

In LINUX(CentOS, RedHat) is there a way to have the banner statement appear before the logon instead of after the logon? In UNIX and Windows the banner appears before a person actually logs on, what I'm seeing in LINUX is that it appears after the login(ftp, telnet, SSH). Thanks (0 Replies)
Discussion started by: ejjones
0 Replies

8. UNIX for Advanced & Expert Users

dup2 filedescriptor redirecting output

int redirect() { int fd,rc; fd = open("sample.DAT",O_CREAT | O_RDWR , 00777 ); rc = dup2(fd , 1 ) ; close (fd ); return 0; } I used the above to redirect all the cout statements to sample.DAT. process is redirecting the output and I had two questions 1. All stdout/cout statements... (2 Replies)
Discussion started by: satish@123
2 Replies

9. Shell Programming and Scripting

Unix Arithmatic operation issue , datatype issue

Hi, I have a shell scripting. This will take 7 digit number in each line and add 7 digit number with next subsequent lines ( normal addition ). Eg: 0000001 0000220 0001235 0000022 0000023 ........... ......... ........ Like this i am having around 1500000 records. After adding... (23 Replies)
Discussion started by: thambi
23 Replies

10. Programming

Understanding the purpose of dup/dup2

I'm having difficulty understanding the purposes of using dup/dup2 when involving forks. for example, if we call fork() once, that is, we are creating a child process. In what cases would we need to use dup or dup2 to duplicate the file descriptors for standard output and standard error? What... (1 Reply)
Discussion started by: Yifan_Guo
1 Replies
Login or Register to Ask a Question