/[gentoo-src]/rc-scripts/src/runscript.c
Gentoo

Contents of /rc-scripts/src/runscript.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations) (download) (as text)
Thu Dec 23 19:15:06 2004 UTC (15 years, 6 months ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +15 -15 lines
File MIME type: text/x-csrc
merge freebsd fixes

1 azarah 1.1 /*
2 vapier 1.8 * runscript.c
3     * Handle launching of Gentoo init scripts.
4     *
5 vapier 1.6 * Copyright 1999-2004 Gentoo Foundation
6 azarah 1.1 * Distributed under the terms of the GNU General Public License v2
7 vapier 1.8 * $Header: /var/cvsroot/gentoo-src/rc-scripts/src/runscript.c,v 1.7 2004/10/06 01:17:27 vapier Exp $
8 azarah 1.1 */
9    
10     #include <stdio.h>
11     #include <stdlib.h>
12     #include <unistd.h>
13     #include <sys/types.h>
14 vapier 1.8 #include <sys/wait.h>
15 azarah 1.3 #include <dlfcn.h>
16    
17 vapier 1.7 static void (*selinux_run_init_old) (void);
18     static void (*selinux_run_init_new) (int argc, char **argv);
19 azarah 1.1
20 vapier 1.8 int main(int argc, char *argv[]) {
21 azarah 1.1 char *myargs[32];
22 vapier 1.4 void *lib_handle;
23 azarah 1.1 int new = 1;
24     myargs[0] = "runscript";
25 vapier 1.8
26 azarah 1.1 while (argv[new] != 0) {
27     myargs[new] = argv[new];
28     new++;
29     }
30 vapier 1.8 myargs[new] = NULL;
31 azarah 1.1 if (argc < 3) {
32 vapier 1.8 execv("/lib/rcscripts/sh/rc-help.sh", myargs);
33 azarah 1.1 exit(1);
34     }
35 vapier 1.8
36 vapier 1.7 lib_handle = dlopen("/lib/rcscripts/runscript_selinux.so", RTLD_NOW | RTLD_GLOBAL);
37 vapier 1.8 if (lib_handle != NULL) {
38 vapier 1.7 selinux_run_init_old = dlsym(lib_handle, "selinux_runscript");
39     selinux_run_init_new = dlsym(lib_handle, "selinux_runscript2");
40    
41     /* use new run_init if it exists, else fall back to old */
42 vapier 1.8 if (selinux_run_init_new != NULL)
43     selinux_run_init_new(argc, argv);
44     else if (selinux_run_init_old != NULL)
45 vapier 1.7 selinux_run_init_old();
46     else {
47     /* this shouldnt happen... probably corrupt lib */
48     fprintf(stderr,"Run_init is missing from runscript_selinux.so!\n");
49     exit(127);
50     }
51 azarah 1.3 }
52    
53 vapier 1.8 if (execv("/sbin/runscript.sh", myargs) < 0)
54 azarah 1.1 exit(1);
55    
56     return 0;
57     }

  ViewVC Help
Powered by ViewVC 1.1.20