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:  No declaration of this system call is provided in glibc headers;
12       see NOTES.
13

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

CONFORMING TO

93       delete_module() is Linux-specific.
94

NOTES

96       The delete_module() system call is not supported by glibc.  No declara‐
97       tion is provided in glibc headers, but, through  a  quirk  of  history,
98       glibc  versions  before  2.23  did  export an ABI for this system call.
99       Therefore, in order to employ this system call,  it  is  (before  glibc
100       2.23) sufficient to manually declare the interface in your code; alter‐
101       natively, you can invoke the system call using syscall(2).
102
103       The uninterruptible sleep that may occur if O_NONBLOCK is omitted  from
104       flags  is  considered undesirable, because the sleeping process is left
105       in an unkillable state.  As at  Linux  3.7,  specifying  O_NONBLOCK  is
106       optional, but in future kernels it is likely to become mandatory.
107
108   Linux 2.4 and earlier
109       In Linux 2.4 and earlier, the system call took only one argument:
110
111          int delete_module(const char *name);
112
113       If name is NULL, all unused modules marked auto-clean are removed.
114
115       Some  further details of differences in the behavior of delete_module()
116       in Linux 2.4 and earlier are not currently  explained  in  this  manual
117       page.
118

SEE ALSO

120       create_module(2),   init_module(2),   query_module(2),  lsmod(8),  mod‐
121       probe(8), rmmod(8)
122

COLOPHON

124       This page is part of release 5.07 of the Linux  man-pages  project.   A
125       description  of  the project, information about reporting bugs, and the
126       latest    version    of    this    page,    can     be     found     at
127       https://www.kernel.org/doc/man-pages/.
128
129
130
131Linux                             2017-09-15                  DELETE_MODULE(2)
Impressum