modprobe: don't exit when silent
[mit.git] / backwards_compat.c
blob45320cfffdfa40924293748b7fe805200a503131
1 /* Simple backwards compat code to exec old version */
3 #ifndef CONFIG_NO_BACKWARDS_COMPAT
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <unistd.h>
8 #include <stdlib.h>
9 #include <errno.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <asm/unistd.h>
14 extern long create_module(const char *, size_t);
16 #include "testing.h"
18 static void exec_old(const char *progname, char *argv[])
20 char *sep;
21 pid_t pid;
22 char ascii_pid[32];
23 char pathname[strlen(argv[0])+1];
24 char oldname[strlen(progname) + strlen(argv[0]) + sizeof(".old")];
26 memset(pathname, 0, strlen(argv[0])+1);
27 sep = strrchr(argv[0], '/');
28 if (sep)
29 memcpy(pathname, argv[0], sep - argv[0]+1);
30 sprintf(oldname, "%s%s.old", pathname, progname);
32 /* Recursion detection: we need an env var since we can't
33 change argv[0] (as older modutils uses it to determine
34 behavior). We *can* recurse in the case of old-style
35 pre-install etc. commands, so make sure pid is exactly the
36 same. */
37 pid = getpid();
38 snprintf(ascii_pid, sizeof(ascii_pid), "%lu", (unsigned long)pid);
39 if (strcmp(getenv("MODULE_RECURSE") ?: "", ascii_pid) == 0) {
40 fprintf(stderr, "WARNING: %s: I am not the old version!\n",
41 oldname);
42 return;
44 setenv("MODULE_RECURSE", ascii_pid, 1);
46 execvp(oldname, argv);
47 fprintf(stderr,
48 "Kernel requires old %s, but couldn't run %s: %s\n",
49 progname, oldname, strerror(errno));
50 exit(2);
53 static void try_old_version(const char *progname, char *argv[])
55 errno = 0;
56 if (create_module(NULL, 0) >= 0 /* Uh oh, what have I just done? */
57 || errno != ENOSYS)
58 exec_old(progname, argv);
60 #else /* CONFIG_NO_BACKWARDS_COMPAT */
61 static inline void try_old_version(const char *progname, char *argv[])
64 #endif /* !CONFIG_NO_BACKWARDS_COMPAT */