kmod.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/stddef.h>
  21. #include <linux/errno.h>
  22. #include <linux/compiler.h>
  23. #define KMOD_PATH_LEN 256
  24. #ifdef CONFIG_MODULES
  25. /* modprobe exit status on success, -ve on error. Return value
  26. * usually useless though. */
  27. extern int request_module(const char * name, ...) __attribute__ ((format (printf, 1, 2)));
  28. #define try_then_request_module(x, mod...) ((x) ?: (request_module(mod), (x)))
  29. #else
  30. static inline int request_module(const char * name, ...) { return -ENOSYS; }
  31. #define try_then_request_module(x, mod...) (x)
  32. #endif
  33. struct key;
  34. struct file;
  35. struct subprocess_info;
  36. /* Allocate a subprocess_info structure */
  37. struct subprocess_info *call_usermodehelper_setup(char *path,
  38. char **argv, char **envp);
  39. /* Set various pieces of state into the subprocess_info structure */
  40. void call_usermodehelper_setkeys(struct subprocess_info *info,
  41. struct key *session_keyring);
  42. int call_usermodehelper_stdinpipe(struct subprocess_info *sub_info,
  43. struct file **filp);
  44. void call_usermodehelper_setcleanup(struct subprocess_info *info,
  45. void (*cleanup)(char **argv, char **envp));
  46. enum umh_wait {
  47. UMH_NO_WAIT = -1, /* don't wait at all */
  48. UMH_WAIT_EXEC = 0, /* wait for the exec, but not the process */
  49. UMH_WAIT_PROC = 1, /* wait for the process to complete */
  50. };
  51. /* Actually execute the sub-process */
  52. int call_usermodehelper_exec(struct subprocess_info *info, enum umh_wait wait);
  53. /* Free the subprocess_info. This is only needed if you're not going
  54. to call call_usermodehelper_exec */
  55. void call_usermodehelper_freeinfo(struct subprocess_info *info);
  56. static inline int
  57. call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait)
  58. {
  59. struct subprocess_info *info;
  60. info = call_usermodehelper_setup(path, argv, envp);
  61. if (info == NULL)
  62. return -ENOMEM;
  63. return call_usermodehelper_exec(info, wait);
  64. }
  65. static inline int
  66. call_usermodehelper_keys(char *path, char **argv, char **envp,
  67. struct key *session_keyring, enum umh_wait wait)
  68. {
  69. struct subprocess_info *info;
  70. info = call_usermodehelper_setup(path, argv, envp);
  71. if (info == NULL)
  72. return -ENOMEM;
  73. call_usermodehelper_setkeys(info, session_keyring);
  74. return call_usermodehelper_exec(info, wait);
  75. }
  76. extern void usermodehelper_init(void);
  77. struct file;
  78. extern int call_usermodehelper_pipe(char *path, char *argv[], char *envp[],
  79. struct file **filp);
  80. #endif /* __LINUX_KMOD_H__ */