What can cause unzip command returning -1 in my script?

I am running unzip via a call system()

in my C ++ code in the following format:

/usr/bin/unzip -o -q /<my_path_to_zip_file>/cfg_T-KTMAKUCB.zip -d /<my_path_to_dest>/../

      

This will be successful in almost 90% of cases. I can't figure out what could be causing the timing to fail with a return code of -1. Any ideas?

+3


source to share


1 answer


According to my local man system

,

Return value -1 on error (e.g. fork (2) failed) and return status otherwise.

and the POSIX spec says,

If the child process cannot be created, or if the exit status for the command language interpreter cannot be obtained, system () should return -1 and set errno to indicate an error



Finally, the manpage for unzip

lists various return codes, but -1 is not.

If the command itself cannot return -1, the problem is probably with the initial fork

/ exec

, due to something like a system-wide or user-wide limit (memory exhausted; process table full; max processes, open files, or VM size limit for user, and etc., etc.).

You have to check errno

when it system

fails. Doing all of this in strace -f

will also show what will happen.

+8


source







All Articles