Operating System - HP-UX
1753939 Members
9031 Online
108811 Solutions
New Discussion

ioscan -m lun hangs on HP-UX 11.31.1109

 
zaobao_0
Occasional Visitor

ioscan -m lun hangs on HP-UX 11.31.1109

I could run /usr/bin/sh -c ioscan -m lun from console, it could get result.

I also get result through function execl("/usr/bin/sh", "sh", "-c", "ioscan -m lun", 0);

 

While when I call execl with child process, it hangs under SD2 with over 10 file system but it could work in most IA64 machine and it worked before configure with many file system.

 

Here is source code, any idea?

bool getCmdOutput(std::string& strOutput, const std::string& strCmd)
{
    strOutput = "";

    int pipe_fd[2] = {0};
    pipe(pipe_fd);

    pid_t pid = fork();
    if (-1 == pid)
    {
        return false;  // error
    }

    if (0 == pid)     // child
    {
         close(pipe_fd[0]);
         dup2(pipe_fd[1], STDOUT_FILENO);
         close(pipe_fd[1]);

         execl("/usr/bin/sh", "sh", "-c", strCmd.c_str(), 0);
         exit(0);
    }
    else
    {
		int stat_loc;
        wait(&stat_loc);
        close(pipe_fd[1]);
        char buffer[BUFFER_SIZE];
        memset(buffer, 0, sizeof(buffer));

        while(0 < read(pipe_fd[0], buffer, BUFFER_SIZE-1))
            strOutput += buffer;

        close(pipe_fd[0]);
    }

    return true;
}

 

P.S. This thread has been moved from HP-UX > System Administration to HP-UX > languages - HP Forums Moderator

2 REPLIES 2
zaobao_0
Occasional Visitor

Re: ioscan -m lun hangs on HP-UX 11.31.1109

here is the information from ioscan core file:


Core was generated by `ioscan'.

#0 0x401f090:0 in _write_sys+0x30 ()
(gdb) bt
#0 0x401f090:0 in _write_sys+0x30 ()
#1 0x401ef90:0 in write+0x1b0 ()
#2 0x401ec20:0 in _xflsbuf+0x220 ()
#3 0x401e910:0 in __fflush_unlocked+0x2d0 ()
#4 0x401e550:0 in do_exitcu+0x50 ()
#5 0x401da40:0 in ___stdio_unsup_1+0x2830 ()
#6 0x401b1d0:0 in _exitcu+0x30 ()
#7 0x401b170:0 in __exit_handler+0x140 ()
#8 0x4077df0:0 in EM_mark_BOS+0x50 ()
(gdb)

 

 

Core was generated by `sh'.

(no debugging symbols found)...(no debugging symbols found)...
(no debugging symbols found)...#0 0x60000000c0369310:0 in _waitpid_sys+0x30 ()
from /usr/lib/hpux32/libc.so.1
(gdb) bt
#0 0x60000000c0369310:0 in _waitpid_sys+0x30 () from /usr/lib/hpux32/libc.so.1
#1 0x60000000c03813e0:0 in waitpid+0x80 () from /usr/lib/hpux32/libc.so.1
#2 0x402b010:0 in job_wait+0x4b0 ()
#3 0x4043c00:0 in xec_switch+0x3fc0 ()
#4 0x403fb90:0 in sh_exec+0x6e0 ()
#5 0x4087b70:0 in exfile+0xc80 ()
#6 0x400ffe0:0 in main+0xc80 ()
(gdb) q

Dennis Handly
Acclaimed Contributor

Re: ioscan -m lun hangs on HP-UX 11.31.1109 (pipe full)

>I also get result through function execl("/usr/bin/sh", "sh", "-c", "ioscan -m lun", 0);

 

You shouldn't be calling sh, but invoke ioscan directly.  You do need to tokenize the parms.

 

You have created a deadlock.  You are waiting for Godot.  :-)

wait(&stat_loc);   // the pipe isn't big enough to hold all of the data!

close(pipe_fd[1]);

read the pipe ...

 

This is in the wrong order, try:

close(pipe_fd[1]);

read the pipe ...

close(pipe_fd[0]);

wait(&stat_loc);