1DELETE_MODULE(2)           Linux Programmer's Manual          DELETE_MODULE(2)
2
3
4

NAME

6       delete_module - unload a kernel module
7

SYNOPSIS

9       int delete_module(const char *name, int flags);
10
11       Note: There is no glibc wrapper for this system call; see NOTES.
12

DESCRIPTION

14       The  delete_module() system call attempts to remove the unused loadable
15       module entry identified by name.  If the module has an  exit  function,
16       then  that function is executed before unloading the module.  The flags
17       argument is used  to  modify  the  behavior  of  the  system  call,  as
18       described below.  This system call requires privilege.
19
20       Module removal is attempted according to the following rules:
21
22       1.  If  there  are  other loaded modules that depend on (i.e., refer to
23           symbols defined in) this module, then the call fails.
24
25       2.  Otherwise, if the reference count for the module (i.e., the  number
26           of  processes  currently using the module) is zero, then the module
27           is immediately unloaded.
28
29       3.  If a module has  a  nonzero  reference  count,  then  the  behavior
30           depends on the bits set in flags.  In normal usage (see NOTES), the
31           O_NONBLOCK flag is always specified, and the O_TRUNC flag may addi‐
32           tionally be specified.
33
34           The various combinations for flags have the following effect:
35
36           flags == O_NONBLOCK
37                  The call returns immediately, with an error.
38
39           flags == (O_NONBLOCK | O_TRUNC)
40                  The module is unloaded immediately, regardless of whether it
41                  has a nonzero reference count.
42
43           (flags & O_NONBLOCK) == 0
44                  If flags does not specify O_NONBLOCK,  the  following  steps
45                  occur:
46
47                  *  The  module  is marked so that no new references are per‐
48                     mitted.
49
50                  *  If the module's reference count is nonzero, the caller is
51                     placed  in  an uninterruptible sleep state (TASK_UNINTER‐
52                     RUPTIBLE) until the reference count  is  zero,  at  which
53                     point the call unblocks.
54
55                  *  The module is unloaded in the usual way.
56
57       The  O_TRUNC  flag has one further effect on the rules described above.
58       By default, if a module has an init function but no exit function, then
59       an  attempt  to  remove  the module will fail.  However, if O_TRUNC was
60       specified, this requirement is bypassed.
61
62       Using the O_TRUNC flag is dangerous!  If the kernel was not built  with
63       CONFIG_MODULE_FORCE_UNLOAD,  this flag is silently ignored.  (Normally,
64       CONFIG_MODULE_FORCE_UNLOAD is enabled.)  Using  this  flag  taints  the
65       kernel (TAINT_FORCED_RMMOD).
66

RETURN VALUE

68       On  success,  zero  is returned.  On error, -1 is returned and errno is
69       set appropriately.
70

ERRORS

72       EBUSY  The module is not "live" (i.e., it is still being initialized or
73              is already marked for removal); or, the module has an init func‐
74              tion but has no exit function, and O_TRUNC was not specified  in
75              flags.
76
77       EFAULT name  refers  to  a  location  outside  the process's accessible
78              address space.
79
80       ENOENT No module by that name exists.
81
82       EPERM  The caller was not privileged (did not have  the  CAP_SYS_MODULE
83              capability), or module unloading is disabled (see /proc/sys/ker‐
84              nel/modules_disabled in proc(5)).
85
86       EWOULDBLOCK
87              Other modules depend on this module; or, O_NONBLOCK  was  speci‐
88              fied in flags, but the reference count of this module is nonzero
89              and O_TRUNC was not specified in flags.
90

CONFORMING TO

92       delete_module() is Linux-specific.
93

NOTES

95       Glibc does not provide a wrapper for this system call;  call  it  using
96       syscall(2).
97
98       The  uninterruptible sleep that may occur if O_NONBLOCK is omitted from
99       flags is considered undesirable, because the sleeping process  is  left
100       in  an  unkillable  state.   As  at Linux 3.7, specifying O_NONBLOCK is
101       optional, but in future kernels it is likely to become mandatory.
102
103   Linux 2.4 and earlier
104       In Linux 2.4 and earlier, the system call took only one argument:
105
106          int delete_module(const char *name);
107
108       If name is NULL, all unused modules marked auto-clean are removed.
109
110       Some further details of differences in the behavior of  delete_module()
111       in  Linux  2.4  and  earlier are not currently explained in this manual
112       page.
113

SEE ALSO

115       create_module(2),  init_module(2),  query_module(2),   lsmod(8),   mod‐
116       probe(8), rmmod(8)
117

COLOPHON

119       This  page  is  part of release 3.53 of the Linux man-pages project.  A
120       description of the project, and information about reporting  bugs,  can
121       be found at http://www.kernel.org/doc/man-pages/.
122
123
124
125Linux                             2012-11-08                  DELETE_MODULE(2)
Impressum