kmod.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef __LINUX_KMOD_H__
  2. #define __LINUX_KMOD_H__
  3. /*
  4. * include/linux/kmod.h
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/gfp.h>
  21. #include <linux/stddef.h>
  22. #include <linux/errno.h>
  23. #include <linux/compiler.h>
  24. #define KMOD_PATH_LEN 256
  25. #ifdef CONFIG_MODULES
  26. /* modprobe exit status on success, -ve on error. Return value
  27. * usually useless though. */
  28. extern int __request_module(bool wait, const char *name, ...) \
  29. __attribute__((format(printf, 2, 3)));
  30. #define request_module(mod...) __request_module(true, mod)
  31. #define request_module_nowait(mod...) __request_module(false, mod)
  32. #define try_then_request_module(x, mod...) \
  33. ((x) ?: (__request_module(true, mod), (x)))
  34. #else
  35. static inline int request_module(const char *name, ...) { return -ENOSYS; }
  36. static inline int request_module_nowait(const char *name, ...) { return -ENOSYS; }
  37. #define try_then_request_module(x, mod...) (x)
  38. #endif
  39. struct key;
  40. struct file;
  41. struct subprocess_info;
  42. /* Allocate a subprocess_info structure */
  43. struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
  44. char **envp, gfp_t gfp_mask);
  45. /* Set various pieces of state into the subprocess_info structure */
  46. void call_usermodehelper_setkeys(struct subprocess_info *info,
  47. struct key *session_keyring);
  48. int call_usermodehelper_stdinpipe(struct subprocess_info *sub_info,
  49. struct file **filp);
  50. void call_usermodehelper_setcleanup(struct subprocess_info *info,
  51. void (*cleanup)(char **argv, char **envp));
  52. enum umh_wait {
  53. UMH_NO_WAIT = -1, /* don't wait at all */
  54. UMH_WAIT_EXEC = 0, /* wait for the exec, but not the process */
  55. UMH_WAIT_PROC = 1, /* wait for the process to complete */
  56. };
  57. /* Actually execute the sub-process */
  58. int call_usermodehelper_exec(struct subprocess_info *info, enum umh_wait wait);
  59. /* Free the subprocess_info. This is only needed if you're not going
  60. to call call_usermodehelper_exec */
  61. void call_usermodehelper_freeinfo(struct subprocess_info *info);
  62. static inline int
  63. call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait)
  64. {
  65. struct subprocess_info *info;
  66. gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
  67. info = call_usermodehelper_setup(path, argv, envp, gfp_mask);
  68. if (info == NULL)
  69. return -ENOMEM;
  70. return call_usermodehelper_exec(info, wait);
  71. }
  72. static inline int
  73. call_usermodehelper_keys(char *path, char **argv, char **envp,
  74. struct key *session_keyring, enum umh_wait wait)
  75. {
  76. struct subprocess_info *info;
  77. gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
  78. info = call_usermodehelper_setup(path, argv, envp, gfp_mask);
  79. if (info == NULL)
  80. return -ENOMEM;
  81. call_usermodehelper_setkeys(info, session_keyring);
  82. return call_usermodehelper_exec(info, wait);
  83. }
  84. extern void usermodehelper_init(void);
  85. struct file;
  86. extern int call_usermodehelper_pipe(char *path, char *argv[], char *envp[],
  87. struct file **filp);
  88. extern int usermodehelper_disable(void);
  89. extern void usermodehelper_enable(void);
  90. #endif /* __LINUX_KMOD_H__ */