Discussion:
weirdest actually useful program I've written so far
(too old to reply)
Rainer Weikusat
2020-08-24 21:34:20 UTC
Permalink
#include <errno.h>
#include <syslog.h>
#include <unistd.h>

int main(int argc, char **argv)
{
int errno_;

++argv;
execvp(*argv, argv);

errno_ = errno;
openlog("run-prg", LOG_PID | LOG_PERROR, LOG_USER);

errno = errno_;
syslog(LOG_ERR, "execvp %s: %m(%d)", *argv, errno);

return 1;
}

----------

This does actually solve a real problem: As part of getting a suricata
5.0.3 crosscompiled with an SDK based on Yocto, I need a suitable rust
compiler (distant sounds of someone throwing up at the other end of a
long tunnel) and this rust compiler needs (some parts) of the llvm
compiler. This needs to be built using the cmake.bbclass file which
comes with the Yocto version I'm forced to use.

llvm is to be compiled for the host and not for the target. But the
cmake version being used refuses to run the configuration process
because - presumably as a "clever" hack - when supposed to be used for
compiling for the host, it's run in "cross-compiling mode" with a
toolchain file specifying the native code compiler and not the
cross-compiler. May sound brilliant but cmake then balks at TRY_RUN
expressions on the grounds that these cannot possibly be used when
running in cross-compiling mode (as - surely - no sane person who isn't
"brilliant" would ever use this mode for running the native code
compiler).

The program above is the solution to this: It's an x86-on-x86 emulator
:-) which enables cmake to run the supposedly cross-compiled
binaries which weren't really cross-compiled (but cmake doesn't know
this).
Kaz Kylheku
2020-08-24 23:00:18 UTC
Permalink
Post by Rainer Weikusat
#include <errno.h>
#include <syslog.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int errno_;
++argv;
execvp(*argv, argv);
errno_ = errno;
openlog("run-prg", LOG_PID | LOG_PERROR, LOG_USER);
errno = errno_;
syslog(LOG_ERR, "execvp %s: %m(%d)", *argv, errno);
return 1;
}
----------
This does actually solve a real problem: As part of getting a suricata
Sure, but how is it different from the standard program "env", other
than not supporting VAR=val assignments and various options that
are not relevant here?
Post by Rainer Weikusat
5.0.3 crosscompiled with an SDK based on Yocto, I need a suitable rust
compiler (distant sounds of someone throwing up at the other end of a
long tunnel)
... at the other end from the other someone throwing up when Yocto
was mentioned.
--
TXR Programming Lanuage: http://nongnu.org/txr
Music DIY Mailing List: http://www.kylheku.com/diy
ADA MP-1 Mailing List: http://www.kylheku.com/mp1
Rainer Weikusat
2020-08-25 14:43:09 UTC
Permalink
Post by Kaz Kylheku
Post by Rainer Weikusat
#include <errno.h>
#include <syslog.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int errno_;
++argv;
execvp(*argv, argv);
errno_ = errno;
openlog("run-prg", LOG_PID | LOG_PERROR, LOG_USER);
errno = errno_;
syslog(LOG_ERR, "execvp %s: %m(%d)", *argv, errno);
return 1;
}
----------
This does actually solve a real problem: As part of getting a suricata
Sure, but how is it different from the standard program "env", other
than not supporting VAR=val assignments and various options that
are not relevant here?
It executes a program in an unmodified environment?
Kaz Kylheku
2020-08-25 15:04:11 UTC
Permalink
Post by Rainer Weikusat
Post by Kaz Kylheku
Post by Rainer Weikusat
#include <errno.h>
#include <syslog.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int errno_;
++argv;
execvp(*argv, argv);
errno_ = errno;
openlog("run-prg", LOG_PID | LOG_PERROR, LOG_USER);
errno = errno_;
syslog(LOG_ERR, "execvp %s: %m(%d)", *argv, errno);
return 1;
}
----------
This does actually solve a real problem: As part of getting a suricata
Sure, but how is it different from the standard program "env", other
than not supporting VAR=val assignments and various options that
are not relevant here?
It executes a program in an unmodified environment?
So does env, without any NAME=val arguments.
Lew Pitcher
2020-08-25 15:22:30 UTC
Permalink
Post by Kaz Kylheku
Post by Rainer Weikusat
Post by Kaz Kylheku
Post by Rainer Weikusat
#include <errno.h>
#include <syslog.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int errno_;
++argv;
execvp(*argv, argv);
errno_ = errno;
openlog("run-prg", LOG_PID | LOG_PERROR, LOG_USER);
errno = errno_;
syslog(LOG_ERR, "execvp %s: %m(%d)", *argv, errno);
return 1;
}
----------
This does actually solve a real problem: As part of getting a suricata
Sure, but how is it different from the standard program "env", other
than not supporting VAR=val assignments and various options that
are not relevant here?
It executes a program in an unmodified environment?
So does env, without any NAME=val arguments.
Rainer's program does two things that env(1) does not:
1) it logs the execvp() error to syslog, and
2) it does not attempt to interpret any flags.

The first point was probably more a selling-point to Rainer than the second,
but the second is, none the less, a reasonable point.

Consider that Rainer says he wrote this code to intercede deep in an opaque
compilation process; it may be that this process invokes oddly-named
internal executables, like "-i" (unlikely, but possible). env(1) would
interpret the commandline in a vastly different manner than Rainer's
program, and give incorrect results. (Yes, I know that this is a very
contrived example, but you get the picture.)
--
Lew Pitcher
"In Skills, We Trust"
Loading...