no swim no life
call_usermodehelper 본문
커널모드에서의 파일삭제는 이놈으로 해결했다.
call_usermodehelper Name call_usermodehelper -- start a usermode application Synopsis int call_usermodehelper (char * path, char ** argv, char ** envp, int wait); Arguments path pathname for the application argv null-terminated argument list envp null-terminated environment list wait wait for the application to finish and return status. Description Runs a user-space application. The application is started asynchronously if wait is not set, and runs as a child of keventd. (ie. it runs with full root capabilities). Must be called from process context. Returns a negative error code if program was not execed successfully, or 0. |
요약,
커널모드에서 유저영역 응용프로그램을 수행하는 함수
- path : 응용프로그램 경로
- argv : 인자 리스트 (null-terminated)
- envp : 환경 변수 (null-terminated)
- wait : 응용프로그램의 수행 결과에 대한 대기 방법
응용프로그램은 비동기적으로 수행되며, keventd의 자식프로세스로 수행하고, root 권한을 가진다.
Process Context로 부터 호출 되어야 하고, 리턴값은 성공( 0 ), 실패( -n ) 이다.
아래와 같이 사용한다.
int removefile( char const *filename )
{
char *argv[4] = { NULL, NULL, NULL, NULL };
char *envp[3] = { NULL, NULL, NULL };
if ( !filename )
return -EINVAL;
argv[0] = "/bin/rm";
argv[1] = "-f";
argv[2] = (char *)filename;
envp[0] = "HOME=/";
envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
return call_usermodehelper( argv[0], argv, envp, 0 );
}
실행되는 응용프로그램은 커널 모듈을 억세스한 응용프로그램이 아닌 / (root) 를 기준으로 argv[0]을 수행한다는 점에 주의. 따라서, filename은 절대 경로를 포함해야 원하는 결과를 얻을 수 있다.
#ifndef __LINUX_KMOD_H__
#define __LINUX_KMOD_H__
/*
* include/linux/kmod.h
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <linux/stddef.h>
#include <linux/errno.h>
#include <linux/compiler.h>
#define KMOD_PATH_LEN 256
#ifdef CONFIG_KMOD
/* modprobe exit status on success, -ve on error. Return value
* usually useless though. */
extern int request_module(const char * name, ...) __attribute__ ((format (printf, 1, 2)));
#else
static inline int request_module(const char * name, ...) { return -ENOSYS; }
#endif
#define try_then_request_module(x, mod...) ((x) ?: (request_module(mod), (x)))
struct key;
extern int call_usermodehelper_keys(char *path, char *argv[], char *envp[], struct key *session_keyring, int wait);
static inline int
call_usermodehelper(char *path, char **argv, char **envp, int wait)
{
return call_usermodehelper_keys(path, argv, envp, NULL, wait);
}
extern void usermodehelper_init(void);
extern int __exec_usermodehelper(char *path, char **argv, char **envp, struct key *ring);
#endif /* __LINUX_KMOD_H__ */
'work > kernel' 카테고리의 다른 글
verify_area( ) (0) | 2008.09.22 |
---|---|
커널 소스 설치 (0) | 2008.09.04 |
리눅스 메모리 사용 제약 (0) | 2008.09.04 |
Comments