OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [fs/] [binfmt_script.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 *  linux/fs/binfmt_script.c
3
 *
4
 *  Copyright (C) 1996  Martin von Löwis
5
 *  original #!-checking implemented by tytso.
6
 *
7
 */
8
 
9
/*
10
 * uClinux revisions for NO_MM
11
 * Copyright (C) 1998  Kenneth Albanowski <kjahds@kjahds.com>,
12
 *                     The Silver Hammer Group, Ltd.
13
 *
14
 *  FIXME: Modifications are untested!
15
 */
16
 
17
#include <linux/module.h>
18
#include <linux/string.h>
19
#include <linux/stat.h>
20
#include <linux/malloc.h>
21
#include <linux/binfmts.h>
22
 
23
static int do_load_script(struct linux_binprm *bprm,struct pt_regs *regs)
24
{
25
        char *cp, *interp, *i_name, *i_arg;
26
        int retval;
27
        if ((bprm->buf[0] != '#') || (bprm->buf[1] != '!') || (bprm->sh_bang))
28
                return -ENOEXEC;
29
        /*
30
         * This section does the #! interpretation.
31
         * Sorta complicated, but hopefully it will work.  -TYT
32
         */
33
 
34
        bprm->sh_bang++;
35
        iput(bprm->inode);
36
        bprm->dont_iput=1;
37
 
38
        bprm->buf[127] = '\0';
39
        if ((cp = strchr(bprm->buf, '\n')) == NULL)
40
                cp = bprm->buf+127;
41
        *cp = '\0';
42
        while (cp > bprm->buf) {
43
                cp--;
44
                if ((*cp == ' ') || (*cp == '\t'))
45
                        *cp = '\0';
46
                else
47
                        break;
48
        }
49
        for (cp = bprm->buf+2; (*cp == ' ') || (*cp == '\t'); cp++);
50
        if (!cp || *cp == '\0')
51
                return -ENOEXEC; /* No interpreter name found */
52
        interp = i_name = cp;
53
        i_arg = 0;
54
        for ( ; *cp && (*cp != ' ') && (*cp != '\t'); cp++) {
55
                if (*cp == '/')
56
                        i_name = cp+1;
57
        }
58
        while ((*cp == ' ') || (*cp == '\t'))
59
                *cp++ = '\0';
60
        if (*cp)
61
                i_arg = cp;
62
        /*
63
         * OK, we've parsed out the interpreter name and
64
         * (optional) argument.
65
         * Splice in (1) the interpreter's name for argv[0]
66
         *           (2) (optional) argument to interpreter
67
         *           (3) filename of shell script (replace argv[0])
68
         *
69
         * This is done in reverse order, because of how the
70
         * user environment and arguments are stored.
71
         */
72
#ifndef NO_MM
73
        remove_arg_zero(bprm);
74
        bprm->p = copy_strings(1, &bprm->filename, bprm->page, bprm->p, 2);
75
        bprm->argc++;
76
        if (i_arg) {
77
                bprm->p = copy_strings(1, &i_arg, bprm->page, bprm->p, 2);
78
                bprm->argc++;
79
        }
80
        bprm->p = copy_strings(1, &i_name, bprm->page, bprm->p, 2);
81
        bprm->argc++;
82
        if (!bprm->p)
83
                return -E2BIG;
84
        /*
85
         * OK, now restart the process with the interpreter's inode.
86
         * Note that we use open_namei() as the name is now in kernel
87
         * space, and we don't need to copy it.
88
         */
89
        retval = open_namei(interp, 0, 0, &bprm->inode, NULL);
90
        if (retval)
91
                return retval;
92
        bprm->dont_iput=0;
93
        retval=prepare_binprm(bprm);
94
        if(retval<0)
95
                return retval;
96
        return search_binary_handler(bprm,regs);
97
#else /* !NO_MM */
98
        {
99
                char ** oldargv = bprm->argv;
100
                int oldargc = bprm->argc;
101
                int i;
102
 
103
                bprm->argc = oldargc + (i_arg ? 2 : 1);
104
                bprm->argv = kmalloc(sizeof(char*) * bprm->argc, GFP_KERNEL);
105
 
106
                if (!bprm->argv) {
107
                        bprm->argc = oldargc;
108
                        bprm->argv = oldargv;
109
                        return -E2BIG;
110
                }
111
 
112
                for(i=1;i<=oldargc;i++)
113
                        bprm->argv[bprm->argc-i] = oldargv[oldargc-i];
114
 
115
                bprm->argv[0] = i_name;
116
                i=1;
117
                if (i_arg)
118
                        bprm->argv[i++] = i_arg;
119
                bprm->argv[i++] = bprm->filename;
120
 
121
 
122
                /*
123
                 * OK, now restart the process with the interpreter's inode.
124
                 * Note that we use open_namei() as the name is now in kernel
125
                 * space, and we don't need to copy it.
126
                 */
127
                retval = open_namei(interp, 0, 0, &bprm->inode, NULL);
128
                if (!retval) {
129
                        bprm->dont_iput=0;
130
                        retval=prepare_binprm(bprm);
131
                }
132
                if (!retval) {
133
                        retval =  search_binary_handler(bprm,regs);
134
                }
135
 
136
                kfree(bprm->argv);
137
                bprm->argv = oldargv;
138
                bprm->argc = oldargc;
139
 
140
                return retval;
141
        }
142
#endif /* !NO_MM */
143
}
144
 
145
static int load_script(struct linux_binprm *bprm,struct pt_regs *regs)
146
{
147
        int retval;
148
        MOD_INC_USE_COUNT;
149
        retval = do_load_script(bprm,regs);
150
        MOD_DEC_USE_COUNT;
151
        return retval;
152
}
153
 
154
struct linux_binfmt script_format = {
155
#ifndef MODULE
156
        NULL, 0, load_script, NULL, NULL
157
#else
158
        NULL, &mod_use_count_, load_script, NULL, NULL
159
#endif
160
};
161
 
162
int init_script_binfmt(void) {
163
        return register_binfmt(&script_format);
164
}
165
 
166
#ifdef MODULE
167
int init_module(void)
168
{
169
        return init_script_binfmt();
170
}
171
 
172
void cleanup_module( void) {
173
        unregister_binfmt(&script_format);
174
}
175
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.