system() fails


 
Thread Tools Search this Thread
Top Forums Programming system() fails
# 1  
Old 07-30-2008
system() fails

Hi,

I have the following code which fails with return value 1.

sprintf(tmp, "rm -rf %s/* 2>/dev/null\n", dest);
rc = system( tmp );
rc is 1

The files exist and the paths are correct. I can do a manual copy but the application fails. All the calls to system() function fail with the same return code. If I restart the application, this works fine.

On running truss, following is the output.
ioctl is failing with EIO error (Some Physical I/O error).

What could be the reason for this failure?

Thanks!

8287: 14.1724 vfork() = 16381
16381: 14.1724 vfork() (returning as child ...) = 8287
16381: 14.1777 lwp_sigmask(SIG_SETMASK, 0x00020000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
16381: 14.1778 lwp_sigmask(SIG_SETMASK, 0x00020000, 0x00000000) = 0x00020000 [0x00000000]
8287: 14.1783 lwp_sigmask(SIG_SETMASK, 0x00020000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
16381: 14.1789 execve("/bin/sh", 0xFFBFAA84, 0xFFBFDDAC) argc = 3
16381: rm -rf /usr/Dir_cp/* 2>>/usr/logs/audit080725
.
.
.
16381: 14.1881 getuid() = 110 [110]
16381: 14.1882 getuid() = 110 [110]
16381: 14.1882 getgid() = 110 [110]
16381: 14.1882 getgid() = 110 [110]
16381: 14.1884 ioctl(2, TCGETA, 0xFFBFDB8C) Err#5 EIO
16381: 14.1884 Received signal #1, SIGHUP [caught][/B]
16381: 14.1886 schedctl() = 0xFF26C000
16381: 14.1886 sigfillset(0xFF36FB20) = 0
16381: 14.1887 lwp_sigmask(SIG_SETMASK, 0x00020001, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
16381: 14.1887 lwp_sigmask(SIG_SETMASK, 0x00020000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
16381: 14.1888 sigaction(SIGHUP, 0xFFBFD5C0, 0xFFBFD660) = 0
16381: 14.1888 kill(16381, SIGHUP) = 0
16381: 14.1889 Received signal #1, SIGHUP [default]
16381: siginfo: SIGHUP pid=16381 uid=110

8287: 14.1893 waitid(P_PID, 16381, 0xFFBFA928, WEXITED|WTRAPPED) = 0
8287: 14.1894 sigaction(SIGINT, 0xFFBFA968, 0x00000000) = 0
8287: 14.1895 sigaction(SIGQUIT, 0xFFBFA968, 0x00000000) = 0
8287: 14.1895 schedctl() = 0xFED14000
8287: 14.1896 lwp_sigmask(SIG_SETMASK, 0x00020000, 0x00000000) = 0xFFBFFEFF [0x0000FFFF]
# 2  
Old 07-30-2008
Do you have permission to remove those files?
I don't know how your code looks like, but you can restrict your code to some lines to try it out, something like:

Code:
#include <stdio.h>

int main()
{
  char tmp[128];
  char *dest = "/usr/Dir_cp";
  int rc;

  sprintf(tmp, "rm -rf %s/* 2>/dev/null\n", dest);
  printf("Command : %s\n", tmp);

  rc = system(tmp);
  printf("Exit code system command: %d\n", rc);

}

Regards
# 3  
Old 07-30-2008
what is the value of dest ?
# 4  
Old 07-30-2008
This ioctl is failing with a control terminal error as to be expected from a redirection inside the child without a controlling terminal with normal attributes for the exec'd shell.
If I may ask: Why would you want to use system for this and not unlink()?
# 5  
Old 07-31-2008
Franklin52,

Sufficient permissions are present to remove the files, copy etc.
I did capture, tmp and rc,
tmp is
rm -rf /usr/Dir_cp/* 2>>/usr/logs/audit080725
rc is 1.

This occurs intermittently and application restart solves the issue.

Sivaswami,
Dest is "/usr/Dir_cp"

ramen_noodle,

I think unlink is used for removing linked files.
system() is used not only for remove operation but for copy etc in this application.
# 6  
Old 07-31-2008
ramen is telling you about 3-4 things.

The command run system() does not have stderr to redirect to without causing an error.
That is your error.

unlink() and remove() are how you delete files in UNIX/C. Not system(). try man unlink before you decide it is for removing what you seem to think a link might be. A link is a directory entry that points to an inode, by the way. That is usually an actual file.

Finally he is telling you that system() is a bad choice. Don't use it for things you can do in C. There are a lot of reasons for this: from security to performance, to 'why not just use shell instead of C?'

And next to last, you should be using the macros in sys/wait.h to test the return code of system() - you should consider: WIFEXITED(), WEXITSTATUS(), and so on. There are reasons for this, like the LSB of the return code, only, has meaning. You need to ignore the other bytes.

And last - don't you imagine that maybe all of the commands like: cp, mv, rm -- are written in C to start with? And that some of them are system calls, so that running them in C is an order of magnitude more efficient. By the way what system call do suppose rm uses? Hint: ramen named it.
# 7  
Old 08-01-2008
jim mcnamara,

I didn't know much about this, so couldn't get what ramen_noodle was pointing to, thanks for elaborating.
So rm uses unlink.

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Cloning a system via mksysb backup from one system and restore to new system

Hello All, I am trying to clone an entire AIX virtual machine to a new virtual machine including all partitions and OS.Can anyone help me on the procedure to follow? I am not really sure on how it can be done.Thanks in advance. Please use CODE tags for sample input, sample output, and for code... (4 Replies)
Discussion started by: gull05
4 Replies

2. HP-UX

shl_load fails

Hi, I have written a simple program of 2 lines in C to load a library using SHL_LOAD. It fails with error "/usr/lib/hpux32/dld.so: Unable to find library 'xyz.sl'. Load failure for library , ERRNO = 2" Shlib_PATH,LD_LIBRARY_PATH,PATH,LD_PRELOAD are set correctly and library exists on the... (0 Replies)
Discussion started by: ashwinichavan
0 Replies

3. Programming

realloc() fails

Not sure in which forum to post this. I'm trying here, in Programming. I'm working on a PC with Intel Duo processor & 2GB of ram. OS is Ubuntu 10.04. I'm having problems with a C++ program that makes extensive use of realloc(). It happens that as soon as the overall memory allocated(OS +... (14 Replies)
Discussion started by: mamboknave
14 Replies

4. Solaris

smf fails to mount svc:/system/filesystem/usr:default

http://i44.tinypic.com/2cmq7vn.jpg Please help me on this issue i'm using solaris on vmware x86 even i runed fsck on root disk like 'fsck -Y /dev/rdsk/c0d0s0 ' but again after reboot it is going to maintanance mode reply soon (6 Replies)
Discussion started by: knl.sundeep
6 Replies

5. UNIX for Advanced & Expert Users

why script fails sometime?

Hi, I am trying to run a shell script on solaris,some time it works fine and some times it fails unexpectedly. There is a script called "autostart.sh" which automatically starts the Application server but some times the script fails to strat the application server. can anyone tell me what... (10 Replies)
Discussion started by: tahir23
10 Replies

6. UNIX for Advanced & Expert Users

make fails...

Hi When im trying to do make --version and make --help in HP-UX it throws error Make: Unknown flag argument -. Stop. a soft link is present in this directory /usr/bin/make and hard link is in /usr/ccs/bin/make what could be the reason can any1 ..please tell me how to solve this... (1 Reply)
Discussion started by: vasanthan
1 Replies

7. Shell Programming and Scripting

Need to know why Perl fails.

Hello . Would really like to know why this code fails . I need to edit both the QUESNO : and <\p> tag at the same time . open(TEXT, "<20030211.txt") || die ("Cannot open the text files"); while (<TEXT>) { if ($_ =~ m/QUESNO :/) { if ($_ =~ m/<\/p>/) { print ($_); ... (0 Replies)
Discussion started by: whatsup
0 Replies

8. AIX

mkvg fails

# mkvg -y temp_vg hdisk5 0516-1254 mkvg: Changing the PVID in the ODM. 0516-1207 mkvg: An invalid physical volume ID been detected on hdisk5. 0516-862 mkvg: Unable to create volume group. ??? What do I do? AIX 4.3.3 I have seen something like this before but I don't remember the... (2 Replies)
Discussion started by: osee
2 Replies

9. UNIX for Advanced & Expert Users

System Fails

Hi Exprts, There's a critical problem on one of the Workstations that the client reports every morning their system is down. It seems there's no power failure, as in the next startup the file systems are stable ,so i checked the "messages" file , the last line which i got before failure is :... (2 Replies)
Discussion started by: nikk
2 Replies

10. Programming

stat() fails!!! what can i do?

Hi all, I can not understand why my stat() function fails all the time when function tries to go recursevly. Someone suggested that it might be poiter problem. Please, look up my code at: www.donnelly.cc.ks.us/readdir_test.c. How can i solve this problem? Any suggestion are welcome! Thank you... (3 Replies)
Discussion started by: solvman
3 Replies
Login or Register to Ask a Question