Commit Graph

23 Commits

Author SHA1 Message Date
tg
942035921c Pass arguments via a resonse file if executing a child fails
Command line length limit of OS/2 is 32KiB. If the total length of
all arguments is larger than this limit, it's needed to use a
response file.

Previously, the total length calculation was simply to add length of
all arguments. However, this result was not match with real length of
arguments, which are passed to child processes with OS/2 APIs.

Because conversion methods of arguments from libc to OS/2 APIs are
different depending on libc.

For example, kLIBC inserts its signature to an argument list. In
addition, it passes arguments with a leading space like:

    arg0
     kLIBC signature
     arg1
     arg2
     ...

Whereas, EMX just distinguishes arg0 and others like:

    arg0
    arg1 arg2 arg3 ...

After all, simple sum of a length of arguments are not correct.

The better way is to try to execute a child process, and to retry with
a response file if it fails due to arguments-too-long.

This has been found while doing 'bootstrap', especially 'autoreconf'
in coreutils git repo. It stops with:

    autom4te: /usr/local/bin/m4: Invalid argument

From: KO Myung-Hun <komh@chollian.net>
2017-12-22 16:41:42 +00:00
tg
d93bd77f28 Set stdin to text mode before executing child processes
Normal OS/2 programs expect that standard IOs, especially stdin,
are opened in text mode at the startup. By the way, on OS/2 kLIBC
child processes inherit a translation mode of a parent process.
As a result, if stdin is set to binary mode in a parent process,
stdin of child processes is opened in binary mode as well at the
startup. In this case, some programs such as sed suffer from CR.

This is the regression fix of commit 20dbf6.

From: KO Myung-Hun <komh@chollian.net>
2017-12-22 16:37:14 +00:00
tg
5468d726b3 move slashifying of PATH, TMPDIR and two OS/2-specific variables from
OS/2-specific to common DOSPATH-specific code (ifdef for the latter two)

also gets us rid of the use of getenv
2017-10-13 23:34:49 +00:00
tg
7d18c762d2 komh says these are redundant 2017-10-13 11:54:06 +00:00
tg
0ba04f9bb7 apply fixes from code review by @komh 2017-10-12 15:17:04 +00:00
tg
5db583cd81 handle drive-qualified nōn-absolute pathnames in do_realpath(), untested
the idea here is that:

- /foo/bar and a:/foo/bar are absolute
- foo/bar is relative
- a:foo/bar needs to be handled specially,
  mostly per making it into an absolute (“a:/” + getcwd(a:) + “foo/bar”)
2017-10-11 23:23:03 +00:00
tg
e6395046df use strnul(); optimise 2017-04-29 22:04:31 +00:00
tg
718d397fff merge mksh-os2 by KO Myung-Hun <komh@chollian.net> from https://github.com/komh/mksh-os2 2017-04-02 15:00:45 +00:00
mirabilos
62a5331aee no strcpy() allowed in BSD code 2017-03-26 00:05:25 +01:00
mirabilos
de3d3aa5d2 mostly KNF; afree() can be called with NULL argument 2017-03-25 23:56:09 +01:00
KO Myung-Hun
9f84c65e76 os2: return an error code correctly when a child was signaled
For example, a child process terminates due to abort().

    modified:   os2.c
2016-12-21 20:37:37 +09:00
KO Myung-Hun
20dbf6b45b Read in text mode in a needed place only
Converting CR+LF to LF in blocking_read() which is a underlying read
function, may affect to the functions which do not perform line-based
operation.

    modified:   funcs.c
    modified:   main.c
    modified:   misc.c
    modified:   os2.c
    modified:   shf.c
2016-12-19 08:27:06 +09:00
KO Myung-Hun
18ff277047 Write in binary mode through pipes
On kLIBC, a child inherits a translation mode of stdio/stdout/stderr
of a parent. So if setting stdio handles of a parent to text mode,
a child reads CR+LF as LF and write LF to CR+LF. Especially, LF to
CR+LF conversion causes many troubles in UNIX programs.

Instead, if a child inherts a child inherit a current translation mode,
where stdin is text mode, stdout and stderr are binary mode, a child
would write LF as is.

This is the way for OS/2 to survive in UNIX jungle.

For example, 'make check' of libiconv fails due to mismatch of CR+LF
and LF.
2016-12-15 17:37:04 +09:00
KO Myung-Hun
52c47ec69e os2: fix the last character of a response file is splitted
For example, if a response file has the following:

    0123456789

Then, it is splitted into two arguments, 012345678 and 9.

    modified:   os2.c
2016-03-20 11:28:22 +09:00
KO Myung-Hun
25bb7dcec4 exec: fix that executing a file with multiple dots fails on OS/2
For example, [a.b.exe] cannot be executed with [a.b].

    modified:   exec.c
2015-06-11 16:10:29 +09:00
KO Myung-Hun
645b537439 Support BEGINLIBPATH, ENDLIBPATH and LIBPATHSTRICT on OS/2 2015-06-03 13:00:50 +09:00
KO Myung-Hun
011d0abf2c Clean-up temporary files on OS/2
On OS/2, unlink() fails on opened files. For this case, try to unlink()
them at termination.
2015-06-03 13:00:49 +09:00
KO Myung-Hun
29161973e3 Set stdin to text mode, and stdout/stderr to binary mode if not a console 2015-06-03 13:00:47 +09:00
KO Myung-Hun
4076b74ae8 Convert backslashes of PATH and TMPDIR to slashes on OS/2
PATH and TMPDIR are used by OS/2 as well. So they may have backslashes
as a directory separator. A backslash may cause an unexpected behavior
when do 'echo'. Because a backslash may be used as an escaped character.
2015-06-03 13:00:45 +09:00
KO Myung-Hun
ffb5e7cd19 Workaround for execve() on OS/2 2015-06-03 13:00:44 +09:00
KO Myung-Hun
07e5cadc54 Support a response file on OS/2 2015-06-03 13:00:43 +09:00
KO Myung-Hun
a03cf65602 Consider executable extensions in case of some test commands on OS/2
-r, -w, -x, -a, -e, -f.
2015-06-03 13:00:42 +09:00
KO Myung-Hun
5ed2481df2 Try to append executable suffixes if not having extension on OS/2 2015-06-03 13:00:40 +09:00