]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/delete_module.2
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man2 / delete_module.2
CommitLineData
f4008050 1.\" Copyright (C) 2012 Michael Kerrisk <mtk.manpages@gmail.com>
c4d4162c 2.\"
5fbde956 3.\" SPDX-License-Identifier: Linux-man-pages-copyleft
c4d4162c 4.\"
4c1c5274 5.TH delete_module 2 (date) "Linux man-pages (unreleased)"
c4d4162c 6.SH NAME
460240ca 7delete_module \- unload a kernel module
0bf0ca71
AC
8.SH LIBRARY
9Standard C library
8fc3b2cf 10.RI ( libc ", " \-lc )
c4d4162c
MK
11.SH SYNOPSIS
12.nf
43be8898 13.BR "#include <fcntl.h>" " /* Definition of " O_* " constants */"
46950763 14.BR "#include <sys/syscall.h>" " /* Definition of " SYS_* " constants */"
1ae6b2c7 15.B #include <unistd.h>
43be8898 16.PP
46950763 17.BI "int syscall(SYS_delete_module, const char *" name ", unsigned int " flags );
c4d4162c 18.fi
bc2813df
AC
19.PP
20.IR Note :
21glibc provides no wrapper for
22.BR delete_module (),
23necessitating the use of
24.BR syscall (2).
c4d4162c 25.SH DESCRIPTION
b4f49502 26The
c4d4162c 27.BR delete_module ()
b4f49502 28system call attempts to remove the unused loadable module entry
460240ca
MK
29identified by
30.IR name .
b4f49502
MK
31If the module has an
32.I exit
33function, then that function is executed before unloading the module.
34The
1ae6b2c7 35.I flags
b4f49502
MK
36argument is used to modify the behavior of the system call,
37as described below.
c4d4162c 38This system call requires privilege.
efeece04 39.PP
b4f49502 40Module removal is attempted according to the following rules:
22356d97 41.IP (1) 5
460240ca
MK
42If there are other loaded modules that depend on
43(i.e., refer to symbols defined in) this module,
44then the call fails.
22356d97 45.IP (2)
b4f49502 46Otherwise, if the reference count for the module
3d1ee497 47(i.e., the number of processes currently using the module)
b4f49502 48is zero, then the module is immediately unloaded.
22356d97 49.IP (3)
b4f49502
MK
50If a module has a nonzero reference count,
51then the behavior depends on the bits set in
52.IR flags .
53In normal usage (see NOTES), the
1ae6b2c7 54.B O_NONBLOCK
b4f49502 55flag is always specified, and the
1ae6b2c7 56.B O_TRUNC
b4f49502
MK
57flag may additionally be specified.
58.\" O_TRUNC == KMOD_REMOVE_FORCE in kmod library
59.\" O_NONBLOCK == KMOD_REMOVE_NOWAIT in kmod library
efeece04 60.IP
b4f49502
MK
61The various combinations for
62.I flags
63have the following effect:
22356d97 64.RS
460240ca 65.TP
b4f49502
MK
66.B flags == O_NONBLOCK
67The call returns immediately, with an error.
68.TP
69.B flags == (O_NONBLOCK | O_TRUNC)
70The module is unloaded immediately,
71regardless of whether it has a nonzero reference count.
72.TP
0cb430a1 73.B (flags & O_NONBLOCK) == 0
b4f49502
MK
74If
75.I flags
76does not specify
77.BR O_NONBLOCK ,
78the following steps occur:
460240ca 79.RS
22356d97 80.IP \(bu 3
b4f49502 81The module is marked so that no new references are permitted.
22356d97 82.IP \(bu
b4f49502
MK
83If the module's reference count is nonzero,
84the caller is placed in an uninterruptible sleep state
85.RB ( TASK_UNINTERRUPTIBLE )
86until the reference count is zero, at which point the call unblocks.
22356d97 87.IP \(bu
b4f49502 88The module is unloaded in the usual way.
460240ca 89.RE
b4f49502
MK
90.RE
91.PP
92The
93.B O_TRUNC
94flag has one further effect on the rules described above.
35f69680 95By default, if a module has an
b4f49502
MK
96.I init
97function but no
fa1d2749 98.I exit
26cd31fd 99function, then an attempt to remove the module fails.
b4f49502 100However, if
1ae6b2c7 101.B O_TRUNC
b4f49502
MK
102was specified, this requirement is bypassed.
103.PP
fa1d2749 104Using the
b4f49502
MK
105.B O_TRUNC
106flag is dangerous!
460240ca
MK
107If the kernel was not built with
108.BR CONFIG_MODULE_FORCE_UNLOAD ,
109this flag is silently ignored.
e64bdfcf 110(Normally,
1ae6b2c7 111.B CONFIG_MODULE_FORCE_UNLOAD
b4f49502
MK
112is enabled.)
113Using this flag taints the kernel (TAINT_FORCED_RMMOD).
47297adb 114.SH RETURN VALUE
c13182ef
MK
115On success, zero is returned.
116On error, \-1 is returned and
c4d4162c 117.I errno
f6a4078b 118is set to indicate the error.
c4d4162c
MK
119.SH ERRORS
120.TP
121.B EBUSY
460240ca
MK
122The module is not "live"
123(i.e., it is still being initialized or is already marked for removal);
b4f49502
MK
124or, the module has
125an
126.I init
127function but has no
460240ca 128.I exit
b4f49502 129function, and
460240ca
MK
130.B O_TRUNC
131was not specified in
132.IR flags .
c4d4162c
MK
133.TP
134.B EFAULT
135.I name
b4f49502 136refers to a location outside the process's accessible address space.
c4d4162c
MK
137.TP
138.B ENOENT
139No module by that name exists.
140.TP
141.B EPERM
142The caller was not privileged
143(did not have the
144.B CAP_SYS_MODULE
460240ca
MK
145capability),
146or module unloading is disabled
147(see
1ae6b2c7 148.I /proc/sys/kernel/modules_disabled
460240ca
MK
149in
150.BR proc (5)).
151.TP
152.B EWOULDBLOCK
153Other modules depend on this module;
154or,
1ae6b2c7 155.B O_NONBLOCK
460240ca
MK
156was specified in
157.IR flags ,
fa1d2749 158but the reference count of this module is nonzero and
460240ca
MK
159.B O_TRUNC
160was not specified in
161.IR flags .
3113c7f3 162.SH STANDARDS
c4d4162c 163.BR delete_module ()
8382f16d 164is Linux-specific.
460240ca 165.SH NOTES
4a9c7a5e
MK
166The
167.BR delete_module ()
0b13a3d6 168system call is not supported by glibc.
fa3b5cee
MK
169No declaration is provided in glibc headers, but, through a quirk of history,
170glibc versions before 2.23 did export an ABI for this system call.
4a9c7a5e 171Therefore, in order to employ this system call,
fa3b5cee
MK
172it is (before glibc 2.23) sufficient to
173manually declare the interface in your code;
4a9c7a5e 174alternatively, you can invoke the system call using
460240ca 175.BR syscall (2).
efeece04 176.PP
b2fc8e9f 177The uninterruptible sleep that may occur if
1ae6b2c7 178.B O_NONBLOCK
b4f49502 179is omitted from
1ae6b2c7 180.I flags
b4f49502
MK
181is considered undesirable, because the sleeping process is left
182in an unkillable state.
183As at Linux 3.7, specifying
1ae6b2c7 184.B O_NONBLOCK
b4f49502 185is optional, but in future kernels it is likely to become mandatory.
460240ca
MK
186.SS Linux 2.4 and earlier
187In Linux 2.4 and earlier, the system call took only one argument:
efeece04 188.PP
460240ca 189.BI " int delete_module(const char *" name );
efeece04 190.PP
460240ca
MK
191If
192.I name
193is NULL, all unused modules marked auto-clean are removed.
efeece04 194.PP
460240ca
MK
195Some further details of differences in the behavior of
196.BR delete_module ()
197in Linux 2.4 and earlier are
198.I not
199currently explained in this manual page.
47297adb 200.SH SEE ALSO
c4d4162c
MK
201.BR create_module (2),
202.BR init_module (2),
98038e98 203.BR query_module (2),
b4f49502 204.BR lsmod (8),
eceb82f7 205.BR modprobe (8),
98038e98 206.BR rmmod (8)