Ruby
2.7.7p221 (2022-11-24 revision 168ec2b1e5ad0e4688e963d9de019557c78feed9)
rubystub.c
Go to the documentation of this file.
1
#include "
internal.h
"
2
#if defined HAVE_DLADDR
3
#include <dlfcn.h>
4
#endif
5
#if defined HAVE_SYS_PARAM_H
6
#include <sys/param.h>
7
#endif
8
static
void
* stub_options(
int
argc
,
char
**
argv
);
9
#define ruby_options stub_options
10
#include <
main.c
>
11
#undef ruby_options
12
13
void
*
14
stub_options(
int
argc
,
char
**
argv
)
15
{
16
char
xflag[] =
"-x"
;
17
char
*xargv[4] = {
NULL
, xflag};
18
char
*cmd =
argv
[0];
19
void
*ret;
20
21
#if defined __CYGWIN__ || defined _WIN32
22
/* GetCommandLineW should contain the accessible path,
23
* use argv[0] as is */
24
#elif defined __linux__
25
{
26
char
selfexe[
MAXPATHLEN
];
27
ssize_t
len
=
readlink
(
"/proc/self/exe"
, selfexe,
sizeof
(selfexe));
28
if
(
len
< 0) {
29
perror
(
"readlink(\"/proc/self/exe\")"
);
30
return
NULL
;
31
}
32
selfexe[
len
] =
'\0'
;
33
cmd = selfexe;
34
}
35
#elif defined HAVE_DLADDR
36
{
37
Dl_info dli;
38
if
(!dladdr(stub_options, &dli)) {
39
perror
(
"dladdr"
);
40
return
NULL
;
41
}
42
cmd = (
char
*)dli.dli_fname;
43
}
44
#endif
45
46
#ifndef HAVE_SETPROCTITLE
47
/* argc and argv must be the original */
48
ruby_init_setproctitle
(
argc
,
argv
);
49
#endif
50
51
/* set script with -x option */
52
/* xargv[0] is NULL not to re-initialize setproctitle again */
53
xargv[2] = cmd;
54
ret =
ruby_options
(3, xargv);
55
56
/* set all arguments to ARGV */
57
ruby_set_argv
(
argc
- 1,
argv
+ 1);
58
59
return
ret;
60
}
internal.h
main.c
readlink
ssize_t readlink(const char *__restrict__ __path, char *__restrict__ __buf, size_t __buflen)
NULL
#define NULL
Definition:
rb_mjit_min_header-2.7.7.h:11172
ruby_set_argv
void ruby_set_argv(int, char **)
Definition:
ruby.c:2391
ruby_init_setproctitle
void ruby_init_setproctitle(int argc, char *argv[])
len
__inline__ const void *__restrict__ size_t len
Definition:
rb_mjit_min_header-2.7.7.h:3017
argv
const VALUE * argv
Definition:
rb_mjit_min_header-2.7.7.h:5811
ssize_t
_ssize_t ssize_t
Definition:
rb_mjit_min_header-2.7.7.h:1347
argc
int argc
Definition:
rb_mjit_min_header-2.7.7.h:15544
perror
void perror(const char *)
MAXPATHLEN
#define MAXPATHLEN
Definition:
rb_mjit_min_header-2.7.7.h:11179
ruby_options
#define ruby_options
Definition:
rubystub.c:9
Generated by
1.9.2