Re: [Patch] Support UTF-8 scripts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



D. Hazelton wrote:
>>I would need to write a compiled C program to do all
>>sorts of fragile hackish things like calling a script
>>/sbin/init.sh.
> 
> 
> Problem is, the program 
> would not be fragile or hackish - it'd be almost as simple as a 
> "hello world" program.
> 
> #include <unistd.h>
> 
> int main() {
>   /* if this fails the system is busted anyway */
>   return execve( "/bin/sh", "/sbin/init.sh", 0 );
> };

This attempt nicely illustrates Kyle's point. This program *is*
fragile and hackish. It is fragile because, even though it is only
five lines, contains two major bugs:
1. execve takes an argv array, not a null-terminated list of
   strings. So this compiles with a warning about incompatible
   pointer types; you meant to use execl(3).
2. In the exec family, the path to the program is different from
   argv[0]. So the correct line would be

     return execl("/bin/sh", "sh", /sbin/init.sh", 0);

It is hackisch, because it also lacks a feature commonly
found in such wrappers:
3. arguments passed to the wrapper are not forwarded to the
   executable. In particular, init takes several arguments
   (e.g. the runlevel), which should be forwarded to the
   final executable.

Just try completing the wrapper on your own.

Regards,
Martin
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux