~vorlon/ubuntu/raring/upstart/lp.1199778

« back to all changes in this revision

Viewing changes to init/process.c

  • Committer: Scott James Remnant
  • Date: 2008-01-15 19:05:04 UTC
  • Revision ID: scott@netsplit.com-20080115190504-wx9st1p8uy7ccmxt
* init/process.c (process_spawn): Call process_error_abort() on any
error condition.
* init/tests/test_process.c (test_spawn): Add a test case for failing
to spawn a process and receiving ProcessError correctly; fix other
cases to ensure they return a pid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
process_spawn (Job          *job,
109
109
               char * const  argv[])
110
110
{
111
 
        NihError *err;
112
 
        sigset_t  child_set, orig_set;
113
 
        pid_t     pid;
114
 
        int       i, fds[2];
 
111
        sigset_t child_set, orig_set;
 
112
        pid_t    pid;
 
113
        int      i, fds[2];
115
114
 
116
115
        nih_assert (job != NULL);
117
116
 
178
177
         * later.
179
178
         */
180
179
        if (process_setup_console (job->config->console, FALSE) < 0)
181
 
                goto error;
 
180
                process_error_abort (fds[1], PROCESS_ERROR_CONSOLE, 0);
182
181
 
183
182
        /* Set resource limits for the process, skipping over any that
184
183
         * aren't set in the job configuration such that they inherit from
188
187
                if (! job->config->limits[i])
189
188
                        continue;
190
189
 
191
 
                if (setrlimit (i, job->config->limits[i]) < 0)
192
 
                        goto error;
 
190
                if (setrlimit (i, job->config->limits[i]) < 0) {
 
191
                        nih_error_raise_system ();
 
192
                        process_error_abort (fds[1], PROCESS_ERROR_RLIMIT, i);
 
193
                }
193
194
        }
194
195
 
195
196
        /* Set the process environment, taking environment variables from
197
198
         * include the standard ones that tell you which job you are.
198
199
         */
199
200
        if (process_setup_environment (job) < 0)
200
 
                goto error;
 
201
                process_error_abort (fds[1], PROCESS_ERROR_ENVIRON, 0);
201
202
 
202
203
        /* Set the file mode creation mask; this is one of the few operations
203
204
         * that can never fail.
206
207
 
207
208
        /* Adjust the process priority ("nice level").
208
209
         */
209
 
        if (setpriority (PRIO_PROCESS, 0, job->config->nice) < 0)
210
 
                goto error;
 
210
        if (setpriority (PRIO_PROCESS, 0, job->config->nice) < 0) {
 
211
                nih_error_raise_system ();
 
212
                process_error_abort (fds[1], PROCESS_ERROR_PRIORITY, 0);
 
213
        }
211
214
 
212
215
        /* Change the root directory, confining path resolution within it;
213
216
         * we do this before the working directory call so that is always
214
217
         * relative to the new root.
215
218
         */
216
219
        if (job->config->chroot) {
217
 
                if (chroot (job->config->chroot) < 0)
218
 
                        goto error;
 
220
                if (chroot (job->config->chroot) < 0) {
 
221
                        nih_error_raise_system ();
 
222
                        process_error_abort (fds[1], PROCESS_ERROR_CHROOT, 0);
 
223
                }
219
224
        }
220
225
 
221
226
        /* Change the working directory of the process, either to the one
222
227
         * configured in the job, or to the root directory of the filesystem
223
228
         * (or at least relative to the chroot).
224
229
         */
225
 
        if (chdir (job->config->chdir ? job->config->chdir : "/") < 0)
226
 
                nih_return_system_error (-1);
 
230
        if (chdir (job->config->chdir ? job->config->chdir : "/") < 0) {
 
231
                nih_error_raise_system ();
 
232
                process_error_abort (fds[1], PROCESS_ERROR_CHDIR, 0);
 
233
        }
227
234
 
228
235
 
229
236
        /* Reset all the signal handlers back to their default handling so
237
244
        if (job->trace_state == TRACE_NEW) {
238
245
                if (ptrace (PTRACE_TRACEME, 0, NULL, 0) < 0) {
239
246
                        nih_error_raise_system();
240
 
                        goto error;
 
247
                        process_error_abort (fds[1], PROCESS_ERROR_PTRACE, 0);
241
248
                }
242
249
        }
243
250
 
244
251
        /* Execute the process, if we escape from here it failed */
245
 
        if (execvp (argv[0], argv) < 0)
 
252
        if (execvp (argv[0], argv) < 0) {
246
253
                nih_error_raise_system ();
247
 
 
248
 
error:
249
 
        err = nih_error_get ();
250
 
 
251
 
        nih_error (_("Unable to execute \"%s\" for %s (#%u): %s"),
252
 
                   argv[0], job->config->name, job->id, err->message);
253
 
        nih_free (err);
254
 
 
255
 
        exit (255);
 
254
                process_error_abort (fds[1], PROCESS_ERROR_EXEC, 0);
 
255
        }
 
256
 
 
257
        nih_assert_not_reached ();
256
258
}
257
259
 
258
260
/**